code
stringlengths 0
56.1M
| repo_name
stringlengths 3
57
| path
stringlengths 2
176
| language
stringclasses 672
values | license
stringclasses 8
values | size
int64 0
56.8M
|
|---|---|---|---|---|---|
#pragma once
#include <core/common.hpp>
#include <volk.h>
#include <vector>
namespace ZN::GFX {
class SemaphorePool final {
public:
explicit SemaphorePool() = default;
~SemaphorePool();
NULL_COPY_AND_ASSIGN(SemaphorePool);
VkSemaphore acquire_semaphore();
void release_semaphore(VkSemaphore);
private:
std::vector<VkSemaphore> m_semaphores;
std::vector<VkSemaphore> m_freeSemaphores;
};
}
|
whupdup/frame
|
real/graphics/semaphore_pool.hpp
|
C++
|
gpl-3.0
| 414
|
#include "shader_program.hpp"
#include <file/file_system.hpp>
#include <graphics/render_context.hpp>
#include <cassert>
#include <cstring>
#include <spirv_reflect.h>
using namespace ZN;
using namespace ZN::GFX;
// ShaderProgram
Memory::IntrusivePtr<ShaderProgram> ShaderProgram::create(const VkShaderModule* modules,
const VkShaderStageFlagBits* stageFlags, uint32_t numModules, VkPipelineLayout layout) {
return Memory::IntrusivePtr<ShaderProgram>(new ShaderProgram(modules, stageFlags, numModules,
layout));
}
ShaderProgram::ShaderProgram(const VkShaderModule* modules,
const VkShaderStageFlagBits* stageFlags, uint32_t numModules,
VkPipelineLayout layout)
: m_numModules(numModules)
, m_layout(layout) {
assert(numModules <= 2 && "Must have at most 2 modules");
memcpy(m_modules, modules, numModules * sizeof(VkShaderModule));
memcpy(m_stageFlags, stageFlags, numModules * sizeof(VkShaderStageFlagBits));
}
ShaderProgram::~ShaderProgram() {
for (uint32_t i = 0; i < m_numModules; ++i) {
g_renderContext->queue_delete([module=this->m_modules[i]] {
vkDestroyShaderModule(g_renderContext->get_device(), module, nullptr);
});
}
}
uint32_t ShaderProgram::get_num_modules() const {
return m_numModules;
}
const VkShaderModule* ShaderProgram::get_shader_modules() const {
return m_modules;
}
const VkShaderStageFlagBits* ShaderProgram::get_stage_flags() const {
return m_stageFlags;
}
VkPipelineLayout ShaderProgram::get_pipeline_layout() const {
return m_layout;
}
// ShaderProgramBuilder
ShaderProgramBuilder& ShaderProgramBuilder::add_shader(const std::string_view& fileName,
VkShaderStageFlagBits stage) {
auto data = g_fileSystem->file_read_bytes(fileName);
if (data.empty()) {
m_error = true;
return *this;
}
m_ownedFileMemory.emplace_back(std::move(data));
auto& fileData = m_ownedFileMemory.back();
return add_shader(reinterpret_cast<const uint32_t*>(fileData.data()), fileData.size(), stage);
}
ShaderProgramBuilder& ShaderProgramBuilder::add_shader(const uint32_t* data, size_t dataSize,
VkShaderStageFlagBits stage) {
m_shaderData.emplace_back(ShaderData{data, dataSize, stage});
return *this;
}
ShaderProgramBuilder& ShaderProgramBuilder::add_type_override(uint32_t set, uint32_t binding,
VkDescriptorType type) {
m_overrides.push_back({set, binding, type});
return *this;
}
ShaderProgramBuilder& ShaderProgramBuilder::add_dynamic_array(uint32_t set, uint32_t binding) {
if (m_dynamicArrays.size() <= set) {
m_dynamicArrays.resize(set + 1);
}
m_dynamicArrays[set].push_back(binding);
return *this;
}
Memory::IntrusivePtr<ShaderProgram> ShaderProgramBuilder::build() {
if (m_error) {
return {};
}
std::vector<VkShaderModule> modules;
std::vector<VkShaderStageFlagBits> stageFlags;
bool error = false;
for (auto [data, dataSize, stage] : m_shaderData) {
if (!reflect_module(data, dataSize, stage)) {
error = true;
break;
}
VkShaderModuleCreateInfo createInfo{};
createInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
createInfo.codeSize = dataSize;
createInfo.pCode = data;
VkShaderModule shaderModule;
if (vkCreateShaderModule(g_renderContext->get_device(), &createInfo, nullptr,
&shaderModule) != VK_SUCCESS) {
error = true;
break;
}
else {
modules.push_back(shaderModule);
stageFlags.push_back(stage);
}
}
VkPipelineLayout layout = VK_NULL_HANDLE;
if (!error) {
layout = build_pipeline_layout();
error = layout == VK_NULL_HANDLE;
}
if (error) {
for (auto shaderModule : modules) {
vkDestroyShaderModule(g_renderContext->get_device(), shaderModule, nullptr);
}
return {};
}
return ShaderProgram::create(modules.data(), stageFlags.data(),
static_cast<uint32_t>(modules.size()), layout);
}
bool ShaderProgramBuilder::reflect_module(const uint32_t* data, size_t dataSize,
VkShaderStageFlagBits stage) {
SpvReflectShaderModule spvModule;
auto result = spvReflectCreateShaderModule(dataSize, data, &spvModule);
if (result != SPV_REFLECT_RESULT_SUCCESS) {
return false;
}
uint32_t count = 0;
result = spvReflectEnumerateDescriptorSets(&spvModule, &count, NULL);
if (result != SPV_REFLECT_RESULT_SUCCESS) {
return false;
}
std::vector<SpvReflectDescriptorSet*> reflectedSets(count);
result = spvReflectEnumerateDescriptorSets(&spvModule, &count, reflectedSets.data());
if (result != SPV_REFLECT_RESULT_SUCCESS) {
return false;
}
std::vector<ReflectedDescriptorLayout> reflectedLayouts;
for (size_t i = 0; i < reflectedSets.size(); ++i) {
auto& reflectedSet = *reflectedSets[i];
ReflectedDescriptorLayout reflectedLayout{};
reflectedLayout.setNumber = reflectedSet.set;
if (m_dynamicArrays.size() <= reflectedSet.set) {
m_dynamicArrays.resize(reflectedSet.set + 1);
}
for (uint32_t j = 0; j < reflectedSet.binding_count; ++j) {
auto& reflectedBinding = *reflectedSet.bindings[j];
bool duplicate = false;
for (auto& prevBinding : reflectedLayout.bindings) {
if (prevBinding.binding == reflectedBinding.binding) {
duplicate = true;
break;
}
}
if (duplicate) {
continue;
}
VkDescriptorSetLayoutBinding binding{};
binding.descriptorCount = 1;
binding.binding = reflectedBinding.binding;
binding.stageFlags = stage;
for (uint32_t dim = 0; dim < reflectedBinding.array.dims_count; ++dim) {
binding.descriptorCount *= reflectedBinding.array.dims[dim];
}
bool hasOverride = false;
for (auto& ovr : m_overrides) {
if (ovr.set == reflectedSet.set && ovr.binding == reflectedBinding.binding) {
binding.descriptorType = ovr.type;
hasOverride = true;
break;
}
}
if (!hasOverride) {
binding.descriptorType
= static_cast<VkDescriptorType>(reflectedBinding.descriptor_type);
}
reflectedLayout.bindings.emplace_back(std::move(binding));
}
reflectedLayouts.emplace_back(std::move(reflectedLayout));
}
result = spvReflectEnumeratePushConstantBlocks(&spvModule, &count, nullptr);
std::vector<SpvReflectBlockVariable*> pushConstants(count);
result = spvReflectEnumeratePushConstantBlocks(&spvModule, &count, pushConstants.data());
for (size_t i = 0; i < count; ++i) {
VkPushConstantRange pcr{};
pcr.offset = pushConstants[i]->offset;
pcr.size = pushConstants[i]->size;
pcr.stageFlags = stage;
m_constantRanges.push_back(std::move(pcr));
}
for (auto& layout : reflectedLayouts) {
add_layout(layout);
}
return true;
}
void ShaderProgramBuilder::add_layout(const ReflectedDescriptorLayout& layoutIn) {
for (auto& layout : m_layouts) {
if (layout.setNumber == layoutIn.setNumber) {
for (auto& bindingIn : layoutIn.bindings) {
bool foundExistingBindings = false;
for (auto& binding : layout.bindings) {
if (binding.binding == bindingIn.binding) {
foundExistingBindings = true;
binding.stageFlags |= bindingIn.stageFlags;
break;
}
}
if (!foundExistingBindings) {
layout.bindings.push_back(bindingIn);
}
}
return;
}
}
m_layouts.push_back(layoutIn);
}
VkPipelineLayout ShaderProgramBuilder::build_pipeline_layout() {
std::vector<VkDescriptorSetLayout> setLayouts;
std::vector<VkDescriptorBindingFlags> flags;
VkDescriptorSetLayoutBindingFlagsCreateInfo bindingFlags{};
bindingFlags.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_BINDING_FLAGS_CREATE_INFO;
for (auto& descLayoutInfo : m_layouts) {
VkDescriptorSetLayoutCreateInfo createInfo{};
createInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
createInfo.bindingCount = static_cast<uint32_t>(descLayoutInfo.bindings.size());
createInfo.pBindings = descLayoutInfo.bindings.data();
if (!m_dynamicArrays[descLayoutInfo.setNumber].empty()) {
flags.clear();
flags.resize(descLayoutInfo.bindings.size());
for (auto arrayIndex : m_dynamicArrays[descLayoutInfo.setNumber]) {
flags[arrayIndex] = VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT
| VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT
| VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT;
}
createInfo.flags |= VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT;
bindingFlags.bindingCount = createInfo.bindingCount;
bindingFlags.pBindingFlags = flags.data();
createInfo.pNext = &bindingFlags;
}
setLayouts.push_back(g_renderContext->descriptor_set_layout_create(createInfo));
}
for (size_t i = 1; i < setLayouts.size(); ++i) {
for (auto j = i; j > 0 && m_layouts[j].setNumber < m_layouts[j - 1].setNumber; --j) {
std::swap(m_layouts[j], m_layouts[j - 1]);
std::swap(setLayouts[j], setLayouts[j - 1]);
}
}
VkPipelineLayoutCreateInfo createInfo{};
createInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
createInfo.setLayoutCount = static_cast<uint32_t>(setLayouts.size());
createInfo.pSetLayouts = setLayouts.data();
if (!m_constantRanges.empty()) {
createInfo.pushConstantRangeCount = static_cast<uint32_t>(m_constantRanges.size());
createInfo.pPushConstantRanges = m_constantRanges.data();
}
return g_renderContext->pipeline_layout_create(createInfo);
}
|
whupdup/frame
|
real/graphics/shader_program.cpp
|
C++
|
gpl-3.0
| 9,106
|
#pragma once
#include <core/intrusive_ptr.hpp>
#include <volk.h>
#include <memory>
#include <string_view>
#include <vector>
namespace ZN::GFX {
class ShaderProgram final : public Memory::IntrusivePtrEnabled<ShaderProgram> {
public:
static Memory::IntrusivePtr<ShaderProgram> create(const VkShaderModule* modules,
const VkShaderStageFlagBits* stageFlags, uint32_t numModules,
VkPipelineLayout);
~ShaderProgram();
NULL_COPY_AND_ASSIGN(ShaderProgram);
uint32_t get_num_modules() const;
const VkShaderModule* get_shader_modules() const;
const VkShaderStageFlagBits* get_stage_flags() const;
VkPipelineLayout get_pipeline_layout() const;
private:
VkShaderModule m_modules[2];
VkShaderStageFlagBits m_stageFlags[2];
uint32_t m_numModules;
VkPipelineLayout m_layout;
explicit ShaderProgram(const VkShaderModule* modules,
const VkShaderStageFlagBits* stageFlags, uint32_t numModules,
VkPipelineLayout);
};
class ShaderProgramBuilder final {
public:
explicit ShaderProgramBuilder() = default;
NULL_COPY_AND_ASSIGN(ShaderProgramBuilder);
ShaderProgramBuilder& add_shader(const std::string_view& fileName,
VkShaderStageFlagBits stage);
ShaderProgramBuilder& add_shader(const uint32_t* data, size_t dataSize,
VkShaderStageFlagBits stage);
ShaderProgramBuilder& add_type_override(uint32_t set, uint32_t binding, VkDescriptorType);
ShaderProgramBuilder& add_dynamic_array(uint32_t set, uint32_t binding);
[[nodiscard]] Memory::IntrusivePtr<ShaderProgram> build();
private:
struct ReflectionOverride {
uint32_t set;
uint32_t binding;
VkDescriptorType type;
};
struct ShaderData {
const uint32_t* data;
size_t dataSize;
VkShaderStageFlagBits stage;
};
struct ReflectedDescriptorLayout {
uint32_t setNumber;
std::vector<VkDescriptorSetLayoutBinding> bindings;
};
std::vector<ShaderData> m_shaderData;
std::vector<ReflectedDescriptorLayout> m_layouts;
std::vector<VkPushConstantRange> m_constantRanges;
std::vector<std::vector<char>> m_ownedFileMemory;
std::vector<ReflectionOverride> m_overrides;
std::vector<std::vector<uint32_t>> m_dynamicArrays;
bool m_error = false;
bool reflect_module(const uint32_t*, size_t, VkShaderStageFlagBits);
void add_layout(const ReflectedDescriptorLayout&);
VkPipelineLayout build_pipeline_layout();
bool is_dynamic_array(uint32_t set, uint32_t binding);
};
}
|
whupdup/frame
|
real/graphics/shader_program.hpp
|
C++
|
gpl-3.0
| 2,422
|
#include "specialization_info.hpp"
#include <cstring>
using namespace ZN;
using namespace ZN::GFX;
SpecializationInfo& SpecializationInfo::add_entry(uint32_t constantID,
const void *data, size_t size) {
auto offset = static_cast<uint32_t>(m_data.size());
m_data.resize(m_data.size() + size);
memcpy(m_data.data() + offset, data, size);
m_mapEntries.push_back({
.constantID = constantID,
.offset = offset,
.size = size
});
return *this;
}
bool SpecializationInfo::empty() const {
return m_data.empty();
}
const VkSpecializationInfo& SpecializationInfo::get_info() {
m_info = {
.mapEntryCount = static_cast<uint32_t>(m_mapEntries.size()),
.pMapEntries = m_mapEntries.data(),
.dataSize = m_data.size(),
.pData = m_data.data()
};
return m_info;
}
|
whupdup/frame
|
real/graphics/specialization_info.cpp
|
C++
|
gpl-3.0
| 779
|
#pragma once
#include <core/common.hpp>
#include <volk.h>
#include <vector>
namespace ZN::GFX {
class SpecializationInfo final {
public:
SpecializationInfo& add_entry(uint32_t constantID, const void* data, size_t size);
bool empty() const;
const VkSpecializationInfo& get_info();
private:
std::vector<uint8_t> m_data;
std::vector<VkSpecializationMapEntry> m_mapEntries;
VkSpecializationInfo m_info;
};
}
|
whupdup/frame
|
real/graphics/specialization_info.hpp
|
C++
|
gpl-3.0
| 427
|
#include "texture.hpp"
#include <file/file_system.hpp>
#include <graphics/dds_texture.hpp>
#include <graphics/render_context.hpp>
#include <graphics/render_utils.hpp>
#include <graphics/vk_initializers.hpp>
#include <stb_image.h>
#include <stb_image_resize.h>
#include <Tracy.hpp>
#include <memory>
using namespace ZN;
using namespace ZN::GFX;
namespace ZN::GFX {
struct TextureLoadData {
std::string fileName;
IntrusivePtr<Texture> result;
Texture::LoadFlags flags;
};
struct AsyncTextureLoadData : public TextureLoadData {
Scheduler::Promise<IntrusivePtr<Texture>> promise;
~AsyncTextureLoadData() {
promise.set_value(std::move(result));
}
};
}
static void load_async_job(void* userData);
static void load_image_internal(TextureLoadData& loadData);
static void load_image_dds(TextureLoadData& loadData, std::vector<char>&& fileData);
static void load_image_stb(TextureLoadData& loadData, std::vector<char>&& fileData);
static void create_image(TextureLoadData& loadData, Buffer& buffer, VkFormat format,
uint32_t mipLevels, VkExtent3D extents);
IntrusivePtr<Texture> Texture::load(std::string fileName, LoadFlags loadFlags) {
TextureLoadData loadData{
.fileName = std::move(fileName),
.flags = loadFlags,
};
load_image_internal(loadData);
return loadData.result;
}
Scheduler::Future<IntrusivePtr<Texture>> Texture::load_async(std::string fileName,
LoadFlags loadFlags) {
auto* loadData = new AsyncTextureLoadData{
{
.fileName = std::move(fileName),
.result = nullptr,
.flags = loadFlags,
}
};
auto result = loadData->promise.get_future();
Scheduler::queue_blocking_job(loadData, Scheduler::NO_SIGNAL, load_async_job);
return result;
}
IntrusivePtr<Texture> Texture::create(IntrusivePtr<ImageView> imageView,
uint32_t descriptorIndex, std::string fileName) {
return Memory::IntrusivePtr(new Texture(std::move(imageView), descriptorIndex,
std::move(fileName)));
}
Texture::Texture(IntrusivePtr<ImageView> imageView, uint32_t descriptorIndex,
std::string fileName)
: m_imageView(std::move(imageView))
, m_descriptorIndex(descriptorIndex)
, m_fileName(std::move(fileName)) {}
Image& Texture::get_image() const {
return m_imageView->get_image();
}
ImageView& Texture::get_image_view() const {
return *m_imageView;
}
uint32_t Texture::get_descriptor_index() const {
return m_descriptorIndex;
}
static void load_async_job(void* userData) {
std::unique_ptr<AsyncTextureLoadData> loadData(
reinterpret_cast<AsyncTextureLoadData*>(userData));
load_image_internal(*loadData);
}
static void load_image_internal(TextureLoadData& loadData) {
auto fileData = g_fileSystem->file_read_bytes(loadData.fileName);
if (fileData.empty()) {
return;
}
// FIXME: Check file magic instead
if (loadData.fileName.ends_with("dds")) {
load_image_dds(loadData, std::move(fileData));
}
else {
load_image_stb(loadData, std::move(fileData));
}
}
static void load_image_dds(TextureLoadData& loadData, std::vector<char>&& fileData) {
ZoneScopedN("DDS");
DDS::DDSTextureInfo textureInfo{};
if (!DDS::get_texture_info(textureInfo, fileData.data(), fileData.size(),
loadData.flags & Texture::LOAD_SRGB_BIT)) {
return;
}
VkExtent3D extents{
textureInfo.width,
textureInfo.height,
1
};
// FIXME: copy over mip levels from the DDS
uint32_t mipLevels = 1;
//uint32_t mipLevels = loadData.generateMipMaps
// ? get_image_mip_levels(textureInfo.width, textureInfo.height) : 1;
auto baseSize = static_cast<size_t>(textureInfo.width * textureInfo.height * 4);
auto totalSize = get_image_total_size_pixels(textureInfo.width, textureInfo.height,
mipLevels) * 4;
auto buffer = Buffer::create(totalSize, VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
VMA_MEMORY_USAGE_CPU_ONLY, VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
memcpy(buffer->map(), textureInfo.dataStart, baseSize);
create_image(loadData, *buffer, textureInfo.format, mipLevels, std::move(extents));
}
static void load_image_stb(TextureLoadData& loadData, std::vector<char>&& fileData) {
ZoneScopedN("STB");
int width, height, channels;
stbi_uc* imageData = {};
{
ZoneScopedN("stbi_load_from_memory");
imageData = stbi_load_from_memory(reinterpret_cast<stbi_uc*>(fileData.data()),
static_cast<int>(fileData.size()), &width, &height, &channels, STBI_rgb_alpha);
}
if (!imageData) {
return;
}
VkExtent3D extents{
static_cast<uint32_t>(width),
static_cast<uint32_t>(height),
1
};
bool genMipMaps = loadData.flags & Texture::LOAD_GENERATE_MIPMAPS_BIT;
VkFormat format = (loadData.flags & Texture::LOAD_SRGB_BIT) ? VK_FORMAT_R8G8B8A8_SRGB
: VK_FORMAT_R8G8B8A8_UNORM;
uint32_t mipLevels = genMipMaps
? get_image_mip_levels(static_cast<uint32_t>(width), static_cast<uint32_t>(height))
: 1;
auto baseSize = static_cast<size_t>(width * height * 4);
auto totalSize = get_image_total_size_pixels(static_cast<uint32_t>(width),
static_cast<uint32_t>(height), genMipMaps * UINT32_MAX + !genMipMaps) * 4;
auto buffer = Buffer::create(totalSize, VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
VMA_MEMORY_USAGE_CPU_ONLY);
auto* mapBuffer = buffer->map();
memcpy(mapBuffer, imageData, baseSize);
if (genMipMaps) {
ZoneScopedN("Generate Mipmaps");
const uint8_t* srcMemory = mapBuffer;
uint8_t* dstMemory = mapBuffer + baseSize;
for (uint32_t i = 0; i < mipLevels; ++i) {
auto outputWidth = (width > 1) * (width / 2) + (width <= 1) * width;
auto outputHeight = (height > 1) * (height / 2) + (height <= 1) * height;
stbir_resize_uint8(srcMemory, width, height, 0, dstMemory, outputWidth, outputHeight,
0, 4);
width = outputWidth;
height = outputHeight;
srcMemory = dstMemory;
dstMemory += static_cast<ptrdiff_t>(4 * width * height);
}
}
stbi_image_free(imageData);
create_image(loadData, *buffer, format, mipLevels, std::move(extents));
}
static void create_image(TextureLoadData& loadData, Buffer& buffer, VkFormat format,
uint32_t mipLevels, VkExtent3D extents) {
auto imageInfo = vkinit::image_create_info(format, VK_IMAGE_USAGE_SAMPLED_BIT
| VK_IMAGE_USAGE_TRANSFER_DST_BIT, std::move(extents));
imageInfo.mipLevels = mipLevels;
auto image = Image::create(imageInfo, VMA_MEMORY_USAGE_GPU_ONLY);
if (!image) {
return;
}
auto imageView = ImageView::create(*image, VK_IMAGE_VIEW_TYPE_2D, format,
VK_IMAGE_ASPECT_COLOR_BIT, mipLevels);
if (!imageView) {
return;
}
g_renderContext->get_upload_context().upload(buffer, *imageView);
auto descriptorIndex = g_renderContext->get_texture_registry().alloc_texture();
g_renderContext->get_texture_registry().update_texture(descriptorIndex, imageView,
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
g_renderContext->mark_image_ready(*imageView);
loadData.result = Texture::create(std::move(imageView), descriptorIndex,
std::move(loadData.fileName));
}
|
whupdup/frame
|
real/graphics/texture.cpp
|
C++
|
gpl-3.0
| 6,838
|
#pragma once
#include <graphics/image_view.hpp>
#include <scheduler/future.hpp>
#include <string>
namespace ZN::GFX {
class Texture final : public Memory::ThreadSafeIntrusivePtrEnabled<Texture> {
public:
using LoadCallback = void(IntrusivePtr<Texture>);
using LoadFlags = uint8_t;
enum LoadFlagBits : LoadFlags {
LOAD_SRGB_BIT = 0b01,
LOAD_GENERATE_MIPMAPS_BIT = 0b10,
};
static IntrusivePtr<Texture> load(std::string fileName, LoadFlags loadFlags);
static Scheduler::Future<IntrusivePtr<Texture>> load_async(std::string fileName,
LoadFlags loadFlags);
static IntrusivePtr<Texture> create(IntrusivePtr<ImageView>, uint32_t, std::string);
NULL_COPY_AND_ASSIGN(Texture);
Image& get_image() const;
ImageView& get_image_view() const;
uint32_t get_descriptor_index() const;
private:
IntrusivePtr<ImageView> m_imageView;
uint32_t m_descriptorIndex;
std::string m_fileName;
explicit Texture(IntrusivePtr<ImageView>, uint32_t, std::string);
};
}
|
whupdup/frame
|
real/graphics/texture.hpp
|
C++
|
gpl-3.0
| 993
|
#include "texture_registry.hpp"
#include <core/logging.hpp>
#include <core/scoped_lock.hpp>
#include <graphics/render_context.hpp>
#include <graphics/vk_initializers.hpp>
#include <cassert>
using namespace ZN;
using namespace ZN::GFX;
TextureRegistry::TextureRegistry(uint32_t capacity)
: m_numAllocated(0)
, m_capacity(capacity)
, m_mutex(Scheduler::Mutex::create()) {
auto samplerInfo = vkinit::sampler_create_info(VK_FILTER_NEAREST);
samplerInfo.minLod = 0.f;
samplerInfo.maxLod = VK_LOD_CLAMP_NONE;
samplerInfo.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR;
m_nearestSampler = GFX::Sampler::create(samplerInfo);
samplerInfo.minFilter = VK_FILTER_LINEAR;
samplerInfo.magFilter = VK_FILTER_LINEAR;
m_linearSampler = GFX::Sampler::create(samplerInfo);
VkDescriptorImageInfo samplerBindingInfo[2] = {};
samplerBindingInfo[0].sampler = *m_linearSampler;
samplerBindingInfo[1].sampler = *m_nearestSampler;
for (size_t i = 0; i < FRAMES_IN_FLIGHT; ++i) {
m_descriptors[i] = g_renderContext->global_update_after_bind_descriptor_set_begin()
.bind_images(0, samplerBindingInfo, 2, VK_DESCRIPTOR_TYPE_SAMPLER,
VK_SHADER_STAGE_FRAGMENT_BIT)
.bind_dynamic_array(1, capacity, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
VK_SHADER_STAGE_FRAGMENT_BIT)
.build();
}
}
void TextureRegistry::update() {
ScopedLock lock(*m_mutex);
if (m_pendingUpdates.empty()) {
return;
}
// FIXME: frame memory
std::vector<VkDescriptorImageInfo> imageInfos;
std::vector<VkWriteDescriptorSet> writes;
imageInfos.reserve(m_pendingUpdates.size());
writes.reserve(m_pendingUpdates.size());
for (size_t i = m_pendingUpdates.size() - 1;; --i) {
auto& du = m_pendingUpdates[i];
imageInfos.emplace_back(VkDescriptorImageInfo{
.sampler = VK_NULL_HANDLE,
.imageView = du.imageView ? du.imageView->get_image_view() : VK_NULL_HANDLE,
.imageLayout = du.layout
});
//LOG_TEMP("Frame %u writing index %u with image view %X; count = %u",
// g_renderContext->get_frame_index(), du.index, du.imageView->get_image_view(),
// du.count);
VkWriteDescriptorSet write{};
write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
write.dstSet = get_descriptor_set();
write.dstBinding = 1;
write.dstArrayElement = du.index;
write.descriptorCount = 1;
write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
write.pImageInfo = &imageInfos.back();
writes.emplace_back(std::move(write));
--du.count;
if (du.count == 0) {
m_pendingUpdates[i] = std::move(m_pendingUpdates.back());
m_pendingUpdates.pop_back();
}
if (i == 0) {
break;
}
}
vkUpdateDescriptorSets(g_renderContext->get_device(), static_cast<uint32_t>(writes.size()),
writes.data(), 0, nullptr);
}
uint32_t TextureRegistry::alloc_texture() {
return alloc_internal();
}
uint32_t TextureRegistry::alloc_texture(VkImageView placeholder, VkImageLayout placeholderLayout) {
auto res = alloc_internal();
update_immediate(res, placeholder, placeholderLayout);
return res;
}
void TextureRegistry::free_texture(uint32_t index) {
ScopedLock lock(*m_mutex);
m_freeList.push_back(index);
//LOG_TEMP("Freeing descriptor index %u", index);
for (size_t i = 0; i < m_pendingUpdates.size(); ++i) {
if (m_pendingUpdates[i].index == index) {
m_pendingUpdates[i] = std::move(m_pendingUpdates.back());
m_pendingUpdates.pop_back();
return;
}
}
}
void TextureRegistry::update_texture(uint32_t index, Memory::IntrusivePtr<ImageView> imageView,
VkImageLayout layout) {
ScopedLock lock(*m_mutex);
m_pendingUpdates.emplace_back(DescriptorUpdate{
.imageView = std::move(imageView),
.layout = layout,
.index = index,
.count = static_cast<uint32_t>(FRAMES_IN_FLIGHT)
});
}
VkDescriptorSet TextureRegistry::get_descriptor_set() const {
return m_descriptors[g_renderContext->get_frame_index()];
}
Sampler& TextureRegistry::get_sampler(SamplerIndex index) const {
switch (index) {
case SamplerIndex::LINEAR:
return *m_linearSampler;
case SamplerIndex::NEAREST:
return *m_nearestSampler;
}
assert(false && "Invalid sampler type");
return *m_linearSampler;
}
uint32_t TextureRegistry::alloc_internal() {
assert(m_numAllocated < m_capacity && "Attempt to allocate texture above capacity");
uint32_t res = 0;
ScopedLock lock(*m_mutex);
if (m_freeList.empty()) {
res = m_numAllocated;
++m_numAllocated;
}
else {
res = m_freeList.back();
m_freeList.pop_back();
}
return res;
}
void TextureRegistry::update_immediate(uint32_t index, VkImageView imageView,
VkImageLayout layout) {
VkDescriptorImageInfo imageInfos[FRAMES_IN_FLIGHT] = {};
VkWriteDescriptorSet writes[FRAMES_IN_FLIGHT] = {};
for (size_t i = 0; i < FRAMES_IN_FLIGHT; ++i) {
imageInfos[i].imageView = imageView;
imageInfos[i].imageLayout = layout;
writes[i].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
writes[i].dstSet = get_descriptor_set();
writes[i].dstBinding = 1;
writes[i].dstArrayElement = index;
writes[i].descriptorCount = 1;
writes[i].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
writes[i].pImageInfo = imageInfos + i;
}
vkUpdateDescriptorSets(g_renderContext->get_device(),
static_cast<uint32_t>(FRAMES_IN_FLIGHT), writes, 0, nullptr);
}
|
whupdup/frame
|
real/graphics/texture_registry.cpp
|
C++
|
gpl-3.0
| 5,213
|
#pragma once
#include <graphics/graphics_fwd.hpp>
#include <graphics/image_view.hpp>
#include <graphics/sampler.hpp>
#include <graphics/sampler_index.hpp>
#include <scheduler/task_scheduler.hpp>
#include <vector>
namespace ZN::GFX {
static constexpr const uint32_t INVALID_TEXTURE_INDEX = static_cast<uint32_t>(~0u);
class DescriptorBuilder;
class TextureRegistry final {
public:
explicit TextureRegistry(uint32_t capacity);
NULL_COPY_AND_ASSIGN(TextureRegistry);
void update();
uint32_t alloc_texture();
uint32_t alloc_texture(VkImageView placeholder, VkImageLayout placeholderLayout);
void free_texture(uint32_t);
void update_texture(uint32_t index, Memory::IntrusivePtr<ImageView>, VkImageLayout);
VkDescriptorSet get_descriptor_set() const;
Sampler& get_sampler(SamplerIndex) const;
private:
struct DescriptorUpdate {
IntrusivePtr<ImageView> imageView;
VkImageLayout layout;
uint32_t index;
uint32_t count;
};
VkDescriptorSet m_descriptors[FRAMES_IN_FLIGHT];
std::vector<uint32_t> m_freeList;
std::vector<DescriptorUpdate> m_pendingUpdates;
uint32_t m_numAllocated;
uint32_t m_capacity;
IntrusivePtr<GFX::Sampler> m_nearestSampler;
IntrusivePtr<GFX::Sampler> m_linearSampler;
IntrusivePtr<Scheduler::Mutex> m_mutex;
uint32_t alloc_internal();
void update_immediate(uint32_t index, VkImageView, VkImageLayout);
};
}
|
whupdup/frame
|
real/graphics/texture_registry.hpp
|
C++
|
gpl-3.0
| 1,394
|
#pragma once
#include <graphics/base_frame_graph_pass.hpp>
namespace ZN::GFX {
class TransferPass final : public FrameGraphPassMixin<TransferPass> {
public:
private:
};
}
|
whupdup/frame
|
real/graphics/transfer_pass.hpp
|
C++
|
gpl-3.0
| 178
|
#pragma once
#include <core/common.hpp>
#include <atomic>
namespace ZN::GFX {
class UniqueGraphicsObject {
public:
explicit UniqueGraphicsObject()
: m_uniqueID(s_counter.fetch_add(1, std::memory_order_relaxed)) {}
DEFAULT_COPY_AND_ASSIGN(UniqueGraphicsObject);
constexpr uint64_t get_unique_id() const {
return m_uniqueID;
}
private:
static inline std::atomic_uint64_t s_counter = 1ull;
uint64_t m_uniqueID;
};
}
|
whupdup/frame
|
real/graphics/unique_graphics_object.hpp
|
C++
|
gpl-3.0
| 443
|
#include "upload_context.hpp"
#include <core/scoped_lock.hpp>
#include <graphics/frame_graph.hpp>
#include <graphics/render_context.hpp>
#include <graphics/vk_common.hpp>
#include <graphics/vk_initializers.hpp>
using namespace ZN;
using namespace ZN::GFX;
static void gen_image_copies(CommandBuffer& cmd, Buffer& buffer, ImageView& imageView);
void UploadContext::upload(Buffer& src, Buffer& dst) {
upload(src, dst, 0, 0, VK_WHOLE_SIZE);
}
void UploadContext::upload(Buffer& src, Buffer& dst, VkDeviceSize srcOffset,
VkDeviceSize dstOffset, VkDeviceSize dstSize) {
ScopedLock lock(*m_mutex);
m_bufferToBuffer.push_back({
.src = src.reference_from_this(),
.dst = dst.reference_from_this(),
.copy = {
.srcOffset = srcOffset,
.dstOffset = dstOffset,
.size = dstSize
}
});
}
void UploadContext::upload(Buffer& src, ImageView& dst) {
ScopedLock lock(*m_mutex);
m_bufferToImage.push_back({
.src = src.reference_from_this(),
.dst = dst.reference_from_this(),
});
}
void UploadContext::emit_commands(FrameGraph& graph) {
ScopedLock lock(*m_mutex);
if (!m_bufferToBuffer.empty()) {
auto& pass = graph.add_transfer_pass();
for (auto& [pSrc, pDst, copy] : m_bufferToBuffer) {
pass.add_buffer(*pDst, ResourceAccess::WRITE, VK_PIPELINE_STAGE_TRANSFER_BIT,
copy.dstOffset, copy.size);
}
pass.add_command_callback([&](auto& cmd) {
ScopedLock lock(*m_mutex);
for (auto& [pSrc, pDst, copy] : m_bufferToBuffer) {
cmd.copy_buffer(*pSrc, *pDst, 1, ©);
}
m_bufferToBuffer.clear();
});
}
if (!m_bufferToImage.empty()) {
auto& pass = graph.add_transfer_pass();
for (auto& [pSrc, pDst] : m_bufferToImage) {
pass.add_texture(*pDst, ResourceAccess::WRITE, VK_PIPELINE_STAGE_TRANSFER_BIT,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
}
pass.add_command_callback([&](auto& cmd) {
ScopedLock lock(*m_mutex);
for (auto& [pSrc, pDst] : m_bufferToImage) {
gen_image_copies(cmd, *pSrc, *pDst);
}
m_bufferToImage.clear();
});
}
}
static void gen_image_copies(CommandBuffer& cmd, Buffer& buffer, ImageView& imageView) {
auto& image = imageView.get_image();
auto& range = imageView.get_subresource_range();
std::vector<VkBufferImageCopy> copies;
copies.reserve(range.levelCount);
auto extent = image.get_extent();
VkDeviceSize bufferOffset = 0;
for (uint32_t i = 0; i < range.levelCount; ++i) {
copies.push_back({
.bufferOffset = bufferOffset,
.bufferRowLength = 0,
.bufferImageHeight = 0,
.imageSubresource = {
.aspectMask = range.aspectMask,
.mipLevel = range.baseMipLevel + i,
.baseArrayLayer = range.baseArrayLayer,
.layerCount = range.layerCount
},
.imageOffset = {},
.imageExtent = extent
});
bufferOffset += static_cast<VkDeviceSize>(4 * extent.width * extent.height);
if (extent.width > 1) {
extent.width /= 2;
}
if (extent.height > 1) {
extent.height /= 2;
}
}
cmd.copy_buffer_to_image(buffer, image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
static_cast<uint32_t>(copies.size()), copies.data());
}
|
whupdup/frame
|
real/graphics/upload_context.cpp
|
C++
|
gpl-3.0
| 3,066
|
#pragma once
#include <core/variant.hpp>
#include <graphics/buffer.hpp>
#include <graphics/image_view.hpp>
#include <scheduler/task_scheduler.hpp>
#include <vector>
namespace ZN::GFX {
class FrameGraph;
class UploadContext final {
public:
explicit UploadContext() = default;
NULL_COPY_AND_ASSIGN(UploadContext);
void upload(Buffer& src, Buffer& dst);
void upload(Buffer& src, Buffer& dst, VkDeviceSize srcOffset, VkDeviceSize dstOffset,
VkDeviceSize dstSize);
void upload(Buffer& src, ImageView& dst);
void emit_commands(FrameGraph&);
private:
struct BufferToBuffer {
Memory::IntrusivePtr<Buffer> src;
Memory::IntrusivePtr<Buffer> dst;
VkBufferCopy copy;
};
struct BufferToImage {
Memory::IntrusivePtr<Buffer> src;
Memory::IntrusivePtr<ImageView> dst;
};
std::vector<BufferToBuffer> m_bufferToBuffer;
std::vector<BufferToImage> m_bufferToImage;
IntrusivePtr<Scheduler::Mutex> m_mutex = Scheduler::Mutex::create();
};
}
|
whupdup/frame
|
real/graphics/upload_context.hpp
|
C++
|
gpl-3.0
| 981
|
#pragma once
#include <core/logging.hpp>
#define VK_CHECK(x) \
do { \
if (VkResult err = x; err) { \
LOG_ERROR("VULKAN", "%d", err); \
} \
} \
while (0)
#define ZN_TRACY_VK_ZONE(cmd, name) \
TracyVkZone(ZN::GFX::g_renderContext->get_tracy_context(), cmd, name)
|
whupdup/frame
|
real/graphics/vk_common.hpp
|
C++
|
gpl-3.0
| 350
|
#include "vk_initializers.hpp"
VkImageCreateInfo vkinit::image_create_info(VkFormat format, VkImageUsageFlags usageFlags,
VkExtent3D extent) {
VkImageCreateInfo info{};
info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
info.imageType = VK_IMAGE_TYPE_2D;
info.format = format;
info.extent = extent;
info.mipLevels = 1;
info.arrayLayers = 1;
info.samples = VK_SAMPLE_COUNT_1_BIT;
info.tiling = VK_IMAGE_TILING_OPTIMAL;
info.usage = usageFlags;
return info;
}
VkImageViewCreateInfo vkinit::image_view_create_info(VkImageViewType viewType, VkFormat format,
VkImage image, VkImageAspectFlags aspectFlags, uint32_t mipLevels, uint32_t arrayLayers) {
VkImageViewCreateInfo info{};
info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
info.viewType = viewType;
info.image = image;
info.format = format;
info.subresourceRange.baseMipLevel = 0;
info.subresourceRange.levelCount = mipLevels;
info.subresourceRange.baseArrayLayer = 0;
info.subresourceRange.layerCount = arrayLayers;
info.subresourceRange.aspectMask = aspectFlags;
return info;
}
VkSamplerCreateInfo vkinit::sampler_create_info(VkFilter filters,
VkSamplerAddressMode samplerAddressMode) {
VkSamplerCreateInfo info{};
info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
info.minFilter = filters;
info.magFilter = filters;
info.addressModeU = samplerAddressMode;
info.addressModeV = samplerAddressMode;
info.addressModeW = samplerAddressMode;
info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR;
info.minLod = 0.f;
info.maxLod = VK_LOD_CLAMP_NONE;
info.mipLodBias = 0.f;
return info;
}
VkDescriptorSetLayoutBinding vkinit::descriptor_set_layout_binding(VkDescriptorType descriptorType,
VkShaderStageFlags stageFlags, uint32_t binding) {
VkDescriptorSetLayoutBinding setBind{};
setBind.binding = binding;
setBind.descriptorCount = 1;
setBind.descriptorType = descriptorType;
setBind.pImmutableSamplers = nullptr;
setBind.stageFlags = stageFlags;
return setBind;
}
VkDescriptorBufferInfo vkinit::descriptor_buffer_info(VkBuffer buffer, VkDeviceSize offset,
VkDeviceSize range) {
return {buffer, offset, range};
}
VkDescriptorImageInfo vkinit::descriptor_image_info(VkImageView imageView, VkSampler sampler,
VkImageLayout layout) {
VkDescriptorImageInfo info{};
info.sampler = sampler;
info.imageView = imageView;
info.imageLayout = layout;
return info;
}
VkWriteDescriptorSet vkinit::write_descriptor_buffer(VkDescriptorType descriptorType,
VkDescriptorSet descriptorSet, const VkDescriptorBufferInfo* bufferInfo,
uint32_t binding) {
VkWriteDescriptorSet write{};
write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
write.dstBinding = binding;
write.dstSet = descriptorSet;
write.descriptorCount = 1;
write.descriptorType = descriptorType;
write.pBufferInfo = bufferInfo;
return write;
}
VkWriteDescriptorSet vkinit::write_descriptor_image(VkDescriptorType descriptorType,
VkDescriptorSet descriptorSet, const VkDescriptorImageInfo* imageInfo, uint32_t binding) {
VkWriteDescriptorSet write{};
write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
write.dstBinding = binding;
write.dstSet = descriptorSet;
write.descriptorCount = 1;
write.descriptorType = descriptorType;
write.pImageInfo = imageInfo;
return write;
}
VkCommandBufferBeginInfo vkinit::command_buffer_begin_info(VkCommandBufferUsageFlags flags) {
VkCommandBufferBeginInfo info{};
info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
info.flags = flags;
return info;
}
VkSubmitInfo vkinit::submit_info(VkCommandBuffer& cmd) {
VkSubmitInfo info{};
info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
info.commandBufferCount = 1;
info.pCommandBuffers = &cmd;
return info;
}
VkBufferMemoryBarrier vkinit::buffer_barrier(VkBuffer buffer, VkDeviceSize offset,
VkDeviceSize size) {
VkBufferMemoryBarrier barrier{};
barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
barrier.buffer = buffer;
barrier.offset = offset;
barrier.size = size;
return barrier;
}
VkImageMemoryBarrier vkinit::image_barrier(VkImage image, VkAccessFlags srcAccessMask,
VkAccessFlags dstAccessMask, VkImageLayout oldLayout, VkImageLayout newLayout,
VkImageAspectFlags aspectMask) {
VkImageMemoryBarrier barrier{};
barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
barrier.srcAccessMask = srcAccessMask;
barrier.dstAccessMask = dstAccessMask;
barrier.oldLayout = oldLayout;
barrier.newLayout = newLayout;
barrier.image = image;
barrier.subresourceRange.aspectMask = aspectMask;
barrier.subresourceRange.layerCount = 1;
barrier.subresourceRange.levelCount = 1;
return barrier;
}
|
whupdup/frame
|
real/graphics/vk_initializers.cpp
|
C++
|
gpl-3.0
| 4,606
|
#pragma once
#include <volk.h>
namespace vkinit {
VkImageCreateInfo image_create_info(VkFormat, VkImageUsageFlags, VkExtent3D);
VkImageViewCreateInfo image_view_create_info(VkImageViewType, VkFormat, VkImage,
VkImageAspectFlags, uint32_t mipLevels = 1, uint32_t arrayLayers = 1);
VkSamplerCreateInfo sampler_create_info(VkFilter filters,
VkSamplerAddressMode samplerAddressMode = VK_SAMPLER_ADDRESS_MODE_REPEAT);
VkDescriptorSetLayoutBinding descriptor_set_layout_binding(VkDescriptorType,
VkShaderStageFlags, uint32_t binding);
VkDescriptorBufferInfo descriptor_buffer_info(VkBuffer, VkDeviceSize offset = 0,
VkDeviceSize range = VK_WHOLE_SIZE);
VkDescriptorImageInfo descriptor_image_info(VkImageView, VkSampler sampler = VK_NULL_HANDLE,
VkImageLayout layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
VkWriteDescriptorSet write_descriptor_buffer(VkDescriptorType, VkDescriptorSet,
const VkDescriptorBufferInfo*, uint32_t binding);
VkWriteDescriptorSet write_descriptor_image(VkDescriptorType, VkDescriptorSet,
const VkDescriptorImageInfo*, uint32_t binding);
VkCommandBufferBeginInfo command_buffer_begin_info(VkCommandBufferUsageFlags flags = 0);
VkSubmitInfo submit_info(VkCommandBuffer& cmd);
VkBufferMemoryBarrier buffer_barrier(VkBuffer buffer, VkDeviceSize offset, VkDeviceSize size);
VkImageMemoryBarrier image_barrier(VkImage image, VkAccessFlags srcAccessMask,
VkAccessFlags dstAccessMask, VkImageLayout oldLayout, VkImageLayout newLayout,
VkImageAspectFlags aspectMask);
}
|
whupdup/frame
|
real/graphics/vk_initializers.hpp
|
C++
|
gpl-3.0
| 1,517
|
#include <core/logging.hpp>
#include <file/file_system.hpp>
#include <graphics/frame_graph.hpp>
#include <graphics/graphics_pipeline.hpp>
#include <graphics/render_context.hpp>
#include <graphics/sampler.hpp>
#include <graphics/shader_program.hpp>
#include <graphics/texture.hpp>
#include <graphics/texture_registry.hpp>
#include <graphics/vk_initializers.hpp>
#include <materials/static_mesh_phong.hpp>
#include <math/matrix4x4.hpp>
#include <renderers/game_renderer.hpp>
#include <renderers/static_mesh_pool.hpp>
#include <scheduler/task_scheduler.hpp>
#include <services/application.hpp>
#include <services/context_action.hpp>
#include <stb_image.h>
#include <asset/indexed_model.hpp>
#include <asset/obj_loader.hpp>
#include <glm/gtx/transform.hpp>
using namespace ZN;
static IntrusivePtr<GFX::Texture> g_texture = nullptr;
static float g_angle = 0.f;
static float g_lightAngle = 0.f;
static GFX::InstanceHandle g_instances[2] = {};
static void render();
static IntrusivePtr<GFX::Mesh> g_cube{};
static void obj_callback(const std::string_view& name, IndexedModel&& model) {
printf("Loaded ");
fwrite(name.data(), 1, name.size(), stdout);
putchar('\n');
auto vertexBuffer = GFX::Buffer::create(model.get_vertex_count()
* sizeof(StaticMeshPool::Vertex), VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
VMA_MEMORY_USAGE_CPU_ONLY);
auto indexBuffer = GFX::Buffer::create(model.get_index_count() * sizeof(uint32_t),
VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VMA_MEMORY_USAGE_CPU_ONLY);
auto mapVertexBuffer = reinterpret_cast<StaticMeshPool::Vertex*>(vertexBuffer->map());
for (size_t i = 0; i < model.get_vertex_count(); ++i) {
auto& v = mapVertexBuffer[i];
v.position = model.get_positions()[i];
v.normal = model.get_normals()[i];
v.tangent = model.get_tangents()[i];
v.texCoord = model.get_tex_coords()[i];
}
memcpy(indexBuffer->map(), model.get_indices(), model.get_index_count() * sizeof(uint32_t));
g_cube = g_staticMeshPool->create_mesh(model.get_vertex_count(), model.get_index_count(),
*vertexBuffer, *indexBuffer, 0, 0);
}
int main() {
Scheduler::init();
g_fileSystem.create();
g_contextActionManager.create();
g_application.create();
g_window.create(1200, 800, "RealGraph");
GFX::g_renderContext.create(*g_window);
GFX::g_renderContext->late_init();
g_renderer.create();
OBJ::load("res://cube.obj", obj_callback);
g_instances[0] = g_staticMeshPhong->add_instance(*g_cube,
StaticMeshInstance{Math::CFrame(2.f, 0.f, -5.f).to_row_major()});
g_instances[1] = g_staticMeshPhong->add_instance(*g_cube,
StaticMeshInstance{Math::CFrame(-2.f, 0.f, -5.f).to_row_major()});
auto futureTexture = GFX::Texture::load_async("res://aya.jpg", 0);
futureTexture.wait();
g_texture = futureTexture.get();
while (!g_window->is_close_requested()) {
//g_application->await_and_process_events();
g_application->poll_events();
g_renderer->render();
render();
g_window->swap_buffers();
}
g_texture = {};
g_renderer.destroy();
GFX::g_renderContext.destroy();
Scheduler::deinit();
g_window.destroy();
g_application.destroy();
g_contextActionManager.destroy();
g_fileSystem.destroy();
}
static void render() {
g_angle += 0.01f;
g_lightAngle += 0.01f;
/*g_staticMeshPhong->get_instance(g_instances[0]).cframe = (Math::CFrame(2, 0, -5)
* Math::CFrame::from_axis_angle(Math::Vector3(0, 1, 0), g_angle)).to_row_major();
g_staticMeshPhong->get_instance(g_instances[1]).cframe = (Math::CFrame(-2, 0, -5)
* Math::CFrame::from_axis_angle(Math::Vector3(0, -1, 0), g_angle)).to_row_major();*/
g_renderer->set_sunlight_dir(Math::Vector3(glm::cos(g_lightAngle), 0, glm::sin(g_lightAngle)));
}
|
whupdup/frame
|
real/main.cpp
|
C++
|
gpl-3.0
| 3,665
|
target_sources(LibCommon PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/static_mesh_phong.cpp"
)
|
whupdup/frame
|
real/materials/CMakeLists.txt
|
Text
|
gpl-3.0
| 88
|
#include "static_mesh_phong.hpp"
#include <graphics/command_buffer.hpp>
#include <graphics/render_context.hpp>
#include <graphics/render_utils.hpp>
#include <graphics/shader_program.hpp>
#include <renderers/static_mesh_pool.hpp>
using namespace ZN;
StaticMeshPhong::StaticMeshPhong()
: MaterialImpl(*g_staticMeshPool) {
auto cullShader = GFX::ShaderProgramBuilder()
.add_shader("shaders://static_mesh_cull.comp.spv", VK_SHADER_STAGE_COMPUTE_BIT)
.build();
auto forwardShader = GFX::ShaderProgramBuilder()
.add_shader("shaders://mesh_blinn_phong.vert.spv", VK_SHADER_STAGE_VERTEX_BIT)
.add_shader("shaders://mesh_blinn_phong.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT)
.add_dynamic_array(2, 1)
.build();
m_cull = GFX::ComputePipelineBuilder()
.add_program(*cullShader)
.build();
m_forward = GFX::GraphicsPipelineBuilder()
.add_program(*forwardShader)
.set_vertex_attribute_descriptions(StaticMeshPool::input_attribute_descriptions())
.set_vertex_binding_descriptions(StaticMeshPool::input_binding_descriptions())
.build();
}
void StaticMeshPhong::indirect_cull(GFX::CommandBuffer& cmd) {
auto drawCount = get_instance_count();
auto dset = GFX::g_renderContext->dynamic_descriptor_set_begin()
.bind_buffer(0, {get_mesh_pool().get_gpu_indirect_buffer(), 0, VK_WHOLE_SIZE},
VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_SHADER_STAGE_COMPUTE_BIT)
.bind_buffer(1, {get_instance_index_buffer(), 0, VK_WHOLE_SIZE},
VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_SHADER_STAGE_COMPUTE_BIT)
.bind_buffer(2, {get_instance_index_output_buffer(), 0, VK_WHOLE_SIZE},
VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_SHADER_STAGE_COMPUTE_BIT)
.build();
cmd.bind_pipeline(*m_cull);
cmd.push_constants(VK_SHADER_STAGE_COMPUTE_BIT, 0, sizeof(uint32_t), &drawCount);
cmd.bind_descriptor_sets(0, 1, &dset, 0, nullptr);
cmd.dispatch(GFX::get_group_count(drawCount, 256), 1, 1);
}
void StaticMeshPhong::render_depth_only(GFX::CommandBuffer& cmd, VkDescriptorSet) {
}
void StaticMeshPhong::render_forward(GFX::CommandBuffer& cmd, VkDescriptorSet globalDescriptor,
VkDescriptorSet) {
auto dset = GFX::g_renderContext->dynamic_descriptor_set_begin()
.bind_buffer(0, {g_staticMeshPhong->get_instance_buffer(), 0, VK_WHOLE_SIZE},
VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_SHADER_STAGE_VERTEX_BIT)
.bind_buffer(1, {g_staticMeshPhong->get_instance_index_output_buffer(), 0, VK_WHOLE_SIZE},
VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_SHADER_STAGE_VERTEX_BIT)
.build();
auto imgSet = GFX::g_renderContext->get_texture_registry().get_descriptor_set();
VkDescriptorSet dsets[] = {globalDescriptor, dset, imgSet};
cmd.bind_pipeline(*m_forward);
cmd.bind_descriptor_sets(0, 3, dsets, 0, nullptr);
render_internal(cmd);
}
|
whupdup/frame
|
real/materials/static_mesh_phong.cpp
|
C++
|
gpl-3.0
| 2,737
|
#pragma once
#include <core/local.hpp>
#include <graphics/compute_pipeline.hpp>
#include <graphics/graphics_pipeline.hpp>
#include <graphics/material.hpp>
#include <renderers/static_mesh_instance.hpp>
namespace ZN {
class StaticMeshPhong final : public GFX::MaterialImpl<StaticMeshPhong, StaticMeshInstance> {
public:
explicit StaticMeshPhong();
void indirect_cull(GFX::CommandBuffer&) override;
void render_depth_only(GFX::CommandBuffer&, VkDescriptorSet globalDescriptor) override;
void render_forward(GFX::CommandBuffer&, VkDescriptorSet globalDescriptor,
VkDescriptorSet aoDescriptor) override;
private:
Memory::IntrusivePtr<GFX::ComputePipeline> m_cull;
Memory::IntrusivePtr<GFX::GraphicsPipeline> m_forward;
};
inline Local<StaticMeshPhong> g_staticMeshPhong{};
}
|
whupdup/frame
|
real/materials/static_mesh_phong.hpp
|
C++
|
gpl-3.0
| 797
|
target_sources(LibCommon PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/transform.cpp"
)
|
whupdup/frame
|
real/math/CMakeLists.txt
|
Text
|
gpl-3.0
| 80
|
#pragma once
#include <math/common.hpp>
#include <math/geometric.hpp>
#include <math/matrix3x3.hpp>
#include <math/matrix4x4.hpp>
#include <math/quaternion.hpp>
#include <math/trigonometric.hpp>
#include <math/vector3.hpp>
#include <math/vector4.hpp>
namespace ZN::Math {
struct RowMajorCFrameData {
Math::Vector4 data[3];
};
class CFrame {
public:
static CFrame from_axis_angle(const Vector3& axis, float angle);
static CFrame from_euler_angles_xyz(float rx, float ry, float rz);
static CFrame look_at(const Vector3& eye, const Vector3& center,
const Vector3& up = Vector3(0, 1, 0));
// FIXME: This needs to be but GLM doesn't have enabled for some reason
CFrame() = default;
explicit CFrame(float diagonal)
: m_columns{{diagonal, 0.f, 0.f}, {0.f, diagonal, 0.f}, {0.f, 0.f, diagonal}, {}}
{}
CFrame(float x, float y, float z)
: m_columns{{1.f, 0.f, 0.f}, {0.f, 1.f, 0.f}, {0.f, 0.f, 1.f}, {x, y, z}} {}
explicit CFrame(Vector3 pos)
: m_columns{{1.f, 0.f, 0.f}, {0.f, 1.f, 0.f}, {0.f, 0.f, 1.f}, std::move(pos)} {}
CFrame(Vector3 pos, const Quaternion& rot)
: m_columns{{}, {}, {}, std::move(pos)} {
get_rotation_matrix() = glm::mat3_cast(rot);
}
CFrame(Vector3 pos, Vector3 vX, Vector3 vY, Vector3 vZ)
: m_columns{std::move(vX), std::move(vY), std::move(vZ), std::move(pos)} {}
CFrame(float x, float y, float z, float r00, float r01, float r02, float r10, float r11,
float r12, float r20, float r21, float r22)
: m_columns{{r00, r01, r02}, {r10, r11, r12}, {r20, r21, r22}, {x, y, z}} {}
explicit CFrame(const Matrix4x4& m)
: m_columns{Vector3(m[0]), Vector3(m[1]), Vector3(m[2]), Vector3(m[3])} {}
CFrame& operator+=(const Vector3& v) {
get_position() += v;
return *this;
}
CFrame& operator-=(const Vector3& v) {
get_position() -= v;
return *this;
}
CFrame& operator*=(const CFrame& other) {
get_position() += get_rotation_matrix() * other.get_position();
get_rotation_matrix() *= other.get_rotation_matrix();
return *this;
}
Vector3 operator*(const Vector3& v) const {
return get_rotation_matrix() * v + get_position();
}
CFrame& scale_self_by(const Vector3& v) {
get_rotation_matrix()[0] *= v.x;
get_rotation_matrix()[1] *= v.y;
get_rotation_matrix()[2] *= v.z;
return *this;
}
CFrame scale_by(const Vector3& v) const {
return CFrame(*this).scale_self_by(v);
}
CFrame& fast_inverse_self() {
get_rotation_matrix() = glm::transpose(get_rotation_matrix());
m_columns[3] = get_rotation_matrix() * -m_columns[3];
return *this;
}
CFrame& inverse_self() {
get_rotation_matrix() = glm::inverse(get_rotation_matrix());
m_columns[3] = get_rotation_matrix() * -m_columns[3];
return *this;
}
CFrame fast_inverse() const {
return CFrame(*this).fast_inverse_self();
}
CFrame inverse() const {
return CFrame(*this).inverse_self();
}
Vector3& operator[](size_t index) {
return m_columns[index];
}
const Vector3& operator[](size_t index) const {
return m_columns[index];
}
Matrix3x3& get_rotation_matrix() {
return *reinterpret_cast<Matrix3x3*>(this);
}
const Matrix3x3& get_rotation_matrix() const {
return *reinterpret_cast<const Matrix3x3*>(this);
}
Vector3& get_position() {
return m_columns[3];
}
const Vector3& get_position() const {
return m_columns[3];
}
const Vector3& right_vector() const {
return m_columns[0];
}
const Vector3& up_vector() const {
return m_columns[1];
}
Vector3 look_vector() const {
return -m_columns[2];
}
Matrix4x4 to_matrix4x4() const {
return Matrix4x4(Vector4(m_columns[0], 0.f), Vector4(m_columns[1], 0.f),
Vector4(m_columns[2], 0.f), Vector4(m_columns[3], 1.f));
}
RowMajorCFrameData to_row_major() const {
return {
Math::Vector4{m_columns[0][0], m_columns[1][0], m_columns[2][0], m_columns[3][0]},
Math::Vector4{m_columns[0][1], m_columns[1][1], m_columns[2][1], m_columns[3][1]},
Math::Vector4{m_columns[0][2], m_columns[1][2], m_columns[2][2], m_columns[3][2]},
};
}
void to_euler_angles_xyz(float& x, float& y, float& z) const {
float t1 = Math::atan2(m_columns[2][1], m_columns[2][2]);
float c2 = Math::sqrt(m_columns[0][0] * m_columns[0][0]
+ m_columns[1][0] * m_columns[1][0]);
float t2 = Math::atan2(-m_columns[2][0], c2);
float s1 = Math::sin(t1);
float c1 = Math::cos(t1);
float t3 = Math::atan2(s1 * m_columns[0][2] - c1 * m_columns[0][1],
c1 * m_columns[1][1] - s1 * m_columns[1][2]);
x = -t1;
y = -t2;
z = -t3;
}
private:
Vector3 m_columns[4];
};
inline Math::CFrame operator*(const Math::CFrame& a, const Math::CFrame& b) {
auto result = a;
result *= b;
return result;
}
inline Math::CFrame Math::CFrame::from_axis_angle(const Math::Vector3& axis, float angle) {
float c = Math::cos(angle);
float s = Math::sin(angle);
float t = 1.f - c;
float r00 = c + axis.x * axis.x * t;
float r11 = c + axis.y * axis.y * t;
float r22 = c + axis.z * axis.z * t;
float tmp1 = axis.x * axis.y * t;
float tmp2 = axis.z * s;
float r01 = tmp1 + tmp2;
float r10 = tmp1 - tmp2;
float tmp3 = axis.x * axis.z * t;
float tmp4 = axis.y * s;
float r02 = tmp3 - tmp4;
float r20 = tmp3 + tmp4;
float tmp5 = axis.y * axis.z * t;
float tmp6 = axis.x * s;
float r12 = tmp5 + tmp6;
float r21 = tmp5 - tmp6;
return CFrame(0.f, 0.f, 0.f, r00, r01, r02, r10, r11, r12, r20, r21, r22);
}
inline Math::CFrame Math::CFrame::from_euler_angles_xyz(float rX, float rY, float rZ) {
return from_axis_angle(Vector3(0, 0, 1), rZ)
* from_axis_angle(Vector3(0, 1, 0), rY)
* from_axis_angle(Vector3(1, 0, 0), rX);
}
inline Math::CFrame Math::CFrame::look_at(const Vector3& eye, const Vector3& center,
const Vector3& up) {
auto fwd = Math::normalize(eye - center);
auto right = Math::normalize(Math::cross(up, fwd));
auto actualUp = Math::cross(fwd, right);
return Math::CFrame(eye, right, actualUp, fwd);
}
}
|
whupdup/frame
|
real/math/cframe.hpp
|
C++
|
gpl-3.0
| 6,016
|
#pragma once
#include <cassert>
#include <math/trigonometric.hpp>
#include <math/geometric.hpp>
#include <math/vector2.hpp>
#include <math/vector3.hpp>
#include <math/matrix2x2.hpp>
namespace ZN::Math {
class CFrame2D {
public:
CFrame2D() = default;
CFrame2D(float diagonal)
: m_columns{{diagonal, 0.f}, {0.f, diagonal}, {}} {}
CFrame2D& set_translation(const Vector2& translation) {
m_columns[2] = translation;
return *this;
}
CFrame2D& set_translation(float x, float y) {
m_columns[2][0] = x;
m_columns[2][1] = y;
return *this;
}
CFrame2D& set_rotation(float rotation) {
float s = Math::sin(rotation);
float c = Math::cos(rotation);
m_columns[0][0] = c;
m_columns[0][1] = s;
m_columns[1][0] = -s;
m_columns[1][1] = c;
return *this;
}
CFrame2D& apply_scale(float scale) {
m_columns[0] *= scale;
m_columns[1] *= scale;
return *this;
}
CFrame2D& apply_scale_local(const Vector2& scale) {
m_columns[0] *= scale.x;
m_columns[1] *= scale.y;
return *this;
}
CFrame2D& apply_scale_global(const Vector2& scale) {
m_columns[0] *= scale;
m_columns[1] *= scale;
return *this;
}
CFrame2D& fast_inverse_self() {
get_rotation_matrix() = Math::transpose(get_rotation_matrix());
m_columns[2] *= -1.f;
return *this;
}
CFrame2D fast_inverse() const {
return CFrame2D(*this).fast_inverse_self();
}
Vector2 point_to_local_space(const Vector2& point) const {
return Math::transpose(get_rotation_matrix()) * (point - m_columns[2]);
}
Vector2& operator[](size_t index) {
return m_columns[index];
}
const Vector2& operator[](size_t index) const {
return m_columns[index];
}
CFrame2D& operator+=(const Vector2& c) {
m_columns[2] += c;
return *this;
}
CFrame2D& operator-=(const Vector2& c) {
m_columns[2] -= c;
return *this;
}
CFrame2D& operator*=(const CFrame2D& c) {
m_columns[2] += get_rotation_matrix() * c.m_columns[2];
get_rotation_matrix() *= c.get_rotation_matrix();
return *this;
}
Vector3 row(size_t index) const {
switch (index) {
case 0:
return Vector3(m_columns[0][0], m_columns[1][0], m_columns[2][0]);
case 1:
return Vector3(m_columns[0][1], m_columns[1][1], m_columns[2][1]);
default:
return Vector3();
}
}
Matrix2x2& get_rotation_matrix() {
return *reinterpret_cast<Matrix2x2*>(this);
}
const Matrix2x2& get_rotation_matrix() const {
return *reinterpret_cast<const Matrix2x2*>(this);
}
private:
Vector2 m_columns[3];
};
inline Math::CFrame2D operator*(const Math::CFrame2D& a,
const Math::CFrame2D& b) {
auto result = a;
result *= b;
return result;
}
inline Math::Vector2 operator*(const Math::CFrame2D& c, const Math::Vector3& v) {
return Math::Vector2(Math::dot(c.row(0), v), Math::dot(c.row(1), v));
}
inline Math::CFrame2D operator+(const Math::CFrame2D& c, const Math::Vector2& v) {
auto result = c;
result += v;
return result;
}
inline Math::CFrame2D operator-(const Math::CFrame2D& c, const Math::Vector2& v) {
auto result = c;
result -= v;
return result;
}
}
|
whupdup/frame
|
real/math/cframe2d.hpp
|
C++
|
gpl-3.0
| 3,144
|
#pragma once
#include <cstdint>
#include <math/vector4.hpp>
#include <math/color3uint8.hpp>
namespace ZN::Math {
struct Color3 {
static constexpr Color3 from_rgb(float r, float g, float b) {
return Color3(r / 255.f, g / 255.f, b / 255.f);
}
constexpr Color3()
: r(0.f)
, g(0.f)
, b(0.f) {}
constexpr Color3(float rIn, float gIn, float bIn)
: r(rIn)
, g(gIn)
, b(bIn) {}
constexpr Color3(uint32_t argb)
: r(static_cast<float>((argb >> 16) & 0xFF) / 255.f)
, g(static_cast<float>((argb >> 8) & 0xFF) / 255.f)
, b(static_cast<float>(argb & 0xFF) / 255.f) {}
constexpr Color3(Color3uint8 c3u8)
: r(static_cast<float>((c3u8.argb >> 16) & 0xFF) / 255.f)
, g(static_cast<float>((c3u8.argb >> 8) & 0xFF) / 255.f)
, b(static_cast<float>((c3u8.argb & 0xFF) / 255.f)) {}
Math::Vector4 to_vector4(float alpha) const {
return Math::Vector4(r, g, b, alpha);
}
constexpr bool operator==(const Color3& other) const {
// FIXME: maybe epsilon comparison
return r == other.r && g == other.g && b == other.b;
}
float r;
float g;
float b;
};
constexpr Math::Color3 operator*(const Math::Color3& color, float s) {
return Math::Color3(color.r * s, color.g * s, color.b * s);
}
constexpr Math::Color3 operator*(float s, const Math::Color3& color) {
return color * s;
}
}
|
whupdup/frame
|
real/math/color3.hpp
|
C++
|
gpl-3.0
| 1,321
|
#pragma once
#include <cstdint>
namespace ZN::Math {
struct Color3uint8 {
explicit Color3uint8() = default;
explicit Color3uint8(uint32_t argbIn)
: argb(argbIn) {}
explicit Color3uint8(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 0xFF)
: argb(b | (g << 8) | (r << 16) | (a << 24)) {}
uint32_t argb;
constexpr bool operator==(Color3uint8 other) const {
return argb == other.argb;
}
};
}
|
whupdup/frame
|
real/math/color3uint8.hpp
|
C++
|
gpl-3.0
| 407
|
#pragma once
#include <cmath>
namespace ZN::Math {
using std::fma;
using std::pow;
using std::abs;
using std::sqrt;
template <typename T>
constexpr const T& min(const T& a, const T& b) {
return (b < a) ? b : a;
}
template <typename T>
constexpr const T& max(const T& a, const T& b) {
return (b < a) ? a : b;
}
template <typename T>
constexpr T clamp(T v, T vMin, T vMax) {
return Math::min(Math::max(v, vMin), vMax);
}
}
|
whupdup/frame
|
real/math/common.hpp
|
C++
|
gpl-3.0
| 433
|
#pragma once
#include <glm/geometric.hpp>
namespace ZN::Math {
using glm::dot;
using glm::floor;
using glm::ceil;
using glm::length;
using glm::normalize;
using glm::cross;
}
|
whupdup/frame
|
real/math/geometric.hpp
|
C++
|
gpl-3.0
| 180
|
#pragma once
#include <glm/matrix.hpp>
namespace ZN::Math {
using glm::transpose;
}
|
whupdup/frame
|
real/math/matrix.hpp
|
C++
|
gpl-3.0
| 89
|
#pragma once
#include <math/matrix.hpp>
#include <glm/mat2x2.hpp>
namespace ZN::Math {
using Matrix2x2 = glm::mat2;
}
|
whupdup/frame
|
real/math/matrix2x2.hpp
|
C++
|
gpl-3.0
| 124
|
#pragma once
#include <glm/mat3x3.hpp>
namespace ZN::Math {
using Matrix3x3 = glm::mat3;
}
|
whupdup/frame
|
real/math/matrix3x3.hpp
|
C++
|
gpl-3.0
| 96
|
#pragma once
#include <glm/mat4x4.hpp>
namespace ZN::Math {
using Matrix4x4 = glm::mat4;
}
|
whupdup/frame
|
real/math/matrix4x4.hpp
|
C++
|
gpl-3.0
| 96
|
#pragma once
#include <math/vector4.hpp>
#include <math/matrix4x4.hpp>
#include <math/trigonometric.hpp>
namespace ZN::Math {
// for Vulkan reverse-Z
inline Math::Matrix4x4 infinite_perspective(float fov, float aspectRatio, float zNear) {
float tanHalfFOV = Math::tan(fov * 0.5f);
return Math::Matrix4x4(
1.f / (tanHalfFOV * aspectRatio), 0.f, 0.f, 0.f,
0.f, -1.f / tanHalfFOV, 0.f, 0.f,
0.f, 0.f, 0.f, -1.f,
0.f, 0.f, zNear, 0.f
);
}
inline Math::Matrix4x4 inverse_infinite_perspective(float fov, float aspectRatio, float zNear) {
float tanHalfFOV = Math::tan(fov * 0.5f);
return Math::Matrix4x4(
tanHalfFOV * aspectRatio, 0.f, 0.f, 0.f,
0.f, -tanHalfFOV, 0.f, 0.f,
0.f, 0.f, 0.f, 1.f / zNear,
0.f, 0.f, -1.f, 0.f
);
}
// values (x, y, z, w) such that:
// vec3(fma(gl_FragCoord.xy * vec2(1.0, -1.0), values.xx, values.yz), values.w) / depth
// will be equivalent to:
// vec4 h = (inverse(perspective) * vec4(clipSpaceFragCoord, depth, 1.0));
// h / h.w;
inline Math::Vector4 infinite_perspective_clip_to_view_space_deprojection(float fov,
float width, float height, float zNear) {
float tanHalfFOV = Math::tan(fov * 0.5f);
return Math::Vector4(2.f * zNear * tanHalfFOV / height, -zNear * tanHalfFOV * width / height,
zNear * tanHalfFOV, -zNear);
}
// The size in pixels of a 1 unit object if viewed from 1 unit away
inline float image_plane_pixels_per_unit(float fov, float width) {
float scale = -2.f * Math::tan(fov * 0.5f);
return width / scale;
}
}
|
whupdup/frame
|
real/math/matrix_projection.hpp
|
C++
|
gpl-3.0
| 1,498
|
#pragma once
#include <glm/gtc/quaternion.hpp>
namespace ZN::Math {
using Quaternion = glm::quat;
}
|
whupdup/frame
|
real/math/quaternion.hpp
|
C++
|
gpl-3.0
| 105
|
#pragma once
#include <math/common.hpp>
#include <math/vector2.hpp>
namespace ZN::Math {
struct Rect {
constexpr Rect()
: xMin(0.f)
, yMin(0.f)
, xMax(0.f)
, yMax(0.f) {}
constexpr Rect(float xMinIn, float yMinIn, float xMaxIn, float yMaxIn)
: xMin(xMinIn)
, yMin(yMinIn)
, xMax(xMaxIn)
, yMax(yMaxIn) {}
Rect(const Math::Vector2& minIn, const Math::Vector2& maxIn)
: xMin(minIn.x)
, yMin(minIn.y)
, xMax(maxIn.x)
, yMax(maxIn.y) {}
Rect& operator+=(const Math::Vector2& v);
Rect& operator-=(const Math::Vector2& v);
Rect intersection(const Rect& other) const;
Vector2 centroid() const;
Vector2 size() const;
Vector2 min() const;
Vector2 max() const;
bool valid() const;
bool contains(const Math::Vector2& point) const;
float xMin;
float yMin;
float xMax;
float yMax;
};
// Global operator overloads
inline Math::Rect operator+(const Math::Rect& r, const Math::Vector2& v) {
auto result = r;
result += v;
return result;
}
inline Math::Rect operator+(const Math::Vector2& v, const Math::Rect& r) {
return r + v;
}
inline Math::Rect operator-(const Math::Rect& r, const Math::Vector2& v) {
auto result = r;
result -= v;
return result;
}
inline Math::Rect operator-(const Math::Vector2& v, const Math::Rect& r) {
return r - v;
}
// Methods
inline Math::Rect& Math::Rect::operator+=(const Math::Vector2& v) {
xMin += v.x;
yMin += v.y;
xMax += v.x;
yMax += v.y;
return *this;
}
inline Math::Rect& Math::Rect::operator-=(const Math::Vector2& v) {
xMin -= v.x;
yMin -= v.y;
xMax -= v.x;
yMax -= v.y;
return *this;
}
inline Math::Rect Math::Rect::intersection(const Math::Rect& other) const {
return Math::Rect(Math::max(xMin, other.xMin), Math::max(yMin, other.yMin),
Math::min(xMax, other.xMax), Math::min(yMax, other.yMax));
}
inline Math::Vector2 Math::Rect::centroid() const {
return Math::Vector2((xMin + xMax) * 0.5f, (yMin + yMax) * 0.5f);
}
inline Math::Vector2 Math::Rect::size() const {
return Math::Vector2(xMax - xMin, yMax - yMin);
}
inline Math::Vector2 Math::Rect::min() const {
return Math::Vector2(xMin, yMin);
}
inline Math::Vector2 Math::Rect::max() const {
return Math::Vector2(xMax, yMax);
}
inline bool Math::Rect::valid() const {
return xMin < xMax && yMin < yMax;
}
inline bool Math::Rect::contains(const Math::Vector2& point) const {
return point.x >= xMin && point.x <= xMax && point.y >= yMin && point.y <= yMax;
}
}
|
whupdup/frame
|
real/math/rect.hpp
|
C++
|
gpl-3.0
| 2,447
|
#include "transform.hpp"
#include <glm/gtx/transform.hpp>
#include <math/common.hpp>
using namespace ZN::Math;
static Quaternion my_nlerp(const Quaternion& from, const Quaternion& to, float inc,
bool shortest) {
if (shortest && glm::dot(from, to) < 0.f) {
return glm::normalize(from + (-to - from) * inc);
}
else {
return glm::normalize(from + (to - from) * inc);
}
}
static Quaternion my_slerp(const Quaternion& from, const Quaternion& to, float inc,
bool shortest) {
float cs = glm::dot(from, to);
Quaternion correctedTo = to;
if (shortest && cs < 0.f) {
cs = -cs;
correctedTo = -to;
}
if (cs >= 0.9999f || cs <= -0.9999f) {
return my_nlerp(from, correctedTo, inc, false);
}
float sn = sqrt(1.f - cs * cs);
float angle = atan2(sn, cs);
float invSin = 1.f / sn;
float srcFactor = sin((1.f - inc) * angle) * invSin;
float dstFactor = sin(inc * angle) * invSin;
return from * srcFactor + correctedTo * dstFactor;
}
void Transform::mix(const Transform& other, float factor, Transform& dest) const {
dest.position = glm::mix(position, other.position, factor);
//dest.rotation = glm::mix(rotation, other.rotation, factor);
dest.rotation = my_slerp(rotation, other.rotation, factor, true);
dest.scale = glm::mix(scale, other.scale, factor);
}
CFrame Transform::to_cframe() const {
return CFrame(position, rotation).scale_self_by(scale);
}
Matrix4x4 Transform::to_matrix() const {
return glm::scale(glm::translate(Matrix4x4(1.f), position) * glm::mat4_cast(rotation), scale);
}
|
whupdup/frame
|
real/math/transform.cpp
|
C++
|
gpl-3.0
| 1,522
|
#pragma once
#include <math/vector3.hpp>
#include <math/quaternion.hpp>
#include <math/matrix4x4.hpp>
#include <math/cframe.hpp>
namespace ZN::Math {
struct Transform {
void mix(const Transform& other, float factor, Transform& dest) const;
CFrame to_cframe() const;
Matrix4x4 to_matrix() const;
Vector3 position;
Quaternion rotation;
Vector3 scale;
};
}
|
whupdup/frame
|
real/math/transform.hpp
|
C++
|
gpl-3.0
| 367
|
#pragma once
#include <cmath>
#include <glm/trigonometric.hpp>
#ifndef M_PI
#define M_PI 3.141592653589793238462
#endif
namespace ZN::Math {
using std::sin;
using std::cos;
using std::tan;
using std::atan2;
using glm::radians;
using glm::degrees;
}
|
whupdup/frame
|
real/math/trigonometric.hpp
|
C++
|
gpl-3.0
| 256
|
#pragma once
#include <cstdint>
#include <math/vector2.hpp>
namespace ZN::Math {
struct UDim {
float scale;
int32_t offset;
constexpr bool operator==(const UDim& other) const {
return scale == other.scale && offset == other.offset;
}
constexpr bool operator!=(const UDim& other) const {
return !(*this == other);
}
};
struct UDim2 {
UDim x;
UDim y;
Math::Vector2 get_scale() const {
return Math::Vector2(x.scale, y.scale);
}
Math::Vector2 get_offset() const {
return Math::Vector2(static_cast<float>(x.offset), static_cast<float>(y.offset));
}
constexpr bool operator==(const UDim2& other) const {
return x == other.x && y == other.y;
}
constexpr bool operator!=(const UDim2& other) const {
return !(*this == other);
}
};
}
|
whupdup/frame
|
real/math/udim.hpp
|
C++
|
gpl-3.0
| 765
|
#pragma once
#include <glm/vec2.hpp>
namespace ZN::Math {
using Vector2 = glm::vec2;
}
|
whupdup/frame
|
real/math/vector2.hpp
|
C++
|
gpl-3.0
| 92
|
#pragma once
#include <glm/vec3.hpp>
namespace ZN::Math {
using Vector3 = glm::vec3;
}
|
whupdup/frame
|
real/math/vector3.hpp
|
C++
|
gpl-3.0
| 92
|
#pragma once
#include <glm/vec4.hpp>
namespace ZN::Math {
using Vector4 = glm::vec4;
}
|
whupdup/frame
|
real/math/vector4.hpp
|
C++
|
gpl-3.0
| 92
|
target_sources(LibCommon PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/game_renderer.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/static_mesh_pool.cpp"
)
|
whupdup/frame
|
real/renderers/CMakeLists.txt
|
Text
|
gpl-3.0
| 136
|
#include "game_renderer.hpp"
#include <core/logging.hpp>
#include <core/threading.hpp>
#include <graphics/render_context.hpp>
#include <graphics/vk_common.hpp>
#include <materials/static_mesh_phong.hpp>
#include <math/common.hpp>
#include <math/matrix_projection.hpp>
#include <renderers/static_mesh_pool.hpp>
#include <services/application.hpp>
#include <TracyVulkan.hpp>
using namespace ZN;
static constexpr const std::string_view g_defaultSkyboxFileNames[] = {
"res://sky512_ft.dds",
"res://sky512_bk.dds",
"res://sky512_up.dds",
"res://sky512_dn.dds",
"res://sky512_rt.dds",
"res://sky512_lf.dds",
};
static constexpr VkFormat g_depthFormat = VK_FORMAT_D32_SFLOAT;
static constexpr VkFormat g_depthPyramidFormat = VK_FORMAT_R32_SFLOAT;
GameRenderer::GameRenderer() {
g_staticMeshPool.create();
g_staticMeshPhong.create();
buffers_init();
frame_data_init();
}
GameRenderer::~GameRenderer() {
g_staticMeshPhong.destroy();
g_staticMeshPool.destroy();
}
void GameRenderer::render() {
ZoneScopedN("Render");
g_staticMeshPool->update();
update_buffers();
ScopedLock swapcahinLock(*GFX::g_renderContext->get_swapchain_mutex());
GFX::g_renderContext->frame_begin();
indirect_cull();
forward_pass();
GFX::g_renderContext->frame_end();
}
void GameRenderer::update_camera(const Math::Vector3& position, const Math::Matrix4x4& view) {
m_cameraData.view = view;
m_cameraData.position = position;
Math::Vector3 viewSunlightDir(view * Math::Vector4(m_sunlightDirection, 0.f));
memcpy(&m_sceneData.sunlightDirection, &viewSunlightDir, sizeof(Math::Vector3));
}
void GameRenderer::set_sunlight_dir(const Math::Vector3& dir) {
m_sunlightDirection = dir;
Math::Vector3 viewSunlightDir(m_cameraData.view * Math::Vector4(m_sunlightDirection, 0.f));
memcpy(&m_sceneData.sunlightDirection, &viewSunlightDir, sizeof(Math::Vector3));
}
void GameRenderer::set_brightness(float brightness) {
m_sceneData.sunlightDirection.w = brightness;
}
void GameRenderer::buffers_init() {
ZoneScopedN("Buffers");
auto proj = Math::infinite_perspective(glm::radians(70.f),
static_cast<float>(g_window->get_aspect_ratio()), 0.1f);
auto fWidth = static_cast<float>(g_window->get_width());
auto fHeight = static_cast<float>(g_window->get_height());
m_cameraData.projInfo = Math::infinite_perspective_clip_to_view_space_deprojection(
glm::radians(70.f), fWidth, fHeight, 0.1f);
m_cameraData.projection = std::move(proj);
m_cameraData.view = Math::Matrix4x4(1.f);
m_cameraData.screenSize = Math::Vector2(fWidth, fHeight);
g_window->resize_event().connect([&](int width, int height) {
auto fWidth = static_cast<float>(width);
auto fHeight = static_cast<float>(height);
auto proj = Math::infinite_perspective(glm::radians(70.f),
static_cast<float>(g_window->get_aspect_ratio()), 0.1f);
m_cameraData.projInfo = Math::infinite_perspective_clip_to_view_space_deprojection(
glm::radians(70.f), fWidth, fHeight, 0.1f);
m_cameraData.projection = std::move(proj);
m_cameraData.screenSize = Math::Vector2(fWidth, fHeight);
});
auto scenePaddedSize = GFX::g_renderContext->pad_uniform_buffer_size(sizeof(SceneData));
auto cameraPaddedSize = GFX::g_renderContext->pad_uniform_buffer_size(sizeof(CameraData));
auto sceneDataBufferSize = GFX::FRAMES_IN_FLIGHT * scenePaddedSize;
auto cameraDataBufferSize = GFX::FRAMES_IN_FLIGHT * cameraPaddedSize;
m_sceneDataBuffer = GFX::Buffer::create(sceneDataBufferSize,
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VMA_MEMORY_USAGE_CPU_TO_GPU);
m_cameraDataBuffer = GFX::Buffer::create(cameraDataBufferSize,
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VMA_MEMORY_USAGE_CPU_TO_GPU);
// FIXME: this probably belongs in lighting init
m_sunlightDirection = Math::Vector3(1, 0, 0);
m_sceneData.ambientColor = Math::Vector4(1, 1, 1, 0.3f);
m_sceneData.sunlightDirection = Math::Vector4(1, 0, 0, 1);
m_sceneData.sunlightColor = Math::Vector4(1, 1, 1, 1);
for (size_t i = 0; i < GFX::FRAMES_IN_FLIGHT; ++i) {
memcpy(m_sceneDataBuffer->map() + i * scenePaddedSize, &m_sceneData, sizeof(SceneData));
memcpy(m_cameraDataBuffer->map() + i * cameraPaddedSize, &m_cameraData,
sizeof(CameraData));
}
}
void GameRenderer::frame_data_init() {
ZoneScopedN("Frame Data");
auto scenePaddedSize = GFX::g_renderContext->pad_uniform_buffer_size(sizeof(SceneData));
auto cameraPaddedSize = GFX::g_renderContext->pad_uniform_buffer_size(sizeof(CameraData));
for (size_t i = 0; i < GFX::FRAMES_IN_FLIGHT; ++i) {
auto& frame = m_frames[i];
VkDescriptorBufferInfo camBuf{};
camBuf.buffer = *m_cameraDataBuffer;
camBuf.offset = i * cameraPaddedSize;
camBuf.range = sizeof(CameraData);
VkDescriptorBufferInfo sceneBuf{};
sceneBuf.buffer = *m_sceneDataBuffer;
sceneBuf.offset = i * scenePaddedSize;
sceneBuf.range = sizeof(SceneData);
//auto depthInputInfo = vkinit::descriptor_image_info(*m_viewDepthBuffer);
frame.globalDescriptor = GFX::g_renderContext->global_descriptor_set_begin()
.bind_buffer(0, camBuf, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT)
.bind_buffer(1, sceneBuf, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT)
.build();
//frame.depthInputDescriptor = GFX::g_renderContext->global_descriptor_set_begin()
// .bind_image(0, depthInputInfo, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,
// VK_SHADER_STAGE_FRAGMENT_BIT)
// .build();
}
}
// UPDATE METHODS
void GameRenderer::update_buffers() {
auto scenePaddedSize = GFX::g_renderContext->pad_uniform_buffer_size(sizeof(SceneData));
auto cameraPaddedSize = GFX::g_renderContext->pad_uniform_buffer_size(sizeof(CameraData));
auto frameIndex = GFX::g_renderContext->get_frame_index();
memcpy(m_sceneDataBuffer->map() + frameIndex * scenePaddedSize, &m_sceneData,
sizeof(SceneData));
memcpy(m_cameraDataBuffer->map() + frameIndex * cameraPaddedSize, &m_cameraData,
sizeof(CameraData));
}
void GameRenderer::indirect_cull() {
auto& graph = GFX::g_renderContext->get_frame_graph();
auto& copyPass = graph.add_pass();
auto& cullPass = graph.add_pass();
copyPass.add_buffer(g_staticMeshPool->get_gpu_indirect_buffer(), GFX::ResourceAccess::WRITE,
VK_PIPELINE_STAGE_TRANSFER_BIT);
copyPass.add_command_callback([&](auto& cmd) {
VkBufferCopy copy{
.srcOffset = 0,
.dstOffset = 0,
.size = g_staticMeshPool->get_zeroed_indirect_buffer().get_size()
};
cmd.copy_buffer(g_staticMeshPool->get_zeroed_indirect_buffer(),
g_staticMeshPool->get_gpu_indirect_buffer(), 1, ©);
});
cullPass.add_buffer(g_staticMeshPool->get_gpu_indirect_buffer(),
GFX::ResourceAccess::READ_WRITE, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
GFX::Material::for_each_material([&](auto& material) {
cullPass.add_buffer(material.get_instance_buffer(), GFX::ResourceAccess::READ,
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
cullPass.add_buffer(material.get_instance_index_buffer(),
GFX::ResourceAccess::READ, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
cullPass.add_buffer(material.get_instance_index_output_buffer(),
GFX::ResourceAccess::WRITE, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
});
cullPass.add_command_callback([](auto& cmd) {
GFX::Material::for_each_material([&](auto& material) {
material.indirect_cull(cmd);
});
});
}
void GameRenderer::forward_pass() {
auto& graph = GFX::g_renderContext->get_frame_graph();
auto& pass = graph.add_pass();
auto& frame = m_frames[GFX::g_renderContext->get_frame_index()];
pass.add_color_attachment(GFX::g_renderContext->get_swapchain_image_view(),
GFX::ResourceAccess::WRITE);
GFX::Material::for_each_material([&](auto& material) {
pass.add_buffer(material.get_mesh_pool().get_gpu_indirect_buffer(),
GFX::ResourceAccess::READ, VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT);
pass.add_buffer(material.get_mesh_pool().get_vertex_buffer(), GFX::ResourceAccess::READ,
VK_PIPELINE_STAGE_VERTEX_INPUT_BIT);
pass.add_buffer(material.get_mesh_pool().get_index_buffer(), GFX::ResourceAccess::READ,
VK_PIPELINE_STAGE_VERTEX_INPUT_BIT);
pass.add_buffer(material.get_instance_buffer(), GFX::ResourceAccess::READ,
VK_PIPELINE_STAGE_VERTEX_SHADER_BIT);
pass.add_buffer(material.get_instance_index_output_buffer(), GFX::ResourceAccess::READ,
VK_PIPELINE_STAGE_VERTEX_SHADER_BIT);
});
Memory::IntrusivePtr<GFX::ImageView> readyTexture{};
while (GFX::g_renderContext->get_ready_image(readyTexture)) {
pass.add_texture(*readyTexture, GFX::ResourceAccess::READ,
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
}
pass.add_command_callback([globalDescriptor=frame.globalDescriptor](auto& cmd) {
GFX::Material::for_each_material([&](auto& material) {
material.render_forward(cmd, globalDescriptor, VK_NULL_HANDLE);
});
});
}
|
whupdup/frame
|
real/renderers/game_renderer.cpp
|
C++
|
gpl-3.0
| 8,840
|
#pragma once
#include <core/common.hpp>
#include <core/local.hpp>
#include <core/threading.hpp>
#include <graphics/graphics_fwd.hpp>
#include <graphics/image_view.hpp>
#include <math/matrix4x4.hpp>
#include <math/vector2.hpp>
#include <math/vector3.hpp>
#include <math/vector4.hpp>
namespace ZN {
class GameRenderer final {
public:
explicit GameRenderer();
~GameRenderer();
void render();
void update_camera(const Math::Vector3& position, const Math::Matrix4x4& view);
void set_sunlight_dir(const Math::Vector3& dir);
void set_brightness(float brightness);
//void set_skybox(GFX::TextureHandle skybox);
void set_default_skybox();
NULL_COPY_AND_ASSIGN(GameRenderer);
private:
struct FrameData {
VkDescriptorSet globalDescriptor;
};
struct SceneData {
Math::Vector4 fogColor; // w is for exponent
Math::Vector4 fogDistances; // x = min, y = max, zw unused
Math::Vector4 ambientColor;
Math::Vector4 sunlightDirection; // w for sun power
Math::Vector4 sunlightColor;
};
struct CameraData {
Math::Matrix4x4 view;
Math::Matrix4x4 projection;
Math::Vector3 position;
float padding0;
Math::Vector4 projInfo;
Math::Vector2 screenSize;
};
FrameData m_frames[GFX::FRAMES_IN_FLIGHT];
Math::Vector3 m_sunlightDirection;
CameraData m_cameraData;
SceneData m_sceneData;
Memory::IntrusivePtr<GFX::Buffer> m_sceneDataBuffer;
Memory::IntrusivePtr<GFX::Buffer> m_cameraDataBuffer;
void buffers_init();
void frame_data_init();
void update_buffers();
void update_instances(GFX::CommandBuffer&);
void indirect_cull();
void forward_pass();
};
inline Local<GameRenderer> g_renderer;
}
|
whupdup/frame
|
real/renderers/game_renderer.hpp
|
C++
|
gpl-3.0
| 1,674
|
#pragma once
#include <math/cframe.hpp>
namespace ZN {
struct StaticMeshInstance {
Math::RowMajorCFrameData cframe;
};
}
|
whupdup/frame
|
real/renderers/static_mesh_instance.hpp
|
C++
|
gpl-3.0
| 127
|
#include "static_mesh_pool.hpp"
#include <core/fixed_array.hpp>
using namespace ZN;
static constexpr FixedArray g_inputAttribDescriptions = {
VkVertexInputAttributeDescription{0, 0, VK_FORMAT_R32G32B32_SFLOAT,
offsetof(StaticMeshPool::Vertex, position)},
VkVertexInputAttributeDescription{1, 0, VK_FORMAT_R32G32B32_SFLOAT,
offsetof(StaticMeshPool::Vertex, normal)},
VkVertexInputAttributeDescription{2, 0, VK_FORMAT_R32G32B32_SFLOAT,
offsetof(StaticMeshPool::Vertex, tangent)},
VkVertexInputAttributeDescription{3, 0, VK_FORMAT_R32G32B32_SFLOAT,
offsetof(StaticMeshPool::Vertex, texCoord)}
};
static constexpr FixedArray g_inputBindingDescriptions = {
VkVertexInputBindingDescription{0, sizeof(StaticMeshPool::Vertex), VK_VERTEX_INPUT_RATE_VERTEX}
};
Span<const VkVertexInputAttributeDescription> StaticMeshPool::input_attribute_descriptions() {
return g_inputAttribDescriptions;
}
Span<const VkVertexInputBindingDescription> StaticMeshPool::input_binding_descriptions() {
return g_inputBindingDescriptions;
}
Memory::IntrusivePtr<GFX::Mesh> StaticMeshPool::create_mesh(uint32_t vertexCount,
uint32_t indexCount, GFX::Buffer& srcVertexBuffer, GFX::Buffer& srcIndexBuffer,
VkDeviceSize srcVertexOffset, VkDeviceSize srcIndexOffset) {
auto mesh = create_mesh_internal(vertexCount, indexCount);
upload_mesh_internal(*mesh, srcVertexBuffer, srcIndexBuffer, srcVertexOffset,
srcIndexOffset, static_cast<VkDeviceSize>(vertexCount), sizeof(Vertex),
sizeof(uint32_t));
return mesh;
}
|
whupdup/frame
|
real/renderers/static_mesh_pool.cpp
|
C++
|
gpl-3.0
| 1,519
|
#pragma once
#include <core/local.hpp>
#include <core/span.hpp>
#include <graphics/owning_mesh_pool.hpp>
#include <math/vector2.hpp>
#include <math/vector3.hpp>
namespace ZN {
class StaticMeshPool final : public GFX::OwningMeshPool {
public:
struct Vertex {
Math::Vector3 position;
Math::Vector3 normal;
Math::Vector3 tangent;
Math::Vector2 texCoord;
};
static Span<const VkVertexInputAttributeDescription> input_attribute_descriptions();
static Span<const VkVertexInputBindingDescription> input_binding_descriptions();
[[nodiscard]] Memory::IntrusivePtr<GFX::Mesh> create_mesh(uint32_t vertexCount,
uint32_t indexCount, GFX::Buffer& srcVertexBuffer, GFX::Buffer& srcIndexBuffer,
VkDeviceSize srcVertexOffset, VkDeviceSize srcIndexOffset);
constexpr VkIndexType get_index_type() const override {
return VK_INDEX_TYPE_UINT32;
}
};
inline Local<StaticMeshPool> g_staticMeshPool = {};
}
|
whupdup/frame
|
real/renderers/static_mesh_pool.hpp
|
C++
|
gpl-3.0
| 933
|
target_sources(LibCommon PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/task_scheduler.cpp"
)
|
whupdup/frame
|
real/scheduler/CMakeLists.txt
|
Text
|
gpl-3.0
| 85
|
#pragma once
#include <core/badge.hpp>
#include <core/local.hpp>
#include <scheduler/task_scheduler.hpp>
namespace ZN::Scheduler {
template <typename T>
class Promise;
namespace Detail {
template <typename T>
class FutureSharedState final : public BaseSignal,
public Memory::ThreadSafeIntrusivePtrEnabled<FutureSharedState<T>> {
public:
explicit FutureSharedState(Badge<Promise<T>>)
: BaseSignal(1) {}
void set_value(const T& value) {
if (signaled()) {
return;
}
m_value.create(value);
decrement();
}
void set_value(T&& value) {
if (signaled()) {
return;
}
m_value.create(std::move(value));
decrement();
}
T release_value() {
return std::move(*m_value);
}
bool has_value() const {
return m_value;
}
private:
// FIXME: integrate ErrorOr?
Local<T> m_value;
};
}
template <typename T>
class Future final {
public:
using state_type = Detail::FutureSharedState<T>;
explicit Future(IntrusivePtr<state_type> state)
: m_state(std::move(state)) {}
Future(Future&&) noexcept = default;
Future& operator=(Future&&) noexcept = default;
Future(const Future&) = delete;
void operator=(const Future&) = delete;
T get() {
return std::move(m_state->release_value());
}
bool has_value() const {
return m_state->has_value();
}
void wait() {
if (!m_state->signaled()) {
m_state->await();
}
}
private:
IntrusivePtr<state_type> m_state;
};
template <typename T>
class Promise final {
public:
using state_type = Detail::FutureSharedState<T>;
Promise()
: m_state(new state_type({})) {}
Promise(Promise&&) noexcept = default;
Promise& operator=(Promise&&) noexcept = default;
Promise(const Promise&) = delete;
void operator=(const Promise&) = delete;
void set_value(const T& value) {
m_state->set_value(value);
}
void set_value(T&& value) {
m_state->set_value(std::forward<T>(value));
}
Future<T> get_future() {
return Future<T>(m_state);
}
private:
IntrusivePtr<state_type> m_state;
};
}
|
whupdup/frame
|
real/scheduler/future.hpp
|
C++
|
gpl-3.0
| 2,050
|
#include "task_scheduler.hpp"
#include <core/threading.hpp>
#include <core/logging.hpp>
#include <core/system_info.hpp>
#include <blockingconcurrentqueue.h>
#include <cstdlib>
#include <vector>
#define ZN_FIBER_STACK_GUARD_PAGES
#ifdef __SANITIZE_ADDRESS__
extern "C" {
void __sanitizer_start_switch_fiber(void** fakeStackSave, const void* bottom, size_t size);
void __sanitizer_finish_switch_fiber(void* fakeStackSave, const void** bottom, size_t* sizeOld);
}
#define ZN_HAS_ASAN
#endif
#ifdef __SANITIZER_THREAD__
extern "C" {
void* __tsan_get_current_fiber(void);
void* __tsan_create_fiber(unsigned flags);
void* __tsan_destroy_fiber(void* fiber);
void* __tsan_switch_to_fiber(void* fiber, unsigned flags);
}
#define ZN_HAS_TSAN
#endif
using namespace ZN;
using namespace ZN::Scheduler;
namespace ZN::Scheduler {
struct ThreadLocalData {
moodycamel::ConcurrentQueue<ExistingJob> localJobs;
moodycamel::ConcurrentQueue<uint8_t*> freeStackMemory;
ExistingJob currentJob;
BaseSignal* yieldedToSignal;
#ifdef ZN_HAS_TSAN
void* tsanWorkerFiber;
void* tsanCalleeFiber;
#endif
};
}
static constexpr const size_t STACK_SIZE = 64 * 1024;
static std::vector<IntrusivePtr<OS::Thread>> g_workers;
static std::vector<IntrusivePtr<OS::Thread>> g_blockingThreadPool;
static moodycamel::ConcurrentQueue<NewJob> g_newJobs;
static std::atomic_flag g_finished = ATOMIC_FLAG_INIT;
static std::vector<ThreadLocalData> g_threadLocalData;
thread_local uint32_t g_threadIndex = ~0U;
static moodycamel::BlockingConcurrentQueue<NewJob> g_blockingNewJobs;
static void worker_proc(void*);
static void blocking_worker_proc(void*);
static uint8_t* alloc_stack(size_t size);
static void free_stack(uint8_t*);
template <typename T>
constexpr T round_up(T value, T multiple) {
return ((value + multiple - 1) / multiple) * multiple;
}
void Scheduler::init() {
auto numProcs = SystemInfo::get_num_processors();
g_workers.resize(numProcs);
g_threadLocalData.resize(numProcs);
g_blockingThreadPool.resize(numProcs); // FIXME: make this dynamically grow and shrink
for (uint32_t i = 0; i < numProcs; ++i) {
g_workers[i] = OS::Thread::create(worker_proc,
reinterpret_cast<void*>(static_cast<uintptr_t>(i)));
g_workers[i]->set_cpu_affinity(1ull << i);
g_workers[i]->block_signals();
g_blockingThreadPool[i] = OS::Thread::create(blocking_worker_proc, nullptr);
g_blockingThreadPool[i]->block_signals();
}
}
void Scheduler::deinit() {
g_finished.test_and_set(std::memory_order_acq_rel);
g_finished.notify_all();
for (size_t i = 0; i < g_blockingThreadPool.size(); ++i) {
g_blockingNewJobs.enqueue({});
}
g_blockingThreadPool.clear();
g_workers.clear();
g_threadLocalData.clear();
}
void Scheduler::queue_job(void* userData, SignalHandle decrementOnFinish,
const SignalHandle& precondition, JobProc* proc) {
if (!precondition || precondition->signaled()) {
g_newJobs.enqueue({proc, userData, std::move(decrementOnFinish)});
}
else {
precondition->add_job({proc, userData, std::move(decrementOnFinish)});
}
}
void Scheduler::queue_blocking_job(void* userData, SignalHandle decrementOnFinish, JobProc* proc) {
g_blockingNewJobs.enqueue({proc, userData, std::move(decrementOnFinish)});
}
// Signal
IntrusivePtr<Signal> Signal::create(int32_t count) {
return IntrusivePtr(new Signal(count));
}
BaseSignal::BaseSignal(int32_t count)
: m_signal(count)
, m_waitedOnExternally(false) {}
void BaseSignal::increment(int32_t count) {
assert(count > 0 && "increment_signal(): count must be > 0");
auto val = m_signal.load(std::memory_order_relaxed);
while (val > 0 && !m_signal.compare_exchange_weak(val, val + count,
std::memory_order_release, std::memory_order_relaxed));
}
void BaseSignal::decrement() {
if (m_signal.fetch_sub(1, std::memory_order_release) == 1) {
if (m_waitedOnExternally) {
m_waitedOnExternally = false;
m_signal.notify_all();
}
release_jobs();
}
}
void BaseSignal::await() {
if (g_threadIndex == ~0U) {
m_waitedOnExternally = true;
auto value = m_signal.load();
while (value > 0) {
m_signal.wait(value);
value = m_signal.load();
}
return;
}
auto& threadData = g_threadLocalData[g_threadIndex];
#ifdef ZN_HAS_TSAN
__tsan_switch_to_fiber(threadData.tsanWorkerFiber, nullptr);
#endif
threadData.yieldedToSignal = this;
boost_context::jump_fcontext(&threadData.currentJob.callee, threadData.currentJob.worker,
nullptr);
}
void BaseSignal::add_job(NewJob&& job) {
m_newJobs.enqueue(std::move(job));
if (signaled()) {
release_jobs();
}
}
void BaseSignal::add_job(ExistingJob&& job) {
m_existingJobs.enqueue(std::move(job));
if (signaled()) {
release_jobs();
}
}
bool BaseSignal::signaled() const {
return m_signal.load(std::memory_order_acquire) <= 0;
}
void BaseSignal::release_jobs() {
ExistingJob existingJob;
while (m_existingJobs.try_dequeue(existingJob)) {
auto& threadData = g_threadLocalData[existingJob.threadIndex];
threadData.localJobs.enqueue(std::move(existingJob));
}
NewJob newJob{};
while (m_newJobs.try_dequeue(newJob)) {
g_newJobs.enqueue(std::move(newJob));
}
}
// Mutex
IntrusivePtr<Scheduler::Mutex> Scheduler::Mutex::create() {
return IntrusivePtr(new Mutex());
}
Scheduler::Mutex::Mutex()
: BaseSignal(0) {}
bool Scheduler::Mutex::try_lock() {
int32_t expected = 0;
return m_signal.compare_exchange_weak(expected, 1);
}
void Scheduler::Mutex::lock() {
while (!try_lock()) {
await();
}
}
void Scheduler::Mutex::unlock() {
decrement();
}
// Static Functions
static void fiber_proc(void* userData) {
auto& newJob = *reinterpret_cast<NewJob*>(userData);
newJob.proc(newJob.userData);
auto& threadData = g_threadLocalData[g_threadIndex];
#ifdef ZN_HAS_TSAN
__tsan_switch_to_fiber(threadData.tsanWorkerFiber, nullptr);
#endif
boost_context::jump_fcontext(&threadData.currentJob.callee, threadData.currentJob.worker,
nullptr);
}
static void worker_proc(void* userData) {
auto threadIndex = static_cast<uint32_t>(reinterpret_cast<uintptr_t>(userData));
g_threadIndex = threadIndex;
#ifdef ZN_HAS_TSAN
g_threadLocalData[threadIndex].tsanWorkerFiber = __tsan_create_fiber(0);
#endif
for (;;) {
NewJob newJob{};
bool foundJob = false;
auto& threadData = g_threadLocalData[threadIndex];
threadData.yieldedToSignal = nullptr;
if (threadData.localJobs.try_dequeue(threadData.currentJob)) {
foundJob = true;
}
else if (g_newJobs.try_dequeue(newJob)) {
foundJob = true;
#ifdef ZN_FIBER_STACK_GUARD_PAGES
auto stackPadding = SystemInfo::get_page_size();
auto stackSize = round_up(STACK_SIZE, stackPadding);
#else
auto stackSize = STACK_SIZE;
auto stackPadding = 0;
#endif
if (!threadData.freeStackMemory.try_dequeue(threadData.currentJob.stackMemory)) {
threadData.currentJob.stackMemory = alloc_stack(stackSize);
}
threadData.currentJob.decrementOnFinish = std::move(newJob.decrementOnFinish);
threadData.currentJob.threadIndex = threadIndex;
threadData.currentJob.callee = boost_context::make_fcontext(
threadData.currentJob.stackMemory + STACK_SIZE + stackPadding, STACK_SIZE,
fiber_proc);
#ifdef ZN_HAS_VALGRIND
threadData.currentJob.valgrindStackID = VALGRIND_STACK_REGISTER(threadData.currentJob.stackMemory,
threadData.currentJob.stackMemory + stackSize);
#endif
}
else {
OS::Thread::sleep(1);
}
if (foundJob) {
#ifdef ZN_HAS_ASAN
void* fakeStackSave = nullptr;
__sanitizer_start_switch_fiber(&fakeStackSave, threadData.currentJob.stackMemory,
STACK_SIZE);
#endif
#ifdef ZN_HAS_TSAN
threadData.tsanCalleeFiber = __tsan_create_fiber(0);
__tsan_switch_to_fiber(threadData.tsanCalleeFiber, nullptr);
#endif
boost_context::jump_fcontext(&threadData.currentJob.worker,
threadData.currentJob.callee, &newJob);
#ifdef ZN_HAS_TSAN
__tsan_destroy_fiber(threadData.tsanCalleeFiber);
#endif
#ifdef ZN_HAS_ASAN
void* bottomOld = nullptr;
size_t sizeOld = 0;
__sanitizer_finish_switch_fiber(fakeStackSave, &bottomOld, &sizeOld);
#endif
if (threadData.yieldedToSignal) {
threadData.yieldedToSignal->add_job(std::move(threadData.currentJob));
}
else {
#ifdef ZN_HAS_VALGRIND
VALGRIND_STACK_DEREGISTER(threadData.currentJob.valgrindStackID);
#endif
threadData.freeStackMemory.enqueue(threadData.currentJob.stackMemory);
if (threadData.currentJob.decrementOnFinish) {
threadData.currentJob.decrementOnFinish->decrement();
}
}
}
else if (g_finished.test(std::memory_order_relaxed)) {
break;
}
}
#ifdef ZN_HAS_TSAN
__tsan_destroy_fiber(g_threadLocalData[threadIndex].tsanWorkerFiber);
#endif
auto& threadData = g_threadLocalData[threadIndex];
uint8_t* stackMemory;
while (threadData.freeStackMemory.try_dequeue(stackMemory)) {
free_stack(stackMemory);
}
}
static void blocking_worker_proc(void*) {
for (;;) {
NewJob job{};
g_blockingNewJobs.wait_dequeue(job);
if (job.proc) {
job.proc(job.userData);
if (job.decrementOnFinish) {
job.decrementOnFinish->decrement();
}
}
if (g_finished.test(std::memory_order_relaxed)) {
break;
}
}
}
#ifdef ZN_FIBER_STACK_GUARD_PAGES
#if defined(OPERATING_SYSTEM_WINDOWS)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
static void protect_memory(uint8_t* memory, size_t size) {
DWORD oldProtect;
VirtualProtect(memory, size, PAGE_NOACCESS, &oldProtect);
}
static void unprotect_memory(uint8_t* memory, size_t size) {
DWORD oldProtect;
VirtualProtect(memory, size, PAGE_READWRITE, &oldProtect);
}
static uint8_t* alloc_aligned(size_t size, size_t align) {
return static_cast<uint8_t*>(_aligned_malloc(size, align));
}
static void free_aligned(void* mem) {
_aligned_free(mem);
}
#else
#include <sys/mman.h>
static void protect_memory(uint8_t* memory, size_t size) {
mprotect(memory, size, PROT_NONE);
}
static void unprotect_memory(uint8_t* memory, size_t size) {
mprotect(memory, size, PROT_READ | PROT_WRITE);
}
static uint8_t* alloc_aligned(size_t size, size_t align) {
void* result;
int res = posix_memalign(&result, align, size);
(void)res;
return static_cast<uint8_t*>(result);
}
static void free_aligned(void* mem) {
free(mem);
}
#endif
#endif // ZN_FIBER_STACK_GUARD_PAGES
static uint8_t* alloc_stack(size_t size) {
#ifdef ZN_FIBER_STACK_GUARD_PAGES
auto pageSize = SystemInfo::get_page_size();
auto* mem = alloc_aligned(size + 2 * pageSize, pageSize);
protect_memory(mem, pageSize);
protect_memory(mem + STACK_SIZE + pageSize, pageSize);
return mem;
#else
return static_cast<uint8_t*>(std::malloc(size));
#endif
}
static void free_stack(uint8_t* mem) {
#ifdef ZN_FIBER_STACK_GUARD_PAGES
auto pageSize = SystemInfo::get_page_size();
unprotect_memory(mem, pageSize);
unprotect_memory(mem + STACK_SIZE + pageSize, pageSize);
free_aligned(mem);
#else
std::free(mem);
#endif
}
|
whupdup/frame
|
real/scheduler/task_scheduler.cpp
|
C++
|
gpl-3.0
| 10,863
|
#pragma once
#include <core/intrusive_ptr.hpp>
#include <concurrentqueue.h>
#include <boost_context/fcontext.h>
#if __has_include(<valgrind/valgrind.h>)
#include <valgrind/valgrind.h>
#define ZN_HAS_VALGRIND
#endif
namespace ZN::Scheduler {
using JobProc = void(void*);
class Signal;
using SignalHandle = IntrusivePtr<Signal>;
struct NewJob {
JobProc* proc;
void* userData;
SignalHandle decrementOnFinish;
};
struct ExistingJob {
boost_context::fcontext_t worker;
boost_context::fcontext_t callee;
uint8_t* stackMemory;
SignalHandle decrementOnFinish;
uint32_t threadIndex;
#ifdef ZN_HAS_VALGRIND
unsigned valgrindStackID;
#endif
};
class BaseSignal {
public:
NULL_COPY_AND_ASSIGN(BaseSignal);
void increment(int32_t count);
void decrement();
void await();
void add_job(NewJob&&);
void add_job(ExistingJob&&);
uint32_t get_index() const;
bool signaled() const;
protected:
std::atomic_int32_t m_signal;
explicit BaseSignal(int32_t count);
private:
moodycamel::ConcurrentQueue<NewJob> m_newJobs;
moodycamel::ConcurrentQueue<ExistingJob> m_existingJobs;
bool m_waitedOnExternally;
void release_jobs();
};
class Signal final : public BaseSignal, public Memory::ThreadSafeIntrusivePtrEnabled<Signal> {
public:
static IntrusivePtr<Signal> create(int32_t count = 1);
private:
using BaseSignal::BaseSignal;
};
class Mutex final : public BaseSignal, public Memory::ThreadSafeIntrusivePtrEnabled<Mutex> {
public:
static IntrusivePtr<Mutex> create();
bool try_lock();
void lock();
void unlock();
private:
explicit Mutex();
};
constexpr std::nullptr_t NO_SIGNAL = nullptr;
void init();
void deinit();
void queue_job(void* userData, SignalHandle decrementOnFinish, const SignalHandle& precondition,
JobProc*);
void queue_blocking_job(void* userData, SignalHandle decrementOnFinish, JobProc*);
template <typename Functor>
void queue_job(SignalHandle decrementOnFinish, const SignalHandle& precondition,
Functor&& func) {
queue_job(new Functor(std::move(func)), std::move(decrementOnFinish), precondition,
[](void* userData) {
auto* fn = reinterpret_cast<Functor*>(userData);
(*fn)();
delete fn;
});
}
template <typename Functor>
void queue_blocking_job(SignalHandle decrementOnFinish, Functor&& func) {
queue_blocking_job(new Functor(std::move(func)), std::move(decrementOnFinish),
[](void* userData) {
auto* fn = reinterpret_cast<Functor*>(userData);
(*fn)();
delete fn;
});
}
}
|
whupdup/frame
|
real/scheduler/task_scheduler.hpp
|
C++
|
gpl-3.0
| 2,477
|
target_sources(LibCommon PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/application.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/context_action.cpp"
#"${CMAKE_CURRENT_SOURCE_DIR}/run_manager.cpp"
)
|
whupdup/frame
|
real/services/CMakeLists.txt
|
Text
|
gpl-3.0
| 180
|
#include "application.hpp"
#include <core/logging.hpp>
#include <core/threading.hpp>
#include <scheduler/task_scheduler.hpp>
#include <services/context_action.hpp>
#include <cassert>
#include <cstring>
#include <atomic>
using namespace ZN;
static std::atomic_size_t g_instanceCount{0};
static constexpr size_t KEY_COUNT = GLFW_KEY_LAST + 1;
static constexpr size_t MOUSE_BUTTON_COUNT = GLFW_MOUSE_BUTTON_LAST + 1;
static bool g_keyStates[KEY_COUNT] = {};
static bool g_mouseButtonStates[MOUSE_BUTTON_COUNT] = {};
static double g_lastCursorX = 0;
static double g_lastCursorY = 0;
static double g_cursorX = 0;
static double g_cursorY = 0;
static double g_deltaX = 0;
static double g_deltaY = 0;
static IntrusivePtr<Scheduler::Mutex> g_inputMutex = Scheduler::Mutex::create();
static Application::KeyPressEvent g_keyDownEvent;
static Application::KeyPressEvent g_keyUpEvent;
static Application::MouseClickEvent g_mouseDownEvent;
static Application::MouseClickEvent g_mouseUpEvent;
static Application::WindowCloseEvent g_windowCloseEvent;
static void keyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
static void cursorPosCallback(GLFWwindow* window, double xPos, double yPos);
static void mouseButtonCallback(GLFWwindow* window, int button, int action, int mods);
// FIXME: implement static void scrollCallback(GLFWwindow* window, double xOffset, double yOffset);
static void framebufferSizeCallback(GLFWwindow* window, int width, int height);
static void windowCloseCallback(GLFWwindow* window);
Application::Application() noexcept {
if (g_instanceCount.fetch_add(1, std::memory_order_relaxed) == 0) {
if (!glfwInit()) {
LOG_ERROR2("GLFW", "Failed to initialize GLFW");
}
}
}
Application::~Application() noexcept {
if (g_instanceCount.fetch_sub(1, std::memory_order_acq_rel) == 1) {
glfwTerminate();
}
}
void Application::await_and_process_events() noexcept {
glfwWaitEvents();
}
void Application::poll_events() noexcept {
begin_input_frame();
glfwPollEvents();
}
void Application::begin_input_frame() {
ScopedLock lock(*g_inputMutex);
g_deltaX = g_cursorX - g_lastCursorX;
g_deltaY = g_cursorY - g_lastCursorY;
g_lastCursorX = g_cursorX;
g_lastCursorY = g_cursorY;
}
bool Application::is_key_down(int key) const {
return g_keyStates[key];
}
bool Application::is_mouse_button_down(int mouseButton) const {
return g_mouseButtonStates[mouseButton];
}
double Application::get_time() const {
return glfwGetTime();
}
double Application::get_mouse_x() const {
return g_cursorX;
}
double Application::get_mouse_y() const {
return g_cursorY;
}
Math::Vector2 Application::get_mouse_position() const {
return Math::Vector2(static_cast<float>(g_cursorX), static_cast<float>(g_cursorY));
}
double Application::get_mouse_delta_x() const {
ScopedLock lock(*g_inputMutex);
return g_deltaX;
}
double Application::get_mouse_delta_y() const {
ScopedLock lock(*g_inputMutex);
return g_deltaY;
}
Application::KeyPressEvent& Application::key_down_event() {
return g_keyDownEvent;
}
Application::KeyPressEvent& Application::key_up_event() {
return g_keyUpEvent;
}
Application::WindowCloseEvent& Application::window_close_event() {
return g_windowCloseEvent;
}
Window::Window(int width, int height, const char* title) noexcept
: m_handle(nullptr)
, m_width(width)
, m_height(height) {
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
//glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
m_handle = glfwCreateWindow(width, height, title, nullptr, nullptr);
if (!m_handle) {
LOG_ERROR2("GLFW", "Failed to create window");
}
glfwSetWindowUserPointer(m_handle, this);
glfwGetCursorPos(m_handle, &g_cursorX, &g_cursorY);
glfwSetKeyCallback(m_handle, keyCallback);
glfwSetMouseButtonCallback(m_handle, mouseButtonCallback);
glfwSetCursorPosCallback(m_handle, cursorPosCallback);
glfwSetFramebufferSizeCallback(m_handle, framebufferSizeCallback);
glfwSetWindowCloseCallback(m_handle, windowCloseCallback);
}
Window::~Window() noexcept {
glfwDestroyWindow(m_handle);
}
void Window::swap_buffers() noexcept {
assert(m_handle);
glfwSwapBuffers(m_handle);
}
bool Window::is_close_requested() const noexcept {
assert(m_handle);
return glfwWindowShouldClose(m_handle);
}
int Window::get_width() const noexcept {
assert(m_handle);
return m_width;
}
int Window::get_height() const noexcept {
assert(m_handle);
return m_height;
}
double Window::get_aspect_ratio() const noexcept {
assert(m_handle);
return static_cast<double>(m_width) / static_cast<double>(m_height);
}
GLFWwindow* Window::get_handle() noexcept {
return m_handle;
}
Window::ResizeEvent& Window::resize_event() {
return m_resizeEvent;
}
void Window::set_size(int width, int height) {
if (width != 0 && height != 0) {
m_width = width;
m_height = height;
}
m_resizeEvent.fire(width, height);
}
static void keyCallback(GLFWwindow* handle, int key, int scancode, int action, int mods) {
(void)handle;
(void)scancode;
(void)mods;
bool keyState = action != GLFW_RELEASE;
if (keyState != g_keyStates[key]) {
InputObject io{};
io.keyCode = key;
io.type = UserInputType::KEYBOARD;
if (keyState) {
io.state = UserInputState::BEGIN;
g_keyDownEvent.fire(key);
}
else {
io.state = UserInputState::END;
g_keyUpEvent.fire(key);
}
g_contextActionManager->fire_input(io);
}
g_keyStates[key] = keyState;
}
static void cursorPosCallback(GLFWwindow*, double xPos, double yPos) {
g_cursorX = xPos;
g_cursorY = yPos;
InputObject io{};
io.position = Math::Vector3(static_cast<float>(xPos), static_cast<float>(yPos), 0.f);
io.state = UserInputState::CHANGE;
io.type = UserInputType::MOUSE_MOVEMENT;
g_contextActionManager->fire_input(io);
}
static void mouseButtonCallback(GLFWwindow* handle, int button, int action, int mods) {
(void)handle;
(void)mods;
bool buttonState = action != GLFW_RELEASE;
if (buttonState != g_mouseButtonStates[button]) {
InputObject io{};
io.position = Math::Vector3(static_cast<float>(g_cursorX), static_cast<float>(g_cursorY),
0.f);
switch (button) {
case GLFW_MOUSE_BUTTON_1:
io.type = UserInputType::MOUSE_BUTTON_1;
break;
case GLFW_MOUSE_BUTTON_2:
io.type = UserInputType::MOUSE_BUTTON_2;
break;
case GLFW_MOUSE_BUTTON_3:
io.type = UserInputType::MOUSE_BUTTON_3;
break;
default:
io.type = UserInputType::NONE;
}
if (buttonState) {
io.state = UserInputState::BEGIN;
g_mouseDownEvent.fire(button);
}
else {
io.state = UserInputState::END;
g_mouseUpEvent.fire(button);
}
g_contextActionManager->fire_input(io);
}
g_mouseButtonStates[button] = buttonState;
}
static void framebufferSizeCallback(GLFWwindow* handle, int width, int height) {
Window* window = reinterpret_cast<Window*>(glfwGetWindowUserPointer(handle));
window->set_size(width, height);
}
//static void scrollCallback(GLFWwindow* window, double xOffset, double yOffset) {
//}
static void windowCloseCallback(GLFWwindow* handle) {
auto& window = *reinterpret_cast<Window*>(glfwGetWindowUserPointer(handle));
g_windowCloseEvent.fire(window);
}
|
whupdup/frame
|
real/services/application.cpp
|
C++
|
gpl-3.0
| 7,119
|
#pragma once
#include <volk.h>
#include <GLFW/glfw3.h>
#include <core/common.hpp>
#include <core/events.hpp>
#include <core/local.hpp>
#include <math/vector2.hpp>
namespace ZN {
class Window;
class Application final {
public:
using KeyPressEvent = Event::Dispatcher<int>;
using MouseClickEvent = Event::Dispatcher<int>;
using WindowCloseEvent = Event::Dispatcher<Window&>;
explicit Application() noexcept;
~Application() noexcept;
NULL_COPY_AND_ASSIGN(Application);
void await_and_process_events() noexcept;
void poll_events() noexcept;
void begin_input_frame();
bool is_key_down(int key) const;
bool is_mouse_button_down(int mouseButton) const;
double get_time() const;
double get_mouse_x() const;
double get_mouse_y() const;
Math::Vector2 get_mouse_position() const;
double get_mouse_delta_x() const;
double get_mouse_delta_y() const;
KeyPressEvent& key_down_event();
KeyPressEvent& key_up_event();
MouseClickEvent& mouse_down_event();
MouseClickEvent& mouse_up_event();
WindowCloseEvent& window_close_event();
private:
};
class Window final {
public:
using ResizeEvent = Event::Dispatcher<int, int>;
explicit Window(int width, int height, const char* title) noexcept;
~Window() noexcept;
NULL_COPY_AND_ASSIGN(Window);
void swap_buffers() noexcept;
bool is_close_requested() const noexcept;
int get_width() const noexcept;
int get_height() const noexcept;
double get_aspect_ratio() const noexcept;
GLFWwindow* get_handle() noexcept;
void set_size(int width, int height);
ResizeEvent& resize_event();
private:
GLFWwindow* m_handle;
int m_width;
int m_height;
ResizeEvent m_resizeEvent;
};
inline Local<Application> g_application;
inline Local<Window> g_window;
}
|
whupdup/frame
|
real/services/application.hpp
|
C++
|
gpl-3.0
| 1,776
|
#include "context_action.hpp"
using namespace ZN;
// ContextKey
bool ContextActionManager::ContextKey::operator==(const ContextKey& other) const {
return type == other.type && keyCode == other.keyCode;
}
size_t ContextActionManager::ContextKey::hash() const {
return static_cast<size_t>(type) | (static_cast<size_t>(keyCode) << 8);
}
// Action
bool ContextActionManager::Action::operator<(const Action& other) const {
return priority < other.priority;
}
// ContextActionManager
void ContextActionManager::bind_action(std::string_view name, UserInputType type, int keyCode,
CallbackObject&& cb) {
bind_action_at_priority(std::move(name), type, keyCode, ContextActionPriority::DEFAULT,
std::move(cb));
}
void ContextActionManager::bind_action_at_priority(std::string_view name, UserInputType type,
int keyCode, ContextActionPriority priority, CallbackObject&& cb) {
if (type != UserInputType::KEYBOARD) {
keyCode = 0;
}
ContextKey key{type, keyCode};
Action newAction{cb, priority, std::string(std::move(name))};
auto& actions = m_bindings[key];
for (ptrdiff_t i = static_cast<ptrdiff_t>(actions.size() - 1); i >= 0; --i) {
if (actions[i] < newAction) {
actions.insert(actions.begin() + i, std::move(newAction));
return;
}
}
actions.push_back(std::move(newAction));
}
void ContextActionManager::unbind_action(std::string_view name) {
for (auto& [_, actions] : m_bindings) {
for (auto it = actions.begin(), end = actions.end(); it != end; ++it) {
if (it->name.compare(name) == 0) {
actions.erase(it);
return;
}
}
}
}
void ContextActionManager::unbind_all_actions() {
m_bindings.clear();
}
void ContextActionManager::fire_input(const InputObject& inputObject) {
ContextKey key{inputObject.type, inputObject.keyCode};
auto& actions = m_bindings[key];
for (auto it = actions.rbegin(), end = actions.rend(); it != end; ++it) {
if (it->callback(inputObject) == ContextActionResult::SINK) {
return;
}
}
}
|
whupdup/frame
|
real/services/context_action.cpp
|
C++
|
gpl-3.0
| 1,977
|
#pragma once
#include <core/local.hpp>
#include <services/user_input.hpp>
#include <functional>
#include <string>
#include <string_view>
#include <unordered_map>
#include <vector>
namespace ZN {
enum class ContextActionResult {
SINK = 0,
PASS = 1
};
enum class ContextActionPriority {
LOW = 1000,
MEDIUM = 2000,
HIGHT = 3000,
DEFAULT = MEDIUM
};
using ContextActionCallback = ContextActionResult(const InputObject&);
class ContextActionManager {
public:
using CallbackObject = std::function<ContextActionCallback>;
void bind_action(std::string_view name, UserInputType, int keyCode, CallbackObject&&);
void bind_action_at_priority(std::string_view name, UserInputType, int keyCode,
ContextActionPriority, CallbackObject&&);
void unbind_action(std::string_view name);
void unbind_all_actions();
void fire_input(const InputObject&);
private:
struct ContextKey {
UserInputType type;
int keyCode;
bool operator==(const ContextKey&) const;
size_t hash() const;
};
struct ContextKeyHash {
size_t operator()(const ContextKey& k) const {
return k.hash();
}
};
struct Action {
CallbackObject callback;
ContextActionPriority priority;
std::string name;
bool operator<(const Action&) const;
};
std::unordered_map<ContextKey, std::vector<Action>, ContextKeyHash> m_bindings;
};
inline Local<ZN::ContextActionManager> g_contextActionManager;
}
|
whupdup/frame
|
real/services/context_action.hpp
|
C++
|
gpl-3.0
| 1,423
|
#pragma once
#include <cstdint>
#include <math/vector3.hpp>
namespace ZN {
enum class UserInputType : uint8_t {
MOUSE_BUTTON_1 = 0,
MOUSE_BUTTON_2 = 1,
MOUSE_BUTTON_3 = 2,
MOUSE_WHEEL = 3,
MOUSE_MOVEMENT = 4,
TOUCH = 7, // Unused, mobile
KEYBOARD = 8,
FOCUS = 9, // Focus regained to window
ACCELEROMETER = 10, // Unused, mobile
GYRO = 11, // Unused, mobile
GAMEPAD_1 = 12,
GAMEPAD_2 = 13,
GAMEPAD_3 = 14,
GAMEPAD_4 = 15,
GAMEPAD_5 = 16,
GAMEPAD_6 = 17,
GAMEPAD_7 = 18,
GAMEPAD_8 = 19,
TEXT_INPUT = 20, // Input of text into a text-based GuiObject. Normally this is only a TextBox
INPUT_METHOD = 21, // Text input from an input method editor (IME), unsupported
NONE = 22
};
enum class UserInputState : uint8_t {
BEGIN = 0,
CHANGE = 1, // Occurs each frame an inputobject has already begun interacting with the game
// and part of its state is changing, for example a mouse movement/gamepad analog
END = 2,
CANCEL = 3, // Indicates this input is no longer relevant, e.g. binding two action-handling
// functions will cause the first to cancel if an inpu was already in progress
// when the second was bound
NONE = 4 // Should never be encountered, marks end of enum
};
enum class ModifierKey : uint8_t {
SHIFT = 0,
CTRL = 1,
ALT = 2,
META = 3
};
struct InputObject {
Math::Vector3 delta;
Math::Vector3 position;
int keyCode; // FIXME: enum KeyCode
UserInputState state;
UserInputType type;
// FIXME: bool is_modifier_key_down(ModifierKey) const;
};
}
|
whupdup/frame
|
real/services/user_input.hpp
|
C++
|
gpl-3.0
| 1,508
|
find_package(Vulkan REQUIRED)
#find_package(rapidjson REQUIRED)
add_library(boost_context STATIC)
add_library(spirv_reflect STATIC)
add_library(stb STATIC)
#add_library(TinyGLTF STATIC)
add_subdirectory(freetype-2.12.0)
add_subdirectory(tracy)
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC")
set(CMAKE_AR lib.exe)
set(CMAKE_ASM_MASM_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreaded "")
set(CMAKE_ASM_MASM_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDLL "")
set(CMAKE_ASM_MASM_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDebug "")
set(CMAKE_ASM_MASM_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDebugDLL "")
set(CMAKE_ASM_MASM_CREATE_STATIC_LIBRARY "<CMAKE_AR> /OUT:<TARGET> <LINK_FLAGS> <OBJECTS>")
target_sources(boost_context PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/boost_context/asm/make_x86_64_ms_pe_masm.asm"
"${CMAKE_CURRENT_SOURCE_DIR}/boost_context/asm/jump_x86_64_ms_pe_masm.asm"
)
set_source_files_properties(
"${CMAKE_CURRENT_SOURCE_DIR}/boost_context/asm/make_x86_64_ms_pe_masm.asm"
"${CMAKE_CURRENT_SOURCE_DIR}/boost_context/asm/jump_x86_64_ms_pe_masm.asm"
PROPERTIES
COMPILE_FLAGS "/safeseh"
)
else()
target_sources(boost_context PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/boost_context/asm/make_x86_64_ms_pe_gas.S"
"${CMAKE_CURRENT_SOURCE_DIR}/boost_context/asm/jump_x86_64_ms_pe_gas.S"
)
endif()
elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_sources(boost_context PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/boost_context/asm/make_x86_64_sysv_elf_gas.S"
"${CMAKE_CURRENT_SOURCE_DIR}/boost_context/asm/jump_x86_64_sysv_elf_gas.S"
)
else()
message(FATAL_ERROR "OS ${CMAKE_SYSTEM_NAME} unsupported")
endif()
target_include_directories(boost_context INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/boost_context/include")
add_compile_definitions(
TINYGLTF_USE_RAPIDJSON
TINYGLTF_NO_STB_IMAGE_WRITE
)
target_compile_definitions(TracyClient PRIVATE
_WIN32_WINNT=0x0602
WINVER=0x0602
)
target_include_directories(spirv_reflect PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}/spirv_reflect"
)
target_include_directories(spirv_reflect PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}/spirv_reflect/include"
)
target_sources(spirv_reflect PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/spirv_reflect/spirv_reflect.h"
"${CMAKE_CURRENT_SOURCE_DIR}/spirv_reflect/spirv_reflect.c"
)
target_include_directories(stb PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}/stb"
)
target_sources(stb PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/stb/stb_image.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/stb/stb_image_resize.cpp"
)
#target_include_directories(TinyGLTF PUBLIC
# "${CMAKE_CURRENT_SOURCE_DIR}/tinygltf"
#)
#target_sources(TinyGLTF PRIVATE
# "${CMAKE_CURRENT_SOURCE_DIR}/tinygltf/tiny_gltf.cpp"
#)
#target_link_libraries(TinyGLTF PRIVATE stb)
#target_link_libraries(TinyGLTF PRIVATE rapidjson)
|
whupdup/frame
|
real/third_party/CMakeLists.txt
|
Text
|
gpl-3.0
| 2,873
|
## Copyright Adrian Astley 2016 - 2018
## 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)
cmake_minimum_required(VERSION 3.2)
project(boost_context ASM)
include(SetSourceGroup)
option(FTL_FIBER_CANARY_BYTES "Enable canary bytes in fiber switching logic, to help debug errors" OFF)
# Determine the target architecture
#
# Taken from Richard Maxwell's 'sewing' library: https://github.com/JodiTheTigger/sewing
# (MIT license)
#
# Enable the assemblers
if (WIN32 AND MSVC)
enable_language(ASM_MASM)
else()
enable_language(ASM)
endif()
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
set(CONTEXT_PLATFORM "x86_64")
endif()
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64")
set(CONTEXT_PLATFORM "x86_64")
endif()
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "i386")
set(CONTEXT_PLATFORM "i386")
endif()
if (CONTEXT_PLATFORM STREQUAL "x86_64")
if("${CMAKE_SIZEOF_VOID_P}" EQUAL "4")
set(CONTEXT_PLATFORM "i386")
endif()
endif()
if (CMAKE_SYSTEM_PROCESSOR MATCHES "arm")
if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
set(CONTEXT_PLATFORM "arm64")
else()
set(CONTEXT_PLATFORM "arm")
endif()
set(CONTEXT_OS "aapcs")
endif()
if (CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
set(CONTEXT_PLATFORM "arm64")
set(CONTEXT_OS "aapcs")
endif()
if (WIN32)
# arm requires aapcs. So we have to check if arm already set the calling convention
if (NOT CONTEXT_OS)
set(CONTEXT_OS "ms")
endif()
set(CONTEXT_ABI "pe")
if (MSVC)
set(CONTEXT_ASM "masm.asm")
else()
set(CONTEXT_ASM "gas.S")
endif()
elseif(APPLE)
set(CONTEXT_OS "sysv")
set(CONTEXT_ABI "macho")
set(CONTEXT_ASM "gas.S")
elseif(UNIX)
# arm requires aapcs. So we have to check if arm already set the calling convention
if (NOT CONTEXT_OS)
set(CONTEXT_OS "sysv")
endif()
set(CONTEXT_ABI "elf")
set(CONTEXT_ASM "gas.S")
endif()
if(FTL_FIBER_CANARY_BYTES)
set(CONTEXT_CANARY "canary_")
else()
set(CONTEXT_CANARY "")
endif()
message(STATUS "-- System processor: ${CMAKE_SYSTEM_PROCESSOR}")
message(STATUS "-- Target processor: ${CONTEXT_PLATFORM}")
message(STATUS "-- Target asm : ${CONTEXT_CANARY}${CONTEXT_PLATFORM}_${CONTEXT_OS}_${CONTEXT_ABI}_${CONTEXT_ASM}")
SetSourceGroup(NAME Root
PREFIX BOOST_CONTEXT
SOURCE_FILES asm/make_${CONTEXT_CANARY}${CONTEXT_PLATFORM}_${CONTEXT_OS}_${CONTEXT_ABI}_${CONTEXT_ASM}
asm/jump_${CONTEXT_CANARY}${CONTEXT_PLATFORM}_${CONTEXT_OS}_${CONTEXT_ABI}_${CONTEXT_ASM}
include/boost_context/fcontext.h)
if (CONTEXT_ASM MATCHES "masm.asm" AND CONTEXT_PLATFORM MATCHES "i386")
set_source_files_properties(asm/make_${CONTEXT_PLATFORM}_${CONTEXT_OS}_${CONTEXT_ABI}_${CONTEXT_ASM}
asm/jump_${CONTEXT_PLATFORM}_${CONTEXT_OS}_${CONTEXT_ABI}_${CONTEXT_ASM}
PROPERTIES
COMPILE_FLAGS "/safeseh")
endif()
add_library(boost_context STATIC ${BOOST_CONTEXT_ROOT})
target_include_directories(boost_context INTERFACE include)
|
whupdup/frame
|
real/third_party/boost_context/CMakeLists.txt
|
Text
|
gpl-3.0
| 3,069
|
Boost Software License - Version 1.0 - August 17th, 2003
Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:
The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.
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, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
|
whupdup/frame
|
real/third_party/boost_context/LICENSE_1_0.txt
|
Text
|
gpl-3.0
| 1,338
|
/*
Copyright Edward Nevill + Oliver Kowalke 2015
Copyright Adrian Astley 2017 - 2018.
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)
*/
/*******************************************************
* *
* ------------------------------------------------- *
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | *
* ------------------------------------------------- *
* | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| *
* ------------------------------------------------- *
* | d8 | d9 | d10 | d11 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
* ------------------------------------------------- *
* | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| *
* ------------------------------------------------- *
* | d12 | d13 | d14 | d15 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | *
* ------------------------------------------------- *
* | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| *
* ------------------------------------------------- *
* | x19 | x20 | x21 | x22 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | *
* ------------------------------------------------- *
* | 0x60| 0x64| 0x68| 0x6c| 0x70| 0x74| 0x78| 0x7c| *
* ------------------------------------------------- *
* | x23 | x24 | x25 | x26 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | *
* ------------------------------------------------- *
* | 0x80| 0x84| 0x88| 0x8c| 0x90| 0x94| 0x98| 0x9c| *
* ------------------------------------------------- *
* | x27 | x28 | FP | LR | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 40 | 41 | 42 | 43 | 444| 45 | 46 | 47 | *
* ------------------------------------------------- *
* | 0xa0| 0xa4| 0xa8| 0xac| 0xb0| 0xb4| 0xb8| 0xbc| *
* ------------------------------------------------- *
* | PC | align | | | *
* ------------------------------------------------- *
* *
*******************************************************/
.text
.align 2
.global jump_fcontext
.type jump_fcontext, %function
jump_fcontext:
# prepare stack for GP + FPU
sub sp, sp, #0xb0
# save d8 - d15
stp d8, d9, [sp, #0x00]
stp d10, d11, [sp, #0x10]
stp d12, d13, [sp, #0x20]
stp d14, d15, [sp, #0x30]
# save x19-x30
stp x19, x20, [sp, #0x40]
stp x21, x22, [sp, #0x50]
stp x23, x24, [sp, #0x60]
stp x25, x26, [sp, #0x70]
stp x27, x28, [sp, #0x80]
stp x29, x30, [sp, #0x90]
# save LR as PC
str x30, [sp, #0xa0]
# store RSP (pointing to context-data) at address pointed at by X0
# STR doesn't allow us to use sp as the base register, so we have to mov it to x4 first
mov x4, sp
str x4, [x0, 0]
# restore RSP (pointing to context-data) from X1
mov sp, x1
# load d8 - d15
ldp d8, d9, [sp, #0x00]
ldp d10, d11, [sp, #0x10]
ldp d12, d13, [sp, #0x20]
ldp d14, d15, [sp, #0x30]
# load x19-x30
ldp x19, x20, [sp, #0x40]
ldp x21, x22, [sp, #0x50]
ldp x23, x24, [sp, #0x60]
ldp x25, x26, [sp, #0x70]
ldp x27, x28, [sp, #0x80]
ldp x29, x30, [sp, #0x90]
# pass data (third arg passed to jump_fcontext) as first arg passed to context function
mov x0, x2
# load pc
ldr x4, [sp, #0xa0]
# restore stack from GP + FP
add sp, sp, #0xb0
ret x4
.size jump_fcontext,.-jump_fcontext
# Mark that we don't need executable stack.
.section .note.GNU-stack,"",%progbits
|
whupdup/frame
|
real/third_party/boost_context/asm/jump_arm64_aapcs_elf_gas.S
|
Assembly
|
gpl-3.0
| 4,390
|
/*
Copyright Oliver Kowalke 2009.
Copyright Adrian Astley 2017 - 2018.
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)
*/
/*******************************************************
* *
* ------------------------------------------------- *
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | *
* ------------------------------------------------- *
* | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| *
* ------------------------------------------------- *
* | s16 | s17 | s18 | s19 | s20 | s21 | s22 | s23 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
* ------------------------------------------------- *
* | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| *
* ------------------------------------------------- *
* | s24 | s25 | s26 | s27 | s28 | s29 | s30 | s31 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | *
* ------------------------------------------------- *
* | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| *
* ------------------------------------------------- *
* | v1 | v2 | v3 | v4 | v5 | v6 | v7 | v8 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | *
* ------------------------------------------------- *
* | 0x60| 0x64| 0x68| 0x6c| 0x70| 0x74| 0x78| 0x7c| *
* ------------------------------------------------- *
* | lr | pc | | *
* ------------------------------------------------- *
* *
*******************************************************/
.text
.globl jump_fcontext
.align 2
.type jump_fcontext,%function
jump_fcontext:
@ save LR as PC
push {lr}
@ save V1-V8,LR
push {v1-v8,lr}
@ prepare stack for storing FPU
sub sp, sp, #64
#if (defined(__VFP_FP__) && !defined(__SOFTFP__))
@ save S16-S31
vstmia sp, {d8-d15}
#endif
@ store RSP (pointing to context-data) at address pointed at by A1
str sp, [a1]
@ restore RSP (pointing to context-data) from A2
mov sp, a2
#if (defined(__VFP_FP__) && !defined(__SOFTFP__))
@ restore S16-S31
vldmia sp, {d8-d15}
#endif
@ prepare stack for restoring other register
add sp, sp, #64
@ restore V1-V8,LR
pop {v1-v8,lr}
@ pass data (third arg passed to jump_fcontext) as first arg passed to context function
mov a1, a3
@ restore PC
pop {pc}
.size jump_fcontext,.-jump_fcontext
@ Mark that we don't need executable stack.
.section .note.GNU-stack,"",%progbits
|
whupdup/frame
|
real/third_party/boost_context/asm/jump_arm_aapcs_elf_gas.S
|
Assembly
|
gpl-3.0
| 3,040
|
; Copyright Oliver Kowalke 2009.
; Copyright Adrian Astley 2017 - 2018.
; 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)
; ---------------------------------------------------------------------------------
; | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
; ---------------------------------------------------------------------------------
; | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c |
; ---------------------------------------------------------------------------------
; | SEE registers (XMM6-XMM15) |
; ---------------------------------------------------------------------------------
; ---------------------------------------------------------------------------------
; | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
; ---------------------------------------------------------------------------------
; | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c |
; ---------------------------------------------------------------------------------
; | SEE registers (XMM6-XMM15) |
; ---------------------------------------------------------------------------------
; ---------------------------------------------------------------------------------
; | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
; ---------------------------------------------------------------------------------
; | 0xe40 | 0x44 | 0x48 | 0x4c | 0x50 | 0x54 | 0x58 | 0x5c |
; ---------------------------------------------------------------------------------
; | SEE registers (XMM6-XMM15)
; ---------------------------------------------------------------------------------
; ---------------------------------------------------------------------------------
; | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 |
; ---------------------------------------------------------------------------------
; | 0x60 | 0x64 | 0x68 | 0x6c | 0x70 | 0x74 | 0x78 | 0x7c |
; ---------------------------------------------------------------------------------
; | SEE registers (XMM6-XMM15) |
; ---------------------------------------------------------------------------------
; ---------------------------------------------------------------------------------
; | 32 | 32 | 33 | 34 | 35 | 36 | 37 | 38 |
; ---------------------------------------------------------------------------------
; | 0x80 | 0x84 | 0x88 | 0x8c | 0x90 | 0x94 | 0x98 | 0x9c |
; ---------------------------------------------------------------------------------
; | SEE registers (XMM6-XMM15) |
; ---------------------------------------------------------------------------------
; ---------------------------------------------------------------------------------
; | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 |
; ---------------------------------------------------------------------------------
; | 0xa0 | 0xa4 | 0xa8 | 0xac | 0xb0 | 0xb4 | 0xb8 | 0xbc |
; ---------------------------------------------------------------------------------
; | fc_mxcsr|fc_x87_cw| <alignment> | fbr_strg | fc_dealloc |
; ---------------------------------------------------------------------------------
; ---------------------------------------------------------------------------------
; | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 |
; ---------------------------------------------------------------------------------
; | 0xc0 | 0xc4 | 0xc8 | 0xcc | 0xd0 | 0xd4 | 0xd8 | 0xdc |
; ---------------------------------------------------------------------------------
; | limit | base | R12 | R13 |
; ---------------------------------------------------------------------------------
; ---------------------------------------------------------------------------------
; | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 |
; ---------------------------------------------------------------------------------
; | 0xe0 | 0xe4 | 0xe8 | 0xec | 0xf0 | 0xf4 | 0xf8 | 0xfc |
; ---------------------------------------------------------------------------------
; | R14 | R15 | RDI | RSI |
; ---------------------------------------------------------------------------------
; ---------------------------------------------------------------------------------
; | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 |
; ---------------------------------------------------------------------------------
; | 0x100 | 0x104 | 0x108 | 0x10c | 0x110 | 0x114 | 0x118 | 0x11c |
; ---------------------------------------------------------------------------------
; | RBX | RBP | 0xC0FFEE | RIP |
; ---------------------------------------------------------------------------------
; ---------------------------------------------------------------------------------
; | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 |
; ---------------------------------------------------------------------------------
; | 0x120 | 0x124 | 0x128 | 0x12c | 0x130 | 0x134 | 0x138 | 0x13c |
; ---------------------------------------------------------------------------------
; | "Shadow Space" |
; ---------------------------------------------------------------------------------
; ---------------------------------------------------------------------------------
; | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 |
; ---------------------------------------------------------------------------------
; | 0x140 | 0x144 | 0x148 | 0x14c | 0x150 | 0x154 | 0x158 | 0x15c |
; ---------------------------------------------------------------------------------
; | Caller's stack frame... |
; ---------------------------------------------------------------------------------
.code
jump_fcontext PROC FRAME
.endprolog
; prepare stack
lea rsp, [rsp-0118h]
; save XMM storage
movaps [rsp], xmm6
movaps [rsp+010h], xmm7
movaps [rsp+020h], xmm8
movaps [rsp+030h], xmm9
movaps [rsp+040h], xmm10
movaps [rsp+050h], xmm11
movaps [rsp+060h], xmm12
movaps [rsp+070h], xmm13
movaps [rsp+080h], xmm14
movaps [rsp+090h], xmm15
; save MMX control- and status-word
stmxcsr [rsp+0a0h]
; save x87 control-word
fnstcw [rsp+0a4h]
; load NT_TIB
mov r10, gs:[030h]
; save fiber local storage
mov rax, [r10+018h]
mov [rsp+0b0h], rax
; save current deallocation stack
mov rax, [r10+01478h]
mov [rsp+0b8h], rax
; save current stack limit
mov rax, [r10+010h]
mov [rsp+0c0h], rax
; save current stack base
mov rax, [r10+08h]
mov [rsp+0c8h], rax
mov [rsp+0d0h], r12 ; save R12
mov [rsp+0d8h], r13 ; save R13
mov [rsp+0e0h], r14 ; save R14
mov [rsp+0e8h], r15 ; save R15
mov [rsp+0f0h], rdi ; save RDI
mov [rsp+0f8h], rsi ; save RSI
mov [rsp+0100h], rbx ; save RBX
mov [rsp+0108h], rbp ; save RBP
; set canary bytes of this context stack
mov rax, 0c0ffeeh
mov [rsp+0110h], rax
; check canary bytes of next context stack
mov rax, 0c0ffeeh
mov rbx, [rdx+0110h]
cmp rax, rbx
jne canary_check_failed
; preserve RSP (pointing to context-data) in RCX
mov [rcx], rsp
; restore RSP (pointing to context-data) from RDX
mov rsp, rdx
; restore XMM storage
movaps xmm6, [rsp]
movaps xmm7, [rsp+010h]
movaps xmm8, [rsp+020h]
movaps xmm9, [rsp+030h]
movaps xmm10, [rsp+040h]
movaps xmm11, [rsp+050h]
movaps xmm12, [rsp+060h]
movaps xmm13, [rsp+070h]
movaps xmm14, [rsp+080h]
movaps xmm15, [rsp+090h]
; restore MMX control- and status-word
ldmxcsr [rsp+0a0h]
; save x87 control-word
fldcw [rsp+0a4h]
; load NT_TIB
mov r10, gs:[030h]
; restore fiber local storage
mov rax, [rsp+0b0h]
mov [r10+018h], rax
; restore current deallocation stack
mov rax, [rsp+0b8h]
mov [r10+01478h], rax
; restore current stack limit
mov rax, [rsp+0c0h]
mov [r10+010h], rax
; restore current stack base
mov rax, [rsp+0c8h]
mov [r10+08h], rax
mov r12, [rsp+0d0h] ; restore R12
mov r13, [rsp+0d8h] ; restore R13
mov r14, [rsp+0e0h] ; restore R14
mov r15, [rsp+0e8h] ; restore R15
mov rdi, [rsp+0f0h] ; restore RDI
mov rsi, [rsp+0f8h] ; restore RSI
mov rbx, [rsp+0100h] ; restore RBX
mov rbp, [rsp+0108h] ; restore RBP
; prepare stack
lea rsp, [rsp+0118h]
; Set the third arg (data) as the first arg of the context function
mov rcx, r8
; load return-address
pop r10
; indirect jump to context
jmp r10
ret
canary_check_failed:
; restore the rsp so we can get a useful stack trace
lea rsp, [rsp+0118h]
; force a seg-fault
mov rax, 0ffffffffh
jmp rax
jump_fcontext ENDP
END
|
whupdup/frame
|
real/third_party/boost_context/asm/jump_canary_x86_64_ms_pe_masm.asm
|
Assembly
|
gpl-3.0
| 9,892
|
; Copyright Oliver Kowalke 2009.
; Copyright Adrian Astley 2017 - 2018.
; 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)
; ---------------------------------------------------------------------------------
; | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
; ---------------------------------------------------------------------------------
; | 0h | 04h | 08h | 0ch | 010h | 014h | 018h | 01ch |
; ---------------------------------------------------------------------------------
; | fc_mxcsr|fc_x87_cw| fc_strg |fc_deallo| limit | base | fc_seh | EDI |
; ---------------------------------------------------------------------------------
; ---------------------------------------------------------------------------------
; | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
; ---------------------------------------------------------------------------------
; | 020h | 024h | 028h | 02ch | 030h | 034h | 038h | 03ch |
; ---------------------------------------------------------------------------------
; | ESI | EBX | EBP | EIP | from | to | data | EH NXT |
; ---------------------------------------------------------------------------------
; ---------------------------------------------------------------------------------
; | 16 | | | | | | | |
; ---------------------------------------------------------------------------------
; | 040h | | | | | | | |
; ---------------------------------------------------------------------------------
; |SEH HNDLR| | | | | | | |
; ---------------------------------------------------------------------------------
.386
.XMM
.model flat, c
.code
jump_fcontext PROC
; prepare stack
lea esp, [esp-02ch]
; save MMX control- and status-word
stmxcsr [esp]
; save x87 control-word
fnstcw [esp+04h]
assume fs:nothing
; load NT_TIB into ECX
mov edx, fs:[018h]
assume fs:error
; load fiber local storage
mov eax, [edx+010h]
mov [esp+08h], eax
; load current deallocation stack
mov eax, [edx+0e0ch]
mov [esp+0ch], eax
; load current stack limit
mov eax, [edx+08h]
mov [esp+010h], eax
; load current stack base
mov eax, [edx+04h]
mov [esp+014h], eax
; load current SEH exception list
mov eax, [edx]
mov [esp+018h], eax
mov [esp+01ch], edi ; save EDI
mov [esp+020h], esi ; save ESI
mov [esp+024h], ebx ; save EBX
mov [esp+028h], ebp ; save EBP
; store ESP (pointing to context-data) in arg 1
mov eax, [esp+030h]
mov [eax], esp
; second arg of jump_fcontext() == fcontext to jump to
mov ecx, [esp+034h]
; store arg 3 (data) in EAX
mov eax, [esp+038h]
; restore ESP (pointing to context-data) from ECX
mov esp, ecx
; restore MMX control- and status-word
ldmxcsr [esp]
; restore x87 control-word
fldcw [esp+04h]
assume fs:nothing
; load NT_TIB into EDX
mov edx, fs:[018h]
assume fs:error
; restore fiber local storage
mov ecx, [esp+08h]
mov [edx+010h], ecx
; restore current deallocation stack
mov ecx, [esp+0ch]
mov [edx+0e0ch], ecx
; restore current stack limit
mov ecx, [esp+010h]
mov [edx+08h], ecx
; restore current stack base
mov ecx, [esp+014h]
mov [edx+04h], ecx
; restore current SEH exception list
mov ecx, [esp+018h]
mov [edx], ecx
mov ecx, [esp+02ch] ; restore EIP
mov edi, [esp+01ch] ; restore EDI
mov esi, [esp+020h] ; restore ESI
mov ebx, [esp+024h] ; restore EBX
mov ebp, [esp+028h] ; restore EBP
; prepare stack
lea esp, [esp+030h]
; jump to context
jmp ecx
jump_fcontext ENDP
END
|
whupdup/frame
|
real/third_party/boost_context/asm/jump_i386_ms_pe_masm.asm
|
Assembly
|
gpl-3.0
| 4,161
|
/*
Copyright Oliver Kowalke 2009.
Copyright Thomas Sailer 2013.
Copyright Adrian Astley 2017 - 2018.
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)
*/
/*************************************************************************************
* ---------------------------------------------------------------------------------- *
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | *
* ---------------------------------------------------------------------------------- *
* | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | *
* ---------------------------------------------------------------------------------- *
* | SEE registers (XMM6-XMM15) | *
* ---------------------------------------------------------------------------------- *
* ---------------------------------------------------------------------------------- *
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
* ---------------------------------------------------------------------------------- *
* | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | *
* ---------------------------------------------------------------------------------- *
* | SEE registers (XMM6-XMM15) | *
* ---------------------------------------------------------------------------------- *
* ---------------------------------------------------------------------------------- *
* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | *
* ---------------------------------------------------------------------------------- *
* | 0xe40 | 0x44 | 0x48 | 0x4c | 0x50 | 0x54 | 0x58 | 0x5c | *
* ---------------------------------------------------------------------------------- *
* | SEE registers (XMM6-XMM15) | *
* ---------------------------------------------------------------------------------- *
* ---------------------------------------------------------------------------------- *
* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | *
* ---------------------------------------------------------------------------------- *
* | 0x60 | 0x64 | 0x68 | 0x6c | 0x70 | 0x74 | 0x78 | 0x7c | *
* ---------------------------------------------------------------------------------- *
* | SEE registers (XMM6-XMM15) | *
* ---------------------------------------------------------------------------------- *
* ---------------------------------------------------------------------------------- *
* | 32 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | *
* ---------------------------------------------------------------------------------- *
* | 0x80 | 0x84 | 0x88 | 0x8c | 0x90 | 0x94 | 0x98 | 0x9c | *
* ---------------------------------------------------------------------------------- *
* | SEE registers (XMM6-XMM15) | *
* ---------------------------------------------------------------------------------- *
* ---------------------------------------------------------------------------------- *
* | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | *
* ---------------------------------------------------------------------------------- *
* | 0xa0 | 0xa4 | 0xa8 | 0xac | 0xb0 | 0xb4 | 0xb8 | 0xbc | *
* ---------------------------------------------------------------------------------- *
* | fc_mxcsr|fc_x87_cw| <alignment> | fbr_strg | fc_dealloc | *
* ---------------------------------------------------------------------------------- *
* ---------------------------------------------------------------------------------- *
* | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | *
* ---------------------------------------------------------------------------------- *
* | 0xc0 | 0xc4 | 0xc8 | 0xcc | 0xd0 | 0xd4 | 0xd8 | 0xdc | *
* ---------------------------------------------------------------------------------- *
* | limit | base | R12 | R13 | *
* ---------------------------------------------------------------------------------- *
* ---------------------------------------------------------------------------------- *
* | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | *
* ---------------------------------------------------------------------------------- *
* | 0xe0 | 0xe4 | 0xe8 | 0xec | 0xf0 | 0xf4 | 0xf8 | 0xfc | *
* ---------------------------------------------------------------------------------- *
* | R14 | R15 | RDI | RSI | *
* ---------------------------------------------------------------------------------- *
* ---------------------------------------------------------------------------------- *
* | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | *
* ---------------------------------------------------------------------------------- *
* | 0x100 | 0x104 | 0x108 | 0x10c | 0x110 | 0x114 | 0x118 | 0x11c | *
* ---------------------------------------------------------------------------------- *
* | RBX | RBP | hidden | RIP | *
* ---------------------------------------------------------------------------------- *
* ---------------------------------------------------------------------------------- *
* | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | *
* ---------------------------------------------------------------------------------- *
* | 0x120 | 0x124 | 0x128 | 0x12c | 0x130 | 0x134 | 0x138 | 0x13c | *
* ---------------------------------------------------------------------------------- *
* | parameter area | *
* ---------------------------------------------------------------------------------- *
* ---------------------------------------------------------------------------------- *
* | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | *
* ---------------------------------------------------------------------------------- *
* | 0x140 | 0x144 | 0x148 | 0x14c | 0x150 | 0x154 | 0x158 | 0x15c | *
* ---------------------------------------------------------------------------------- *
* | FCTX | DATA | | *
* ---------------------------------------------------------------------------------- *
**************************************************************************************/
//.file "jump_x86_64_ms_pe_gas.S"
.text
.p2align 4,,15
.globl jump_fcontext
.def jump_fcontext; .scl 2; .type 32; .endef
.seh_proc jump_fcontext
jump_fcontext:
.seh_endprologue
leaq -0x118(%rsp), %rsp /* prepare stack */
/* save XMM storage */
movaps %xmm6, 0x0(%rsp)
movaps %xmm7, 0x10(%rsp)
movaps %xmm8, 0x20(%rsp)
movaps %xmm9, 0x30(%rsp)
movaps %xmm10, 0x40(%rsp)
movaps %xmm11, 0x50(%rsp)
movaps %xmm12, 0x60(%rsp)
movaps %xmm13, 0x70(%rsp)
movaps %xmm14, 0x80(%rsp)
movaps %xmm15, 0x90(%rsp)
stmxcsr 0xa0(%rsp) /* save MMX control- and status-word */
fnstcw 0xa4(%rsp) /* save x87 control-word */
/* load NT_TIB */
movq %gs:(0x30), %r10
/* save fiber local storage */
movq 0x18(%r10), %rax
movq %rax, 0xb0(%rsp)
/* save current deallocation stack */
movq 0x1478(%r10), %rax
movq %rax, 0xb8(%rsp)
/* save current stack limit */
movq 0x10(%r10), %rax
movq %rax, 0xc0(%rsp)
/* save current stack base */
movq 0x08(%r10), %rax
movq %rax, 0xc8(%rsp)
movq %r12, 0xd0(%rsp) /* save R12 */
movq %r13, 0xd8(%rsp) /* save R13 */
movq %r14, 0xe0(%rsp) /* save R14 */
movq %r15, 0xe8(%rsp) /* save R15 */
movq %rdi, 0xf0(%rsp) /* save RDI */
movq %rsi, 0xf8(%rsp) /* save RSI */
movq %rbx, 0x100(%rsp) /* save RBX */
movq %rbp, 0x108(%rsp) /* save RBP */
/* store RSP (pointing to context-data) in address given by RCX (first arg passed to jump_fcontext) */
movq %rsp, (%rcx)
/* restore RSP (pointing to context-data) from RDX */
movq %rdx, %rsp
/* save XMM storage */
movaps 0x0(%rsp), %xmm6
movaps 0x10(%rsp), %xmm7
movaps 0x20(%rsp), %xmm8
movaps 0x30(%rsp), %xmm9
movaps 0x40(%rsp), %xmm10
movaps 0x50(%rsp), %xmm11
movaps 0x60(%rsp), %xmm12
movaps 0x70(%rsp), %xmm13
movaps 0x80(%rsp), %xmm14
movaps 0x90(%rsp), %xmm15
/* load NT_TIB */
movq %gs:(0x30), %r10
/* restore fiber local storage */
movq 0xb0(%rsp), %rax
movq %rax, 0x18(%r10)
/* restore current deallocation stack */
movq 0xb8(%rsp), %rax
movq %rax, 0x1478(%r10)
/* restore current stack limit */
movq 0xc0(%rsp), %rax
movq %rax, 0x10(%r10)
/* restore current stack base */
movq 0xc8(%rsp), %rax
movq %rax, 0x08(%r10)
movq 0xd0(%rsp), %r12 /* restore R12 */
movq 0xd8(%rsp), %r13 /* restore R13 */
movq 0xe0(%rsp), %r14 /* restore R14 */
movq 0xe8(%rsp), %r15 /* restore R15 */
movq 0xf0(%rsp), %rdi /* restore RDI */
movq 0xf8(%rsp), %rsi /* restore RSI */
movq 0x100(%rsp), %rbx /* restore RBX */
movq 0x108(%rsp), %rbp /* restore RBP */
leaq 0x118(%rsp), %rsp /* prepare stack */
/* restore return-address */
popq %r10
/* Set the third arg (data) as the first arg of the context function */
movq %r8, %rcx
/* indirect jump to context */
jmp *%r10
.seh_endproc
.section .drectve
.ascii " -export:\"jump_fcontext\""
|
whupdup/frame
|
real/third_party/boost_context/asm/jump_x86_64_ms_pe_gas.S
|
Assembly
|
gpl-3.0
| 10,284
|
; Copyright Oliver Kowalke 2009.
; Copyright Adrian Astley 2017 - 2018.
; 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)
; ---------------------------------------------------------------------------------
; | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
; ---------------------------------------------------------------------------------
; | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c |
; ---------------------------------------------------------------------------------
; | SEE registers (XMM6-XMM15) |
; ---------------------------------------------------------------------------------
; ---------------------------------------------------------------------------------
; | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
; ---------------------------------------------------------------------------------
; | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c |
; ---------------------------------------------------------------------------------
; | SEE registers (XMM6-XMM15) |
; ---------------------------------------------------------------------------------
; ---------------------------------------------------------------------------------
; | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
; ---------------------------------------------------------------------------------
; | 0xe40 | 0x44 | 0x48 | 0x4c | 0x50 | 0x54 | 0x58 | 0x5c |
; ---------------------------------------------------------------------------------
; | SEE registers (XMM6-XMM15)
; ---------------------------------------------------------------------------------
; ---------------------------------------------------------------------------------
; | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 |
; ---------------------------------------------------------------------------------
; | 0x60 | 0x64 | 0x68 | 0x6c | 0x70 | 0x74 | 0x78 | 0x7c |
; ---------------------------------------------------------------------------------
; | SEE registers (XMM6-XMM15) |
; ---------------------------------------------------------------------------------
; ---------------------------------------------------------------------------------
; | 32 | 32 | 33 | 34 | 35 | 36 | 37 | 38 |
; ---------------------------------------------------------------------------------
; | 0x80 | 0x84 | 0x88 | 0x8c | 0x90 | 0x94 | 0x98 | 0x9c |
; ---------------------------------------------------------------------------------
; | SEE registers (XMM6-XMM15) |
; ---------------------------------------------------------------------------------
; ---------------------------------------------------------------------------------
; | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 |
; ---------------------------------------------------------------------------------
; | 0xa0 | 0xa4 | 0xa8 | 0xac | 0xb0 | 0xb4 | 0xb8 | 0xbc |
; ---------------------------------------------------------------------------------
; | fc_mxcsr|fc_x87_cw| <alignment> | fbr_strg | fc_dealloc |
; ---------------------------------------------------------------------------------
; ---------------------------------------------------------------------------------
; | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 |
; ---------------------------------------------------------------------------------
; | 0xc0 | 0xc4 | 0xc8 | 0xcc | 0xd0 | 0xd4 | 0xd8 | 0xdc |
; ---------------------------------------------------------------------------------
; | limit | base | R12 | R13 |
; ---------------------------------------------------------------------------------
; ---------------------------------------------------------------------------------
; | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 |
; ---------------------------------------------------------------------------------
; | 0xe0 | 0xe4 | 0xe8 | 0xec | 0xf0 | 0xf4 | 0xf8 | 0xfc |
; ---------------------------------------------------------------------------------
; | R14 | R15 | RDI | RSI |
; ---------------------------------------------------------------------------------
; ---------------------------------------------------------------------------------
; | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 |
; ---------------------------------------------------------------------------------
; | 0x100 | 0x104 | 0x108 | 0x10c | 0x110 | 0x114 | 0x118 | 0x11c |
; ---------------------------------------------------------------------------------
; | RBX | RBP | <alignment> | RIP |
; ---------------------------------------------------------------------------------
; ---------------------------------------------------------------------------------
; | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 |
; ---------------------------------------------------------------------------------
; | 0x120 | 0x124 | 0x128 | 0x12c | 0x130 | 0x134 | 0x138 | 0x13c |
; ---------------------------------------------------------------------------------
; | "Shadow Space" |
; ---------------------------------------------------------------------------------
; ---------------------------------------------------------------------------------
; | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 |
; ---------------------------------------------------------------------------------
; | 0x140 | 0x144 | 0x148 | 0x14c | 0x150 | 0x154 | 0x158 | 0x15c |
; ---------------------------------------------------------------------------------
; | Caller's stack frame... |
; ---------------------------------------------------------------------------------
.code
jump_fcontext PROC FRAME
.endprolog
; prepare stack
lea rsp, [rsp-0118h]
; save XMM storage
movaps [rsp], xmm6
movaps [rsp+010h], xmm7
movaps [rsp+020h], xmm8
movaps [rsp+030h], xmm9
movaps [rsp+040h], xmm10
movaps [rsp+050h], xmm11
movaps [rsp+060h], xmm12
movaps [rsp+070h], xmm13
movaps [rsp+080h], xmm14
movaps [rsp+090h], xmm15
; save MMX control- and status-word
stmxcsr [rsp+0a0h]
; save x87 control-word
fnstcw [rsp+0a4h]
; load NT_TIB
mov r10, gs:[030h]
; save fiber local storage
mov rax, [r10+018h]
mov [rsp+0b0h], rax
; save current deallocation stack
mov rax, [r10+01478h]
mov [rsp+0b8h], rax
; save current stack limit
mov rax, [r10+010h]
mov [rsp+0c0h], rax
; save current stack base
mov rax, [r10+08h]
mov [rsp+0c8h], rax
mov [rsp+0d0h], r12 ; save R12
mov [rsp+0d8h], r13 ; save R13
mov [rsp+0e0h], r14 ; save R14
mov [rsp+0e8h], r15 ; save R15
mov [rsp+0f0h], rdi ; save RDI
mov [rsp+0f8h], rsi ; save RSI
mov [rsp+0100h], rbx ; save RBX
mov [rsp+0108h], rbp ; save RBP
; preserve RSP (pointing to context-data) in RCX
mov [rcx], rsp
; restore RSP (pointing to context-data) from RDX
mov rsp, rdx
; restore XMM storage
movaps xmm6, [rsp]
movaps xmm7, [rsp+010h]
movaps xmm8, [rsp+020h]
movaps xmm9, [rsp+030h]
movaps xmm10, [rsp+040h]
movaps xmm11, [rsp+050h]
movaps xmm12, [rsp+060h]
movaps xmm13, [rsp+070h]
movaps xmm14, [rsp+080h]
movaps xmm15, [rsp+090h]
; restore MMX control- and status-word
ldmxcsr [rsp+0a0h]
; save x87 control-word
fldcw [rsp+0a4h]
; load NT_TIB
mov r10, gs:[030h]
; restore fiber local storage
mov rax, [rsp+0b0h]
mov [r10+018h], rax
; restore current deallocation stack
mov rax, [rsp+0b8h]
mov [r10+01478h], rax
; restore current stack limit
mov rax, [rsp+0c0h]
mov [r10+010h], rax
; restore current stack base
mov rax, [rsp+0c8h]
mov [r10+08h], rax
mov r12, [rsp+0d0h] ; restore R12
mov r13, [rsp+0d8h] ; restore R13
mov r14, [rsp+0e0h] ; restore R14
mov r15, [rsp+0e8h] ; restore R15
mov rdi, [rsp+0f0h] ; restore RDI
mov rsi, [rsp+0f8h] ; restore RSI
mov rbx, [rsp+0100h] ; restore RBX
mov rbp, [rsp+0108h] ; restore RBP
; prepare stack
lea rsp, [rsp+0118h]
; Set the third arg (data) as the first arg of the context function
mov rcx, r8
; load return-address
pop r10
; indirect jump to context
jmp r10
ret
jump_fcontext ENDP
END
|
whupdup/frame
|
real/third_party/boost_context/asm/jump_x86_64_ms_pe_masm.asm
|
Assembly
|
gpl-3.0
| 9,533
|
/*
Copyright Oliver Kowalke 2009.
Copyright Adrian Astley 2017 - 2018.
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)
*/
/****************************************************************************************
* *
* ---------------------------------------------------------------------------------- *
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | *
* ---------------------------------------------------------------------------------- *
* | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | *
* ---------------------------------------------------------------------------------- *
* | fc_mxcsr|fc_x87_cw| R12 | R13 | R14 | *
* ---------------------------------------------------------------------------------- *
* ---------------------------------------------------------------------------------- *
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
* ---------------------------------------------------------------------------------- *
* | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | *
* ---------------------------------------------------------------------------------- *
* | R15 | RBX | RBP | RIP | *
* ---------------------------------------------------------------------------------- *
* *
****************************************************************************************/
.text
.globl jump_fcontext
.type jump_fcontext,@function
.align 16
jump_fcontext:
leaq -0x38(%rsp), %rsp /* prepare stack */
stmxcsr (%rsp) /* save MMX control- and status-word */
fnstcw 0x4(%rsp) /* save x87 control-word */
movq %r12, 0x8(%rsp) /* save R12 */
movq %r13, 0x10(%rsp) /* save R13 */
movq %r14, 0x18(%rsp) /* save R14 */
movq %r15, 0x20(%rsp) /* save R15 */
movq %rbx, 0x28(%rsp) /* save RBX */
movq %rbp, 0x30(%rsp) /* save RBP */
/* store RSP (pointing to context-data) in address given by RDI (first arg passed to jump_fcontext) */
movq %rsp, (%rdi)
/* restore RSP (pointing to context-data) from RSI */
movq %rsi, %rsp
movq 0x38(%rsp), %r8 /* restore return-address */
ldmxcsr (%rsp) /* restore MMX control- and status-word */
fldcw 0x4(%rsp) /* restore x87 control-word */
movq 0x8(%rsp), %r12 /* restore R12 */
movq 0x10(%rsp), %r13 /* restore R13 */
movq 0x18(%rsp), %r14 /* restore R14 */
movq 0x20(%rsp), %r15 /* restore R15 */
movq 0x28(%rsp), %rbx /* restore RBX */
movq 0x30(%rsp), %rbp /* restore RBP */
leaq 0x40(%rsp), %rsp /* prepare stack */
/* pass data (third arg passed to jump_fcontext) as first arg passed to context function */
movq %rdx, %rdi
/* indirect jump to context */
jmp *%r8
.size jump_fcontext,.-jump_fcontext
/* Mark that we don't need executable stack. */
.section .note.GNU-stack,"",%progbits
|
whupdup/frame
|
real/third_party/boost_context/asm/jump_x86_64_sysv_elf_gas.S
|
Assembly
|
gpl-3.0
| 3,401
|
/*
Copyright Oliver Kowalke 2009.
Copyright Adrian Astley 2017 - 2018.
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)
*/
/****************************************************************************************
* *
* ---------------------------------------------------------------------------------- *
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | *
* ---------------------------------------------------------------------------------- *
* | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | *
* ---------------------------------------------------------------------------------- *
* | fc_mxcsr|fc_x87_cw| R12 | R13 | R14 | *
* ---------------------------------------------------------------------------------- *
* ---------------------------------------------------------------------------------- *
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
* ---------------------------------------------------------------------------------- *
* | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | *
* ---------------------------------------------------------------------------------- *
* | R15 | RBX | RBP | RIP | *
* ---------------------------------------------------------------------------------- *
* *
****************************************************************************************/
.text
.globl _jump_fcontext
.align 8
_jump_fcontext:
leaq -0x38(%rsp), %rsp /* prepare stack */
stmxcsr (%rsp) /* save MMX control- and status-word */
fnstcw 0x4(%rsp) /* save x87 control-word */
movq %r12, 0x8(%rsp) /* save R12 */
movq %r13, 0x10(%rsp) /* save R13 */
movq %r14, 0x18(%rsp) /* save R14 */
movq %r15, 0x20(%rsp) /* save R15 */
movq %rbx, 0x28(%rsp) /* save RBX */
movq %rbp, 0x30(%rsp) /* save RBP */
/* store RSP (pointing to context-data) in address given by RDI (first arg passed to jump_fcontext) */
movq %rsp, (%rdi)
/* restore RSP (pointing to context-data) from RSI */
movq %rsi, %rsp
movq 0x38(%rsp), %r8 /* restore return-address */
ldmxcsr (%rsp) /* restore MMX control- and status-word */
fldcw 0x4(%rsp) /* restore x87 control-word */
movq 0x8(%rsp), %r12 /* restore R12 */
movq 0x10(%rsp), %r13 /* restore R13 */
movq 0x18(%rsp), %r14 /* restore R14 */
movq 0x20(%rsp), %r15 /* restore R15 */
movq 0x28(%rsp), %rbx /* restore RBX */
movq 0x30(%rsp), %rbp /* restore RBP */
leaq 0x40(%rsp), %rsp /* prepare stack */
/* pass data (third arg passed to jump_fcontext) as first arg passed to context function */
movq %rdx, %rdi
/* indirect jump to context */
jmp *%r8
|
whupdup/frame
|
real/third_party/boost_context/asm/jump_x86_64_sysv_macho_gas.S
|
Assembly
|
gpl-3.0
| 3,249
|
/*
Copyright Edward Nevill + Oliver Kowalke 2015
Copyright Adrian Astley 2017 - 2018.
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)
*/
/*******************************************************
* *
* ------------------------------------------------- *
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | *
* ------------------------------------------------- *
* | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| *
* ------------------------------------------------- *
* | d8 | d9 | d10 | d11 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
* ------------------------------------------------- *
* | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| *
* ------------------------------------------------- *
* | d12 | d13 | d14 | d15 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | *
* ------------------------------------------------- *
* | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| *
* ------------------------------------------------- *
* | x19 | x20 | x21 | x22 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | *
* ------------------------------------------------- *
* | 0x60| 0x64| 0x68| 0x6c| 0x70| 0x74| 0x78| 0x7c| *
* ------------------------------------------------- *
* | x23 | x24 | x25 | x26 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | *
* ------------------------------------------------- *
* | 0x80| 0x84| 0x88| 0x8c| 0x90| 0x94| 0x98| 0x9c| *
* ------------------------------------------------- *
* | x27 | x28 | FP | LR | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 40 | 41 | 42 | 43 | | | *
* ------------------------------------------------- *
* | 0xa0| 0xa4| 0xa8| 0xac| | | *
* ------------------------------------------------- *
* | PC | align | | | *
* ------------------------------------------------- *
* *
*******************************************************/
.text
.align 2
.global make_fcontext
.type make_fcontext, %function
make_fcontext:
# shift address in x0 (allocated stack) to lower 16 byte boundary
and x0, x0, ~0xF
# reserve space for context-data on context-stack
sub x0, x0, #0xb0
# third arg of make_fcontext() == address of context-function
# store address as a PC to jump in
str x2, [x0, #0xa0]
# save address of finish as return-address for context-function
# will be entered after context-function returns (LR register)
adr x1, finish
str x1, [x0, #0x98]
ret x30 // return pointer to context-data (x0)
finish:
# exit code is zero
mov x0, #0
# exit application
bl _exit
.size make_fcontext,.-make_fcontext
# Mark that we don't need executable stack.
.section .note.GNU-stack,"",%progbits
|
whupdup/frame
|
real/third_party/boost_context/asm/make_arm64_aapcs_elf_gas.S
|
Assembly
|
gpl-3.0
| 3,730
|
/*
Copyright Oliver Kowalke 2009.
Copyright Adrian Astley 2017 - 2018.
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)
*/
/*******************************************************
* *
* ------------------------------------------------- *
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | *
* ------------------------------------------------- *
* | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| *
* ------------------------------------------------- *
* | s16 | s17 | s18 | s19 | s20 | s21 | s22 | s23 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
* ------------------------------------------------- *
* | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| *
* ------------------------------------------------- *
* | s24 | s25 | s26 | s27 | s28 | s29 | s30 | s31 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | *
* ------------------------------------------------- *
* | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| *
* ------------------------------------------------- *
* | v1 | v2 | v3 | v4 | v5 | v6 | v7 | v8 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | *
* ------------------------------------------------- *
* | 0x60| 0x64| 0x68| 0x6c| 0x70| 0x74| 0x78| 0x7c| *
* ------------------------------------------------- *
* | lr | pc | | *
* ------------------------------------------------- *
* *
*******************************************************/
.text
.globl make_fcontext
.align 2
.type make_fcontext,%function
make_fcontext:
@ shift address in A1 to lower 16 byte boundary
bic a1, a1, #15
@ reserve space for context-data on context-stack
sub a1, a1, #128
@ third arg of make_fcontext() == address of context-function
str a3, [a1, #104]
@ compute abs address of label finish
adr a2, finish
@ save address of finish as return-address for context-function
@ will be entered after context-function returns
str a2, [a1, #100]
#if (defined(__VFP_FP__) && !defined(__SOFTFP__))
#endif
bx lr @ return to caller
finish:
@ exit code is zero
mov a1, #0
@ exit application
bl _exit@PLT
.size make_fcontext,.-make_fcontext
@ Mark that we don't need executable stack.
.section .note.GNU-stack,"",%progbits
|
whupdup/frame
|
real/third_party/boost_context/asm/make_arm_aapcs_elf_gas.S
|
Assembly
|
gpl-3.0
| 2,919
|
; Copyright Oliver Kowalke 2009.
; Copyright Adrian Astley 2017 - 2018.
; 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)
; ---------------------------------------------------------------------------------
; | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
; ---------------------------------------------------------------------------------
; | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c |
; ---------------------------------------------------------------------------------
; | SEE registers (XMM6-XMM15) |
; ---------------------------------------------------------------------------------
; ---------------------------------------------------------------------------------
; | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
; ---------------------------------------------------------------------------------
; | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c |
; ---------------------------------------------------------------------------------
; | SEE registers (XMM6-XMM15) |
; ---------------------------------------------------------------------------------
; ---------------------------------------------------------------------------------
; | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
; ---------------------------------------------------------------------------------
; | 0xe40 | 0x44 | 0x48 | 0x4c | 0x50 | 0x54 | 0x58 | 0x5c |
; ---------------------------------------------------------------------------------
; | SEE registers (XMM6-XMM15)
; ---------------------------------------------------------------------------------
; ---------------------------------------------------------------------------------
; | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 |
; ---------------------------------------------------------------------------------
; | 0x60 | 0x64 | 0x68 | 0x6c | 0x70 | 0x74 | 0x78 | 0x7c |
; ---------------------------------------------------------------------------------
; | SEE registers (XMM6-XMM15) |
; ---------------------------------------------------------------------------------
; ---------------------------------------------------------------------------------
; | 32 | 32 | 33 | 34 | 35 | 36 | 37 | 38 |
; ---------------------------------------------------------------------------------
; | 0x80 | 0x84 | 0x88 | 0x8c | 0x90 | 0x94 | 0x98 | 0x9c |
; ---------------------------------------------------------------------------------
; | SEE registers (XMM6-XMM15) |
; ---------------------------------------------------------------------------------
; ---------------------------------------------------------------------------------
; | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 |
; ---------------------------------------------------------------------------------
; | 0xa0 | 0xa4 | 0xa8 | 0xac | 0xb0 | 0xb4 | 0xb8 | 0xbc |
; ---------------------------------------------------------------------------------
; | fc_mxcsr|fc_x87_cw| <alignment> | fbr_strg | fc_dealloc |
; ---------------------------------------------------------------------------------
; ---------------------------------------------------------------------------------
; | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 |
; ---------------------------------------------------------------------------------
; | 0xc0 | 0xc4 | 0xc8 | 0xcc | 0xd0 | 0xd4 | 0xd8 | 0xdc |
; ---------------------------------------------------------------------------------
; | limit | base | R12 | R13 |
; ---------------------------------------------------------------------------------
; ---------------------------------------------------------------------------------
; | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 |
; ---------------------------------------------------------------------------------
; | 0xe0 | 0xe4 | 0xe8 | 0xec | 0xf0 | 0xf4 | 0xf8 | 0xfc |
; ---------------------------------------------------------------------------------
; | R14 | R15 | RDI | RSI |
; ---------------------------------------------------------------------------------
; ---------------------------------------------------------------------------------
; | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 |
; ---------------------------------------------------------------------------------
; | 0x100 | 0x104 | 0x108 | 0x10c | 0x110 | 0x114 | 0x118 | 0x11c |
; ---------------------------------------------------------------------------------
; | RBX | RBP | 0xC0FFEE | RIP |
; ---------------------------------------------------------------------------------
; ---------------------------------------------------------------------------------
; | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 |
; ---------------------------------------------------------------------------------
; | 0x120 | 0x124 | 0x128 | 0x12c | 0x130 | 0x134 | 0x138 | 0x13c |
; ---------------------------------------------------------------------------------
; | "Shadow Space" |
; ---------------------------------------------------------------------------------
; ---------------------------------------------------------------------------------
; | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 |
; ---------------------------------------------------------------------------------
; | 0x140 | 0x144 | 0x148 | 0x14c | 0x150 | 0x154 | 0x158 | 0x15c |
; ---------------------------------------------------------------------------------
; | Caller's stack frame... |
; ---------------------------------------------------------------------------------
; standard C library function
EXTERN _exit:PROC
.code
; generate function table entry in .pdata and unwind information in
make_fcontext PROC FRAME
; .xdata for a function's structured exception handling unwind behavior
.endprolog
; first arg of make_fcontext() == top of context-stack
mov rax, rcx
; shift address in RAX to lower 16 byte boundary
; == pointer to fcontext_t and address of context stack
and rax, -16
; reserve space for context-data on context-stack
; on context-function entry: (RSP -0x8) % 16 == 0
sub rax, 0140h
; first arg of make_fcontext() == top of context-stack
; save top address of context stack as 'base'
mov [rax+0c8h], rcx
; second arg of make_fcontext() == size of context-stack
; negate stack size for LEA instruction (== substraction)
neg rdx
; compute bottom address of context stack (limit)
lea rcx, [rcx+rdx]
; save bottom address of context stack as 'limit'
mov [rax+0c0h], rcx
; save address of context stack limit as 'dealloction stack'
mov [rax+0b8h], rcx
; set fiber-storage to zero
xor rcx, rcx
mov [rax+0b0h], rcx
; save MMX control- and status-word
stmxcsr [rax+0a0h]
; save x87 control-word
fnstcw [rax+0a4h]
; third arg of make_fcontext() == address of context-function
mov [rax+0100h], r8
; compute abs address of label trampoline
lea rcx, trampoline
; save address of trampoline as return-address for context-function
; will be entered after calling jump_fcontext() first time
mov [rax+0118h], rcx
; compute abs address of label finish
lea rcx, finish
; save address of finish as return-address for context-function in RBP
; will be entered after context-function returns
mov [rax+0108h], rcx
; set canary bytes
mov r10, 0c0ffeeh
mov [rax+0110h], r10
ret ; return pointer to context-data
trampoline:
; store return address on stack
; fix stack alignment
push rbp
; jump to context-function
jmp rbx
finish:
; exit code is zero
xor rcx, rcx
; exit application
call _exit
hlt
make_fcontext ENDP
END
|
whupdup/frame
|
real/third_party/boost_context/asm/make_canary_x86_64_ms_pe_masm.asm
|
Assembly
|
gpl-3.0
| 8,986
|
; Copyright Oliver Kowalke 2009.
; Copyright Adrian Astley 2017 - 2018.
; 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)
; ---------------------------------------------------------------------------------
; | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
; ---------------------------------------------------------------------------------
; | 0h | 04h | 08h | 0ch | 010h | 014h | 018h | 01ch |
; ---------------------------------------------------------------------------------
; | fc_mxcsr|fc_x87_cw| fc_strg |fc_deallo| limit | base | fc_seh | EDI |
; ---------------------------------------------------------------------------------
; ---------------------------------------------------------------------------------
; | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
; ---------------------------------------------------------------------------------
; | 020h | 024h | 028h | 02ch | 030h | 034h | 038h | 03ch |
; ---------------------------------------------------------------------------------
; | ESI | EBX | EBP | EIP | from | to | data | EH NXT |
; ---------------------------------------------------------------------------------
; ---------------------------------------------------------------------------------
; | 16 | | | | | | | |
; ---------------------------------------------------------------------------------
; | 040h | | | | | | | |
; ---------------------------------------------------------------------------------
; |SEH HNDLR| | | | | | | |
; ---------------------------------------------------------------------------------
.386
.XMM
.model flat, c
; standard C library function
_exit PROTO, value:SDWORD
.code
make_fcontext PROC
; first arg of make_fcontext() == top of context-stack
mov eax, [esp+04h]
; reserve space for first argument of context-function
; EAX might already point to a 16byte border
lea eax, [eax-08h]
; shift address in EAX to lower 16 byte boundary
and eax, -16
; reserve space for context-data on context-stack
; on context-function entry: (ESP -0x4) % 8 == 0
; additional space is required for SEH
lea eax, [eax-044h]
; save MMX control- and status-word
stmxcsr [eax]
; save x87 control-word
fnstcw [eax+04h]
; first arg of make_fcontext() == top of context-stack
mov ecx, [esp+04h]
; save top address of context stack as 'base'
mov [eax+014h], ecx
; second arg of make_fcontext() == size of context-stack
mov edx, [esp+08h]
; negate stack size for LEA instruction (== substraction)
neg edx
; compute bottom address of context stack (limit)
lea ecx, [ecx+edx]
; save bottom address of context-stack as 'limit'
mov [eax+010h], ecx
; save bottom address of context-stack as 'dealloction stack'
mov [eax+0ch], ecx
; set fiber-storage to zero
xor ecx, ecx
mov [eax+08h], ecx
; third arg of make_fcontext() == address of context-function
; stored in EBX
mov ecx, [esp+0ch]
mov [eax+024h], ecx
; compute abs address of label trampoline
mov ecx, trampoline
; save address of trampoline as return-address for context-function
; will be entered after calling jump_fcontext() first time
mov [eax+02ch], ecx
; compute abs address of label finish
mov ecx, finish
; save address of finish as return-address for context-function in EBP
; will be entered after context-function returns
mov [eax+028h], ecx
; traverse current seh chain to get the last exception handler installed by Windows
; note that on Windows Server 2008 and 2008 R2, SEHOP is activated by default
; the exception handler chain is tested for the presence of ntdll.dll!FinalExceptionHandler
; at its end by RaiseException all seh-handlers are disregarded if not present and the
; program is aborted
assume fs:nothing
; load NT_TIB into ECX
mov ecx, fs:[0h]
assume fs:error
walk:
; load 'next' member of current SEH into EDX
mov edx, [ecx]
; test if 'next' of current SEH is last (== 0xffffffff)
inc edx
jz found
dec edx
; exchange content; ECX contains address of next SEH
xchg edx, ecx
; inspect next SEH
jmp walk
found:
; load 'handler' member of SEH == address of last SEH handler installed by Windows
mov ecx, [ecx+04h]
; save address in ECX as SEH handler for context
mov [eax+03ch], ecx
; set ECX to -1
mov ecx, 0ffffffffh
; save ECX as next SEH item
mov [eax+038h], ecx
; load address of next SEH item
lea ecx, [eax+038h]
; save next SEH
mov [eax+018h], ecx
ret ; return pointer to context-data
trampoline:
; move data for entering context-function
mov [esp], eax
push ebp
; jump to context-function
jmp ebx
finish:
; exit code is zero
xor eax, eax
mov [esp], eax
; exit application
call _exit
hlt
make_fcontext ENDP
END
|
whupdup/frame
|
real/third_party/boost_context/asm/make_i386_ms_pe_masm.asm
|
Assembly
|
gpl-3.0
| 5,436
|
/*
Copyright Oliver Kowalke 2009.
Copyright Thomas Sailer 2013.
Copyright Adrian Astley 2017 - 2018.
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)
*/
/*************************************************************************************
* ---------------------------------------------------------------------------------- *
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | *
* ---------------------------------------------------------------------------------- *
* | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | *
* ---------------------------------------------------------------------------------- *
* | SEE registers (XMM6-XMM15) | *
* ---------------------------------------------------------------------------------- *
* ---------------------------------------------------------------------------------- *
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
* ---------------------------------------------------------------------------------- *
* | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | *
* ---------------------------------------------------------------------------------- *
* | SEE registers (XMM6-XMM15) | *
* ---------------------------------------------------------------------------------- *
* ---------------------------------------------------------------------------------- *
* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | *
* ---------------------------------------------------------------------------------- *
* | 0xe40 | 0x44 | 0x48 | 0x4c | 0x50 | 0x54 | 0x58 | 0x5c | *
* ---------------------------------------------------------------------------------- *
* | SEE registers (XMM6-XMM15) | *
* ---------------------------------------------------------------------------------- *
* ---------------------------------------------------------------------------------- *
* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | *
* ---------------------------------------------------------------------------------- *
* | 0x60 | 0x64 | 0x68 | 0x6c | 0x70 | 0x74 | 0x78 | 0x7c | *
* ---------------------------------------------------------------------------------- *
* | SEE registers (XMM6-XMM15) | *
* ---------------------------------------------------------------------------------- *
* ---------------------------------------------------------------------------------- *
* | 32 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | *
* ---------------------------------------------------------------------------------- *
* | 0x80 | 0x84 | 0x88 | 0x8c | 0x90 | 0x94 | 0x98 | 0x9c | *
* ---------------------------------------------------------------------------------- *
* | SEE registers (XMM6-XMM15) | *
* ---------------------------------------------------------------------------------- *
* ---------------------------------------------------------------------------------- *
* | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | *
* ---------------------------------------------------------------------------------- *
* | 0xa0 | 0xa4 | 0xa8 | 0xac | 0xb0 | 0xb4 | 0xb8 | 0xbc | *
* ---------------------------------------------------------------------------------- *
* | fc_mxcsr|fc_x87_cw| <alignment> | fbr_strg | fc_dealloc | *
* ---------------------------------------------------------------------------------- *
* ---------------------------------------------------------------------------------- *
* | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | *
* ---------------------------------------------------------------------------------- *
* | 0xc0 | 0xc4 | 0xc8 | 0xcc | 0xd0 | 0xd4 | 0xd8 | 0xdc | *
* ---------------------------------------------------------------------------------- *
* | limit | base | R12 | R13 | *
* ---------------------------------------------------------------------------------- *
* ---------------------------------------------------------------------------------- *
* | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | *
* ---------------------------------------------------------------------------------- *
* | 0xe0 | 0xe4 | 0xe8 | 0xec | 0xf0 | 0xf4 | 0xf8 | 0xfc | *
* ---------------------------------------------------------------------------------- *
* | R14 | R15 | RDI | RSI | *
* ---------------------------------------------------------------------------------- *
* ---------------------------------------------------------------------------------- *
* | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | *
* ---------------------------------------------------------------------------------- *
* | 0x100 | 0x104 | 0x108 | 0x10c | 0x110 | 0x114 | 0x118 | 0x11c | *
* ---------------------------------------------------------------------------------- *
* | RBX | RBP | hidden | RIP | *
* ---------------------------------------------------------------------------------- *
* ---------------------------------------------------------------------------------- *
* | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | *
* ---------------------------------------------------------------------------------- *
* | 0x120 | 0x124 | 0x128 | 0x12c | 0x130 | 0x134 | 0x138 | 0x13c | *
* ---------------------------------------------------------------------------------- *
* | parameter area | *
* ---------------------------------------------------------------------------------- *
* ---------------------------------------------------------------------------------- *
* | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | *
* ---------------------------------------------------------------------------------- *
* | 0x140 | 0x144 | 0x148 | 0x14c | 0x150 | 0x154 | 0x158 | 0x15c | *
* ---------------------------------------------------------------------------------- *
* | FCTX | DATA | | *
* ---------------------------------------------------------------------------------- *
**************************************************************************************/
//.file "make_x86_64_ms_pe_gas.asm"
.text
.p2align 4,,15
.globl make_fcontext
.def make_fcontext; .scl 2; .type 32; .endef
.seh_proc make_fcontext
make_fcontext:
.seh_endprologue
/* first arg of make_fcontext() == top of context-stack */
movq %rcx, %rax
/* shift address in RAX to lower 16 byte boundary */
/* == pointer to fcontext_t and address of context stack */
andq $-16, %rax
/* reserve space for context-data on context-stack */
/* on context-function entry: (RSP -0x8) % 16 == 0 */
leaq -0x150(%rax), %rax
/* third arg of make_fcontext() == address of context-function */
movq %r8, 0x100(%rax)
/* first arg of make_fcontext() == top of context-stack */
/* save top address of context stack as 'base' */
movq %rcx, 0xc8(%rax)
/* second arg of make_fcontext() == size of context-stack */
/* negate stack size for LEA instruction (== substraction) */
negq %rdx
/* compute bottom address of context stack (limit) */
leaq (%rcx,%rdx), %rcx
/* save bottom address of context stack as 'limit' */
movq %rcx, 0xc0(%rax)
/* save address of context stack limit as 'dealloction stack' */
movq %rcx, 0xb8(%rax)
/* set fiber-storage to zero */
xorq %rcx, %rcx
movq %rcx, 0xb0(%rax)
/* compute address of transport_t */
leaq 0x140(%rax), %rcx
/* store address of transport_t in hidden field */
movq %rcx, 0x110(%rax)
/* compute abs address of label trampoline */
leaq trampoline(%rip), %rcx
/* save address of finish as return-address for context-function */
/* will be entered after jump_fcontext() first time */
movq %rcx, 0x118(%rax)
/* compute abs address of label finish */
leaq finish(%rip), %rcx
/* save address of finish as return-address for context-function */
/* will be entered after context-function returns */
movq %rcx, 0x108(%rax)
ret /* return pointer to context-data */
trampoline:
/* store return address on stack */
/* fix stack alignment */
pushq %rbp
/* jump to context-function */
jmp *%rbx
finish:
/* 32byte shadow-space for _exit() */
andq $-32, %rsp
/* 32byte shadow-space for _exit() are */
/* already reserved by make_fcontext() */
/* exit code is zero */
xorq %rcx, %rcx
/* exit application */
call _exit
hlt
.seh_endproc
.def _exit; .scl 2; .type 32; .endef /* standard C library function */
.section .drectve
.ascii " -export:\"make_fcontext\""
|
whupdup/frame
|
real/third_party/boost_context/asm/make_x86_64_ms_pe_gas.S
|
Assembly
|
gpl-3.0
| 9,701
|
; Copyright Oliver Kowalke 2009.
; Copyright Adrian Astley 2017 - 2018.
; 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)
; ---------------------------------------------------------------------------------
; | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
; ---------------------------------------------------------------------------------
; | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c |
; ---------------------------------------------------------------------------------
; | SEE registers (XMM6-XMM15) |
; ---------------------------------------------------------------------------------
; ---------------------------------------------------------------------------------
; | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
; ---------------------------------------------------------------------------------
; | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c |
; ---------------------------------------------------------------------------------
; | SEE registers (XMM6-XMM15) |
; ---------------------------------------------------------------------------------
; ---------------------------------------------------------------------------------
; | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
; ---------------------------------------------------------------------------------
; | 0xe40 | 0x44 | 0x48 | 0x4c | 0x50 | 0x54 | 0x58 | 0x5c |
; ---------------------------------------------------------------------------------
; | SEE registers (XMM6-XMM15)
; ---------------------------------------------------------------------------------
; ---------------------------------------------------------------------------------
; | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 |
; ---------------------------------------------------------------------------------
; | 0x60 | 0x64 | 0x68 | 0x6c | 0x70 | 0x74 | 0x78 | 0x7c |
; ---------------------------------------------------------------------------------
; | SEE registers (XMM6-XMM15) |
; ---------------------------------------------------------------------------------
; ---------------------------------------------------------------------------------
; | 32 | 32 | 33 | 34 | 35 | 36 | 37 | 38 |
; ---------------------------------------------------------------------------------
; | 0x80 | 0x84 | 0x88 | 0x8c | 0x90 | 0x94 | 0x98 | 0x9c |
; ---------------------------------------------------------------------------------
; | SEE registers (XMM6-XMM15) |
; ---------------------------------------------------------------------------------
; ---------------------------------------------------------------------------------
; | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 |
; ---------------------------------------------------------------------------------
; | 0xa0 | 0xa4 | 0xa8 | 0xac | 0xb0 | 0xb4 | 0xb8 | 0xbc |
; ---------------------------------------------------------------------------------
; | fc_mxcsr|fc_x87_cw| <alignment> | fbr_strg | fc_dealloc |
; ---------------------------------------------------------------------------------
; ---------------------------------------------------------------------------------
; | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 |
; ---------------------------------------------------------------------------------
; | 0xc0 | 0xc4 | 0xc8 | 0xcc | 0xd0 | 0xd4 | 0xd8 | 0xdc |
; ---------------------------------------------------------------------------------
; | limit | base | R12 | R13 |
; ---------------------------------------------------------------------------------
; ---------------------------------------------------------------------------------
; | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 |
; ---------------------------------------------------------------------------------
; | 0xe0 | 0xe4 | 0xe8 | 0xec | 0xf0 | 0xf4 | 0xf8 | 0xfc |
; ---------------------------------------------------------------------------------
; | R14 | R15 | RDI | RSI |
; ---------------------------------------------------------------------------------
; ---------------------------------------------------------------------------------
; | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 |
; ---------------------------------------------------------------------------------
; | 0x100 | 0x104 | 0x108 | 0x10c | 0x110 | 0x114 | 0x118 | 0x11c |
; ---------------------------------------------------------------------------------
; | RBX | RBP | <alignment> | RIP |
; ---------------------------------------------------------------------------------
; ---------------------------------------------------------------------------------
; | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 |
; ---------------------------------------------------------------------------------
; | 0x120 | 0x124 | 0x128 | 0x12c | 0x130 | 0x134 | 0x138 | 0x13c |
; ---------------------------------------------------------------------------------
; | "Shadow Space" |
; ---------------------------------------------------------------------------------
; ---------------------------------------------------------------------------------
; | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 |
; ---------------------------------------------------------------------------------
; | 0x140 | 0x144 | 0x148 | 0x14c | 0x150 | 0x154 | 0x158 | 0x15c |
; ---------------------------------------------------------------------------------
; | Caller's stack frame... |
; ---------------------------------------------------------------------------------
; standard C library function
EXTERN _exit:PROC
.code
; generate function table entry in .pdata and unwind information in
make_fcontext PROC FRAME
; .xdata for a function's structured exception handling unwind behavior
.endprolog
; first arg of make_fcontext() == top of context-stack
mov rax, rcx
; shift address in RAX to lower 16 byte boundary
; == pointer to fcontext_t and address of context stack
and rax, -16
; reserve space for context-data on context-stack
; on context-function entry: (RSP -0x8) % 16 == 0
sub rax, 0140h
; first arg of make_fcontext() == top of context-stack
; save top address of context stack as 'base'
mov [rax+0c8h], rcx
; second arg of make_fcontext() == size of context-stack
; negate stack size for LEA instruction (== substraction)
neg rdx
; compute bottom address of context stack (limit)
lea rcx, [rcx+rdx]
; save bottom address of context stack as 'limit'
mov [rax+0c0h], rcx
; save address of context stack limit as 'dealloction stack'
mov [rax+0b8h], rcx
; set fiber-storage to zero
xor rcx, rcx
mov [rax+0b0h], rcx
; save MMX control- and status-word
stmxcsr [rax+0a0h]
; save x87 control-word
fnstcw [rax+0a4h]
; third arg of make_fcontext() == address of context-function
mov [rax+0100h], r8
; compute abs address of label trampoline
lea rcx, trampoline
; save address of trampoline as return-address for context-function
; will be entered after calling jump_fcontext() first time
mov [rax+0118h], rcx
; compute abs address of label finish
lea rcx, finish
; save address of finish as return-address for context-function in RBP
; will be entered after context-function returns
mov [rax+0108h], rcx
ret ; return pointer to context-data
trampoline:
; store return address on stack
; fix stack alignment
push rbp
; jump to context-function
jmp rbx
finish:
; exit code is zero
xor rcx, rcx
; exit application
call _exit
hlt
make_fcontext ENDP
END
|
whupdup/frame
|
real/third_party/boost_context/asm/make_x86_64_ms_pe_masm.asm
|
Assembly
|
gpl-3.0
| 8,924
|
/*
Copyright Oliver Kowalke 2009.
Copyright Adrian Astley 2017 - 2018.
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)
*/
/****************************************************************************************
* *
* ---------------------------------------------------------------------------------- *
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | *
* ---------------------------------------------------------------------------------- *
* | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | *
* ---------------------------------------------------------------------------------- *
* | fc_mxcsr|fc_x87_cw| R12 | R13 | R14 | *
* ---------------------------------------------------------------------------------- *
* ---------------------------------------------------------------------------------- *
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
* ---------------------------------------------------------------------------------- *
* | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | *
* ---------------------------------------------------------------------------------- *
* | R15 | RBX | RBP | RIP | *
* ---------------------------------------------------------------------------------- *
* *
****************************************************************************************/
.text
.globl make_fcontext
.type make_fcontext,@function
.align 16
make_fcontext:
/* first arg of make_fcontext() == top of context-stack */
movq %rdi, %rax
/* shift address in RAX to lower 16 byte boundary */
andq $-16, %rax
/* reserve space for context-data on context-stack */
/* on context-function entry: (RSP -0x8) % 16 == 0 */
leaq -0x40(%rax), %rax
/* third arg of make_fcontext() == address of context-function */
/* stored in RBX */
movq %rdx, 0x28(%rax)
/* save MMX control- and status-word */
stmxcsr (%rax)
/* save x87 control-word */
fnstcw 0x4(%rax)
/* compute abs address of label trampoline */
leaq trampoline(%rip), %rcx
/* save address of trampoline as return-address for context-function */
/* will be entered after calling jump_fcontext() first time */
movq %rcx, 0x38(%rax)
/* compute abs address of label finish */
leaq finish(%rip), %rcx
/* save address of finish as return-address for context-function */
/* will be entered after context-function returns */
movq %rcx, 0x30(%rax)
ret /* return pointer to context-data */
trampoline:
/* store return address on stack */
/* fix stack alignment */
push %rbp
/* jump to context-function */
jmp *%rbx
finish:
/* exit code is zero */
xorq %rdi, %rdi
/* exit application */
call _exit@PLT
hlt
.size make_fcontext,.-make_fcontext
/* Mark that we don't need executable stack. */
.section .note.GNU-stack,"",%progbits
|
whupdup/frame
|
real/third_party/boost_context/asm/make_x86_64_sysv_elf_gas.S
|
Assembly
|
gpl-3.0
| 3,435
|
/*
Copyright Oliver Kowalke 2009.
Copyright Adrian Astley 2017 - 2018.
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)
*/
/****************************************************************************************
* *
* ---------------------------------------------------------------------------------- *
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | *
* ---------------------------------------------------------------------------------- *
* | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | *
* ---------------------------------------------------------------------------------- *
* | fc_mxcsr|fc_x87_cw| R12 | R13 | R14 | *
* ---------------------------------------------------------------------------------- *
* ---------------------------------------------------------------------------------- *
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
* ---------------------------------------------------------------------------------- *
* | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | *
* ---------------------------------------------------------------------------------- *
* | R15 | RBX | RBP | RIP | *
* ---------------------------------------------------------------------------------- *
* *
****************************************************************************************/
.text
.globl _make_fcontext
.align 8
_make_fcontext:
/* first arg of make_fcontext() == top of context-stack */
movq %rdi, %rax
/* shift address in RAX to lower 16 byte boundary */
andq $-16, %rax
/* reserve space for context-data on context-stack */
/* on context-function entry: (RSP -0x8) % 16 == 0 */
leaq -0x40(%rax), %rax
/* third arg of make_fcontext() == address of context-function */
/* stored in RBX */
movq %rdx, 0x28(%rax)
/* save MMX control- and status-word */
stmxcsr (%rax)
/* save x87 control-word */
fnstcw 0x4(%rax)
/* compute abs address of label trampoline */
leaq trampoline(%rip), %rcx
/* save address of trampoline as return-address for context-function */
/* will be entered after calling jump_fcontext() first time */
movq %rcx, 0x38(%rax)
/* compute abs address of label finish */
leaq finish(%rip), %rcx
/* save address of finish as return-address for context-function */
/* will be entered after context-function returns */
movq %rcx, 0x30(%rax)
ret /* return pointer to context-data */
trampoline:
/* store return address on stack */
/* fix stack alignment */
push %rbp
/* jump to context-function */
jmp *%rbx
finish:
/* exit code is zero */
xorq %rdi, %rdi
/* exit application */
call __exit
hlt
|
whupdup/frame
|
real/third_party/boost_context/asm/make_x86_64_sysv_macho_gas.S
|
Assembly
|
gpl-3.0
| 3,280
|
/*
Copyright Edward Nevill + Oliver Kowalke 2015
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)
*/
/*******************************************************
* *
* ------------------------------------------------- *
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | *
* ------------------------------------------------- *
* | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| *
* ------------------------------------------------- *
* | d8 | d9 | d10 | d11 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
* ------------------------------------------------- *
* | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| *
* ------------------------------------------------- *
* | d12 | d13 | d14 | d15 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | *
* ------------------------------------------------- *
* | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| *
* ------------------------------------------------- *
* | x19 | x20 | x21 | x22 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | *
* ------------------------------------------------- *
* | 0x60| 0x64| 0x68| 0x6c| 0x70| 0x74| 0x78| 0x7c| *
* ------------------------------------------------- *
* | x23 | x24 | x25 | x26 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | *
* ------------------------------------------------- *
* | 0x80| 0x84| 0x88| 0x8c| 0x90| 0x94| 0x98| 0x9c| *
* ------------------------------------------------- *
* | x27 | x28 | FP | LR | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 40 | 41 | 42 | 43 | | | *
* ------------------------------------------------- *
* | 0xa0| 0xa4| 0xa8| 0xac| | | *
* ------------------------------------------------- *
* | PC | align | | | *
* ------------------------------------------------- *
* *
*******************************************************/
.text
.globl _jump_fcontext
.balign 16
_jump_fcontext:
; prepare stack for GP + FPU
sub sp, sp, #0xb0
; save d8 - d15
stp d8, d9, [sp, #0x00]
stp d10, d11, [sp, #0x10]
stp d12, d13, [sp, #0x20]
stp d14, d15, [sp, #0x30]
; save x19-x30
stp x19, x20, [sp, #0x40]
stp x21, x22, [sp, #0x50]
stp x23, x24, [sp, #0x60]
stp x25, x26, [sp, #0x70]
stp x27, x28, [sp, #0x80]
stp fp, lr, [sp, #0x90]
; save LR as PC
str lr, [sp, #0xa0]
; store RSP (pointing to context-data) in X0
mov x4, sp
; restore RSP (pointing to context-data) from X1
mov sp, x0
; load d8 - d15
ldp d8, d9, [sp, #0x00]
ldp d10, d11, [sp, #0x10]
ldp d12, d13, [sp, #0x20]
ldp d14, d15, [sp, #0x30]
; load x19-x30
ldp x19, x20, [sp, #0x40]
ldp x21, x22, [sp, #0x50]
ldp x23, x24, [sp, #0x60]
ldp x25, x26, [sp, #0x70]
ldp x27, x28, [sp, #0x80]
ldp fp, lr, [sp, #0x90]
; return transfer_t from jump
; pass transfer_t as first arg in context function
; X0 == FCTX, X1 == DATA
mov x0, x4
; load pc
ldr x4, [sp, #0xa0]
; restore stack from GP + FPU
add sp, sp, #0xb0
ret x4
|
whupdup/frame
|
real/third_party/boost_context/asm/not_modified_yet/jump_arm64_aapcs_macho_gas.S
|
Assembly
|
gpl-3.0
| 4,090
|
/*
Copyright Oliver Kowalke 2009.
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)
*/
/*******************************************************
* *
* ------------------------------------------------- *
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | *
* ------------------------------------------------- *
* | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| *
* ------------------------------------------------- *
* | s16 | s17 | s18 | s19 | s20 | s21 | s22 | s23 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
* ------------------------------------------------- *
* | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| *
* ------------------------------------------------- *
* | s24 | s25 | s26 | s27 | s28 | s29 | s30 | s31 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | *
* ------------------------------------------------- *
* | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| *
* ------------------------------------------------- *
* | sjlj|hiddn| v1 | v2 | v3 | v4 | v5 | v6 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | *
* ------------------------------------------------- *
* | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| *
* ------------------------------------------------- *
* | v7 | v8 | lr | pc | FCTX| DATA| | *
* ------------------------------------------------- *
* *
*******************************************************/
.text
.globl _jump_fcontext
.align 2
_jump_fcontext:
@ save LR as PC
push {lr}
@ save hidden,V1-V8,LR
push {a1,v1-v8,lr}
@ locate TLS to save/restore SjLj handler
mrc p15, 0, v2, c13, c0, #3
bic v2, v2, #3
@ load TLS[__PTK_LIBC_DYLD_Unwind_SjLj_Key]
ldr v1, [v2, #8]
@ save SjLj handler
push {v1}
@ prepare stack for FPU
sub sp, sp, #64
#if (defined(__VFP_FP__) && !defined(__SOFTFP__))
@ save S16-S31
vstmia sp, {d8-d15}
#endif
@ store RSP (pointing to context-data) in A1
mov a1, sp
@ restore RSP (pointing to context-data) from A2
mov sp, a2
#if (defined(__VFP_FP__) && !defined(__SOFTFP__))
@ restore S16-S31
vldmia sp, {d8-d15}
#endif
@ prepare stack for FPU
add sp, sp, #64
@ r#estore SjLj handler
pop {v1}
@ store SjLj handler in TLS
str v1, [v2, #8]
@ restore hidden,V1-V8,LR
pop {a4,v1-v8,lr}
@ return transfer_t from jump
str a1, [a4, #0]
str a3, [a4, #4]
@ pass transfer_t as first arg in context function
@ A1 == FCTX, A2 == DATA
mov a2, a3
@ restore PC
pop {pc}
|
whupdup/frame
|
real/third_party/boost_context/asm/not_modified_yet/jump_arm_aapcs_macho_gas.S
|
Assembly
|
gpl-3.0
| 3,189
|
;/*
; Copyright Oliver Kowalke 2009.
; 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)
;*/
; *******************************************************
; * *
; * ------------------------------------------------- *
; * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | *
; * ------------------------------------------------- *
; * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| *
; * ------------------------------------------------- *
; * |deall|limit| base|hiddn| v1 | v2 | v3 | v4 | *
; * ------------------------------------------------- *
; * ------------------------------------------------- *
; * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
; * ------------------------------------------------- *
; * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| *
; * ------------------------------------------------- *
; * | v5 | v6 | v7 | v8 | lr | pc | FCTX| DATA| *
; * ------------------------------------------------- *
; * *
; *******************************************************
AREA |.text|, CODE
ALIGN 4
EXPORT jump_fcontext
jump_fcontext PROC
; save LR as PC
push {lr}
; save hidden,V1-V8,LR
push {a1,v1-v8,lr}
; load TIB to save/restore thread size and limit.
; we do not need preserve CPU flag and can use it's arg register
mrc p15, #0, v1, c13, c0, #2
; save current stack base
ldr a5, [v1, #0x04]
push {a5}
; save current stack limit
ldr a5, [v1, #0x08]
push {a5}
; save current deallocation stack
ldr a5, [v1, #0xe0c]
push {a5}
; store RSP (pointing to context-data) in A1
mov a1, sp
; restore RSP (pointing to context-data) from A2
mov sp, a2
; restore deallocation stack
pop {a5}
str a5, [v1, #0xe0c]
; restore stack limit
pop {a5}
str a5, [v1, #0x08]
; restore stack base
pop {a5}
str a5, [v1, #0x04]
; restore hidden,V1-V8,LR
pop {a4,v1-v8,lr}
; return transfer_t from jump
str a1, [a4, #0]
str a3, [a4, #4]
; pass transfer_t as first arg in context function
; A1 == FCTX, A2 == DATA
mov a2, a3
; restore PC
pop {pc}
ENDP
END
|
whupdup/frame
|
real/third_party/boost_context/asm/not_modified_yet/jump_arm_aapcs_pe_armasm.asm
|
Assembly
|
gpl-3.0
| 2,430
|
/*
Copyright Sergue E. Leontiev 2013.
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)
*/
// Stub file for universal binary
#if defined(__i386__)
#include "jump_i386_sysv_macho_gas.S"
#elif defined(__x86_64__)
#include "jump_x86_64_sysv_macho_gas.S"
#elif defined(__ppc__)
#include "jump_ppc32_sysv_macho_gas.S"
#elif defined(__ppc64__)
#include "jump_ppc64_sysv_macho_gas.S"
#else
#error "No arch's"
#endif
|
whupdup/frame
|
real/third_party/boost_context/asm/not_modified_yet/jump_combined_sysv_macho_gas.S
|
Assembly
|
gpl-3.0
| 559
|
/*
Copyright Oliver Kowalke 2009.
Copyright Thomas Sailer 2013.
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)
*/
/*************************************************************************************
* --------------------------------------------------------------------------------- *
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | *
* --------------------------------------------------------------------------------- *
* | 0h | 04h | 08h | 0ch | 010h | 014h | 018h | 01ch | *
* --------------------------------------------------------------------------------- *
* | fc_mxcsr|fc_x87_cw| fc_strg |fc_deallo| limit | base | fc_seh | EDI | *
* --------------------------------------------------------------------------------- *
* --------------------------------------------------------------------------------- *
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
* --------------------------------------------------------------------------------- *
* | 020h | 024h | 028h | 02ch | 030h | 034h | 038h | 03ch | *
* --------------------------------------------------------------------------------- *
* | ESI | EBX | EBP | EIP | to | data | EH NXT |SEH HNDLR| *
* --------------------------------------------------------------------------------- *
**************************************************************************************/
.file "jump_i386_ms_pe_gas.asm"
.text
.p2align 4,,15
.globl _jump_fcontext
.def _jump_fcontext; .scl 2; .type 32; .endef
_jump_fcontext:
/* prepare stack */
leal -0x2c(%esp), %esp
/* save MMX control- and status-word */
stmxcsr (%esp)
/* save x87 control-word */
fnstcw 0x4(%esp)
/* load NT_TIB */
movl %fs:(0x18), %edx
/* load fiber local storage */
movl 0x10(%edx), %eax
movl %eax, 0x8(%esp)
/* load current dealloction stack */
movl 0xe0c(%edx), %eax
movl %eax, 0xc(%esp)
/* load current stack limit */
movl 0x8(%edx), %eax
movl %eax, 0x10(%esp)
/* load current stack base */
movl 0x4(%edx), %eax
movl %eax, 0x14(%esp)
/* load current SEH exception list */
movl (%edx), %eax
movl %eax, 0x18(%esp)
movl %edi, 0x1c(%esp) /* save EDI */
movl %esi, 0x20(%esp) /* save ESI */
movl %ebx, 0x24(%esp) /* save EBX */
movl %ebp, 0x28(%esp) /* save EBP */
/* store ESP (pointing to context-data) in EAX */
movl %esp, %eax
/* firstarg of jump_fcontext() == fcontext to jump to */
movl 0x30(%esp), %ecx
/* restore ESP (pointing to context-data) from ECX */
movl %ecx, %esp
/* restore MMX control- and status-word */
ldmxcsr (%esp)
/* restore x87 control-word */
fldcw 0x4(%esp)
/* restore NT_TIB into EDX */
movl %fs:(0x18), %edx
/* restore fiber local storage */
movl 0x8(%esp), %ecx
movl %ecx, 0x10(%edx)
/* restore current deallocation stack */
movl 0xc(%esp), %ecx
movl %ecx, 0xe0c(%edx)
/* restore current stack limit */
movl 0x10(%esp), %ecx
movl %ecx, 0x8(%edx)
/* restore current stack base */
movl 0x14(%esp), %ecx
movl %ecx, 0x4(%edx)
/* restore current SEH exception list */
movl 0x18(%esp), %ecx
movl %ecx, (%edx)
movl 0x2c(%esp), %ecx /* restore EIP */
movl 0x1c(%esp), %edi /* restore EDI */
movl 0x20(%esp), %esi /* restore ESI */
movl 0x24(%esp), %ebx /* restore EBX */
movl 0x28(%esp), %ebp /* restore EBP */
/* prepare stack */
leal 0x30(%esp), %esp
/* return transfer_t */
/* FCTX == EAX, DATA == EDX */
movl 0x34(%eax), %edx
/* jump to context */
jmp *%ecx
.section .drectve
.ascii " -export:\"jump_fcontext\""
|
whupdup/frame
|
real/third_party/boost_context/asm/not_modified_yet/jump_i386_ms_pe_gas.asm
|
Assembly
|
gpl-3.0
| 4,007
|
/*
Copyright Oliver Kowalke 2009.
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)
*/
/****************************************************************************************
* *
* ---------------------------------------------------------------------------------- *
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | *
* ---------------------------------------------------------------------------------- *
* | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | *
* ---------------------------------------------------------------------------------- *
* | fc_mxcsr|fc_x87_cw| EDI | ESI | EBX | EBP | EIP | hidden | *
* ---------------------------------------------------------------------------------- *
* ---------------------------------------------------------------------------------- *
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
* ---------------------------------------------------------------------------------- *
* | 0x20 | 0x24 | 0x28 | | *
* ---------------------------------------------------------------------------------- *
* | from | to | data | | *
* ---------------------------------------------------------------------------------- *
* *
****************************************************************************************/
.text
.globl jump_fcontext
.align 2
.type jump_fcontext,@function
jump_fcontext:
leal -0x18(%esp), %esp /* prepare stack */
stmxcsr (%esp) /* save MMX control- and status-word */
fnstcw 0x4(%esp) /* save x87 control-word */
movl %edi, 0x8(%esp) /* save EDI */
movl %esi, 0xc(%esp) /* save ESI */
movl %ebx, 0x10(%esp) /* save EBX */
movl %ebp, 0x14(%esp) /* save EBP */
/* store ESP (pointing to context-data) at address pointed by arg 1 */
movl 0x20(%esp), %eax
movl %esp, (%eax)
/* second arg of jump_fcontext() == fcontext to jump to */
movl 0x24(%esp), %ecx
/* third arg of jump_fcontext() == data to be transferred */
movl 0x28(%esp), %eax
/* restore ESP (pointing to context-data) from ECX */
movl %ecx, %esp
ldmxcsr (%esp) /* restore MMX control- and status-word */
fldcw 0x4(%esp) /* restore x87 control-word */
movl 0x18(%esp), %ecx /* restore EIP */
movl 0x8(%esp), %edi /* restore EDI */
movl 0xc(%esp), %esi /* restore ESI */
movl 0x10(%esp), %ebx /* restore EBX */
movl 0x14(%esp), %ebp /* restore EBP */
leal 0x20(%esp), %esp /* prepare stack */
/* jump to context */
jmp *%ecx
.size jump_fcontext,.-jump_fcontext
/* Mark that we don't need executable stack. */
.section .note.GNU-stack,"",%progbits
|
whupdup/frame
|
real/third_party/boost_context/asm/not_modified_yet/jump_i386_sysv_elf_gas.S
|
Assembly
|
gpl-3.0
| 3,202
|
/*
Copyright Oliver Kowalke 2009.
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)
*/
/****************************************************************************************
* *
* ---------------------------------------------------------------------------------- *
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | *
* ---------------------------------------------------------------------------------- *
* | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | *
* ---------------------------------------------------------------------------------- *
* | fc_mxcsr|fc_x87_cw| EDI | ESI | EBX | EBP | EIP | hidden | *
* ---------------------------------------------------------------------------------- *
* ---------------------------------------------------------------------------------- *
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
* ---------------------------------------------------------------------------------- *
* | 0x20 | 0x24 | | *
* ---------------------------------------------------------------------------------- *
* | to | data | | *
* ---------------------------------------------------------------------------------- *
* *
****************************************************************************************/
.text
.globl _jump_fcontext
.align 2
_jump_fcontext:
leal -0x18(%esp), %esp /* prepare stack */
stmxcsr (%esp) /* save MMX control- and status-word */
fnstcw 0x4(%esp) /* save x87 control-word */
movl %edi, 0x8(%esp) /* save EDI */
movl %esi, 0xc(%esp) /* save ESI */
movl %ebx, 0x10(%esp) /* save EBX */
movl %ebp, 0x14(%esp) /* save EBP */
/* store ESP (pointing to context-data) in ECX */
movl %esp, %ecx
/* first arg of jump_fcontext() == fcontext to jump to */
movl 0x20(%esp), %eax
/* second arg of jump_fcontext() == data to be transferred */
movl 0x24(%esp), %edx
/* restore ESP (pointing to context-data) from EAX */
movl %eax, %esp
/* address of returned transport_t */
movl 0x1c(%esp), %eax
/* return parent fcontext_t */
movl %ecx, (%eax)
/* return data */
movl %edx, 0x4(%eax)
movl 0x18(%esp), %ecx /* restore EIP */
ldmxcsr (%esp) /* restore MMX control- and status-word */
fldcw 0x4(%esp) /* restore x87 control-word */
movl 0x8(%esp), %edi /* restore EDI */
movl 0xc(%esp), %esi /* restore ESI */
movl 0x10(%esp), %ebx /* restore EBX */
movl 0x14(%esp), %ebp /* restore EBP */
leal 0x20(%esp), %esp /* prepare stack */
/* jump to context */
jmp *%ecx
|
whupdup/frame
|
real/third_party/boost_context/asm/not_modified_yet/jump_i386_sysv_macho_gas.S
|
Assembly
|
gpl-3.0
| 3,185
|
/*
Copyright Sergue E. Leontiev 2013.
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)
*/
// Stub file for universal binary
#if defined(__i386__)
#include "jump_i386_sysv_macho_gas.S"
#elif defined(__x86_64__)
#include "jump_x86_64_sysv_macho_gas.S"
#else
#error "No arch's"
#endif
|
whupdup/frame
|
real/third_party/boost_context/asm/not_modified_yet/jump_i386_x86_64_sysv_macho_gas.S
|
Assembly
|
gpl-3.0
| 425
|
/*
Copyright Oliver Kowalke 2009.
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)
*/
/*******************************************************
* *
* ------------------------------------------------- *
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | *
* ------------------------------------------------- *
* | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | *
* ------------------------------------------------- *
* | F20 | F22 | F24 | F26 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
* ------------------------------------------------- *
* | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | *
* ------------------------------------------------- *
* | F28 | F30 | S0 | S1 | S2 | S3 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | *
* ------------------------------------------------- *
* | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | *
* ------------------------------------------------- *
* | S4 | S5 | S6 | S7 | FP |hiddn| RA | PC | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | *
* ------------------------------------------------- *
* | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | *
* ------------------------------------------------- *
* | GP | FCTX| DATA| | | | | | *
* ------------------------------------------------- *
* *
* *****************************************************/
.text
.globl jump_fcontext
.align 2
.type jump_fcontext,@function
.ent jump_fcontext
jump_fcontext:
# reserve space on stack
addiu $sp, $sp, -112
sw $s0, 48($sp) # save S0
sw $s1, 52($sp) # save S1
sw $s2, 56($sp) # save S2
sw $s3, 60($sp) # save S3
sw $s4, 64($sp) # save S4
sw $s5, 68($sp) # save S5
sw $s6, 72($sp) # save S6
sw $s7, 76($sp) # save S7
sw $fp, 80($sp) # save FP
sw $a0, 84($sp) # save hidden, address of returned transfer_t
sw $ra, 88($sp) # save RA
sw $ra, 92($sp) # save RA as PC
#if defined(__mips_hard_float)
s.d $f20, ($sp) # save F20
s.d $f22, 8($sp) # save F22
s.d $f24, 16($sp) # save F24
s.d $f26, 24($sp) # save F26
s.d $f28, 32($sp) # save F28
s.d $f30, 40($sp) # save F30
#endif
# store SP (pointing to context-data) in A0
move $a0, $sp
# restore SP (pointing to context-data) from A1
move $sp, $a1
#if defined(__mips_hard_float)
l.d $f20, ($sp) # restore F20
l.d $f22, 8($sp) # restore F22
l.d $f24, 16($sp) # restore F24
l.d $f26, 24($sp) # restore F26
l.d $f28, 32($sp) # restore F28
l.d $f30, 40($sp) # restore F30
#endif
lw $s0, 48($sp) # restore S0
lw $s1, 52($sp) # restore S1
lw $s2, 56($sp) # restore S2
lw $s3, 60($sp) # restore S3
lw $s4, 64($sp) # restore S4
lw $s5, 68($sp) # restore S5
lw $s6, 72($sp) # restore S6
lw $s7, 76($sp) # restore S7
lw $fp, 80($sp) # restore FP
lw $t0, 84($sp) # restore hidden, address of returned transfer_t
lw $ra, 88($sp) # restore RA
# load PC
lw $t9, 92($sp)
# adjust stack
addiu $sp, $sp, 112
# return transfer_t from jump
sw $a0, ($t0) # fctx of transfer_t
sw $a2, 4($t0) # data of transfer_t
# pass transfer_t as first arg in context function
# A0 == fctx, A1 == data
move $a1, $a2
# jump to context
jr $t9
.end jump_fcontext
.size jump_fcontext, .-jump_fcontext
/* Mark that we don't need executable stack. */
.section .note.GNU-stack,"",%progbits
|
whupdup/frame
|
real/third_party/boost_context/asm/not_modified_yet/jump_mips32_o32_elf_gas.S
|
Assembly
|
gpl-3.0
| 4,179
|
/*
Copyright Sergue E. Leontiev 2013.
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)
*/
// Stub file for universal binary
#if defined(__ppc__)
#include "jump_ppc32_sysv_macho_gas.S"
#elif defined(__ppc64__)
#include "jump_ppc64_sysv_macho_gas.S"
#else
#error "No arch's"
#endif
|
whupdup/frame
|
real/third_party/boost_context/asm/not_modified_yet/jump_ppc32_ppc64_sysv_macho_gas.S
|
Assembly
|
gpl-3.0
| 423
|
/*
Copyright Oliver Kowalke 2009.
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)
*/
/******************************************************
* *
* ------------------------------------------------- *
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | *
* ------------------------------------------------- *
* | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | *
* ------------------------------------------------- *
* | F14 | F15 | F16 | F17 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
* ------------------------------------------------- *
* | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | *
* ------------------------------------------------- *
* | F18 | F19 | F20 | F21 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | *
* ------------------------------------------------- *
* | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | *
* ------------------------------------------------- *
* | F22 | F23 | F24 | F25 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | *
* ------------------------------------------------- *
* | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | *
* ------------------------------------------------- *
* | F26 | F27 | F28 | F29 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | *
* ------------------------------------------------- *
* | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | *
* ------------------------------------------------- *
* | F30 | F31 | fpscr | R13 | R14 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | *
* ------------------------------------------------- *
* | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | *
* ------------------------------------------------- *
* | R15 | R16 | R17 | R18 | R19 | R20 | R21 | R22 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | *
* ------------------------------------------------- *
* | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | *
* ------------------------------------------------- *
* | R23 | R24 | R25 | R26 | R27 | R28 | R29 | R30 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | *
* ------------------------------------------------- *
* | 224 | 228 | 232 | 236 | 240 | 244 | 248 | 252 | *
* ------------------------------------------------- *
* | R31 |hiddn| CR | LR | PC |bchai|linkr| FCTX| *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 64 | | *
* ------------------------------------------------- *
* | 256 | | *
* ------------------------------------------------- *
* | DATA| | *
* ------------------------------------------------- *
* *
*******************************************************/
.text
.globl jump_fcontext
.align 2
.type jump_fcontext,@function
jump_fcontext:
# reserve space on stack
subi %r1, %r1, 244
stfd %f14, 0(%r1) # save F14
stfd %f15, 8(%r1) # save F15
stfd %f16, 16(%r1) # save F16
stfd %f17, 24(%r1) # save F17
stfd %f18, 32(%r1) # save F18
stfd %f19, 40(%r1) # save F19
stfd %f20, 48(%r1) # save F20
stfd %f21, 56(%r1) # save F21
stfd %f22, 64(%r1) # save F22
stfd %f23, 72(%r1) # save F23
stfd %f24, 80(%r1) # save F24
stfd %f25, 88(%r1) # save F25
stfd %f26, 96(%r1) # save F26
stfd %f27, 104(%r1) # save F27
stfd %f28, 112(%r1) # save F28
stfd %f29, 120(%r1) # save F29
stfd %f30, 128(%r1) # save F30
stfd %f31, 136(%r1) # save F31
mffs %f0 # load FPSCR
stfd %f0, 144(%r1) # save FPSCR
stw %r13, 152(%r1) # save R13
stw %r14, 156(%r1) # save R14
stw %r15, 160(%r1) # save R15
stw %r16, 164(%r1) # save R16
stw %r17, 168(%r1) # save R17
stw %r18, 172(%r1) # save R18
stw %r19, 176(%r1) # save R19
stw %r20, 180(%r1) # save R20
stw %r21, 184(%r1) # save R21
stw %r22, 188(%r1) # save R22
stw %r23, 192(%r1) # save R23
stw %r24, 196(%r1) # save R24
stw %r25, 200(%r1) # save R25
stw %r26, 204(%r1) # save R26
stw %r27, 208(%r1) # save R27
stw %r28, 212(%r1) # save R28
stw %r29, 216(%r1) # save R29
stw %r30, 220(%r1) # save R30
stw %r31, 224(%r1) # save R31
stw %r3, 228(%r1) # save hidden
# save CR
mfcr %r0
stw %r0, 232(%r1)
# save LR
mflr %r0
stw %r0, 236(%r1)
# save LR as PC
stw %r0, 240(%r1)
# store RSP (pointing to context-data) in R6
mr %r6, %r1
# restore RSP (pointing to context-data) from R4
mr %r1, %r4
lfd %f14, 0(%r1) # restore F14
lfd %f15, 8(%r1) # restore F15
lfd %f16, 16(%r1) # restore F16
lfd %f17, 24(%r1) # restore F17
lfd %f18, 32(%r1) # restore F18
lfd %f19, 40(%r1) # restore F19
lfd %f20, 48(%r1) # restore F20
lfd %f21, 56(%r1) # restore F21
lfd %f22, 64(%r1) # restore F22
lfd %f23, 72(%r1) # restore F23
lfd %f24, 80(%r1) # restore F24
lfd %f25, 88(%r1) # restore F25
lfd %f26, 96(%r1) # restore F26
lfd %f27, 104(%r1) # restore F27
lfd %f28, 112(%r1) # restore F28
lfd %f29, 120(%r1) # restore F29
lfd %f30, 128(%r1) # restore F30
lfd %f31, 136(%r1) # restore F31
lfd %f0, 144(%r1) # load FPSCR
mtfsf 0xff, %f0 # restore FPSCR
lwz %r13, 152(%r1) # restore R13
lwz %r14, 156(%r1) # restore R14
lwz %r15, 160(%r1) # restore R15
lwz %r16, 164(%r1) # restore R16
lwz %r17, 168(%r1) # restore R17
lwz %r18, 172(%r1) # restore R18
lwz %r19, 176(%r1) # restore R19
lwz %r20, 180(%r1) # restore R20
lwz %r21, 184(%r1) # restore R21
lwz %r22, 188(%r1) # restore R22
lwz %r23, 192(%r1) # restore R23
lwz %r24, 196(%r1) # restore R24
lwz %r25, 200(%r1) # restore R25
lwz %r26, 204(%r1) # restore R26
lwz %r27, 208(%r1) # restore R27
lwz %r28, 212(%r1) # restore R28
lwz %r29, 216(%r1) # restore R29
lwz %r30, 220(%r1) # restore R30
lwz %r31, 224(%r1) # restore R31
lwz %r3, 228(%r1) # restore hidden
# restore CR
lwz %r0, 232(%r1)
mtcr %r0
# restore LR
lwz %r0, 236(%r1)
mtlr %r0
# load PC
lwz %r0, 240(%r1)
# restore CTR
mtctr %r0
# adjust stack
addi %r1, %r1, 244
# return transfer_t
stw %r6, 0(%r3)
stw %r5, 4(%r3)
# jump to context
bctr
.size jump_fcontext, .-jump_fcontext
/* Mark that we don't need executable stack. */
.section .note.GNU-stack,"",%progbits
|
whupdup/frame
|
real/third_party/boost_context/asm/not_modified_yet/jump_ppc32_sysv_elf_gas.S
|
Assembly
|
gpl-3.0
| 7,898
|
/*
Copyright Oliver Kowalke 2009.
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)
*/
/******************************************************
* *
* ------------------------------------------------- *
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | *
* ------------------------------------------------- *
* | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | *
* ------------------------------------------------- *
* | F14 | F15 | F16 | F17 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
* ------------------------------------------------- *
* | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | *
* ------------------------------------------------- *
* | F18 | F19 | F20 | F21 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | *
* ------------------------------------------------- *
* | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | *
* ------------------------------------------------- *
* | F22 | F23 | F24 | F25 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | *
* ------------------------------------------------- *
* | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | *
* ------------------------------------------------- *
* | F26 | F27 | F28 | F29 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | *
* ------------------------------------------------- *
* | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | *
* ------------------------------------------------- *
* | F30 | F31 | fpscr | R13 | R14 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | *
* ------------------------------------------------- *
* | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | *
* ------------------------------------------------- *
* | R15 | R16 | R17 | R18 | R19 | R20 | R21 | R22 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | *
* ------------------------------------------------- *
* | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | *
* ------------------------------------------------- *
* | R23 | R24 | R25 | R26 | R27 | R28 | R29 | R30 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | *
* ------------------------------------------------- *
* | 224 | 228 | 232 | 236 | 240 | 244 | 248 | 252 | *
* ------------------------------------------------- *
* | R31 |hiddn| CR | LR | PC |bchai|linkr| FCTX| *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 64 | | *
* ------------------------------------------------- *
* | 256 | | *
* ------------------------------------------------- *
* | DATA| | *
* ------------------------------------------------- *
* *
*******************************************************/
.text
.globl _jump_fcontext
.align 2
_jump_fcontext:
; reserve space on stack
subi r1, r1, 244
stfd f14, 0(r1) # save F14
stfd f15, 8(r1) # save F15
stfd f16, 16(r1) # save F16
stfd f17, 24(r1) # save F17
stfd f18, 32(r1) # save F18
stfd f19, 40(r1) # save F19
stfd f20, 48(r1) # save F20
stfd f21, 56(r1) # save F21
stfd f22, 64(r1) # save F22
stfd f23, 72(r1) # save F23
stfd f24, 80(r1) # save F24
stfd f25, 88(r1) # save F25
stfd f26, 96(r1) # save F26
stfd f27, 104(r1) # save F27
stfd f28, 112(r1) # save F28
stfd f29, 120(r1) # save F29
stfd f30, 128(r1) # save F30
stfd f31, 136(r1) # save F31
mffs f0 # load FPSCR
stfd f0, 144(r1) # save FPSCR
stw r13, 152(r1) # save R13
stw r14, 156(r1) # save R14
stw r15, 160(r1) # save R15
stw r16, 164(r1) # save R16
stw r17, 168(r1) # save R17
stw r18, 172(r1) # save R18
stw r19, 176(r1) # save R19
stw r20, 180(r1) # save R20
stw r21, 184(r1) # save R21
stw r22, 188(r1) # save R22
stw r23, 192(r1) # save R23
stw r24, 196(r1) # save R24
stw r25, 200(r1) # save R25
stw r26, 204(r1) # save R26
stw r27, 208(r1) # save R27
stw r28, 212(r1) # save R28
stw r29, 216(r1) # save R29
stw r30, 220(r1) # save R30
stw r31, 224(r1) # save R31
stw r3, 228(r1) # save hidden
# save CR
mfcr r0
stw r0, 232(r1)
# save LR
mflr r0
stw r0, 236(r1)
# save LR as PC
stw r0, 240(r1)
# store RSP (pointing to context-data) in R6
mr r6, r1
# restore RSP (pointing to context-data) from R4
mr r1, r4
lfd f14, 0(r1) # restore F14
lfd f15, 8(r1) # restore F15
lfd f16, 16(r1) # restore F16
lfd f17, 24(r1) # restore F17
lfd f18, 32(r1) # restore F18
lfd f19, 40(r1) # restore F19
lfd f20, 48(r1) # restore F20
lfd f21, 56(r1) # restore F21
lfd f22, 64(r1) # restore F22
lfd f23, 72(r1) # restore F23
lfd f24, 80(r1) # restore F24
lfd f25, 88(r1) # restore F25
lfd f26, 96(r1) # restore F26
lfd f27, 104(r1) # restore F27
lfd f28, 112(r1) # restore F28
lfd f29, 120(r1) # restore F29
lfd f30, 128(r1) # restore F30
lfd f31, 136(r1) # restore F31
lfd f0, 144(r1) # load FPSCR
mtfsf 0xff, f0 # restore FPSCR
lwz r13, 152(r1) # restore R13
lwz r14, 156(r1) # restore R14
lwz r15, 160(r1) # restore R15
lwz r16, 164(r1) # restore R16
lwz r17, 168(r1) # restore R17
lwz r18, 172(r1) # restore R18
lwz r19, 176(r1) # restore R19
lwz r20, 180(r1) # restore R20
lwz r21, 184(r1) # restore R21
lwz r22, 188(r1) # restore R22
lwz r23, 192(r1) # restore R23
lwz r24, 196(r1) # restore R24
lwz r25, 200(r1) # restore R25
lwz r26, 204(r1) # restore R26
lwz r27, 208(r1) # restore R27
lwz r28, 212(r1) # restore R28
lwz r29, 216(r1) # restore R29
lwz r30, 220(r1) # restore R30
lwz r31, 224(r1) # restore R31
lwz r3, 228(r1) # restore hidden
# restore CR
lwz r0, 232(r1)
mtcr r0
# restore LR
lwz r0, 236(r1)
mtlr r0
# load PC
lwz r0, 240(r1)
# restore CTR
mtctr r0
# adjust stack
addi r1, r1, 244
# return transfer_t
stw r6, 0(r3)
stw r5, 4(r3)
# jump to context
bctr
|
whupdup/frame
|
real/third_party/boost_context/asm/not_modified_yet/jump_ppc32_sysv_macho_gas.S
|
Assembly
|
gpl-3.0
| 7,558
|
/*
Copyright Oliver Kowalke 2009.
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)
*/
/******************************************************
* *
* ------------------------------------------------- *
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | *
* ------------------------------------------------- *
* | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | *
* ------------------------------------------------- *
* | F14 | F15 | F16 | F17 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
* ------------------------------------------------- *
* | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | *
* ------------------------------------------------- *
* | F18 | F19 | F20 | F21 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | *
* ------------------------------------------------- *
* | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | *
* ------------------------------------------------- *
* | F22 | F23 | F24 | F25 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | *
* ------------------------------------------------- *
* | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | *
* ------------------------------------------------- *
* | F26 | F27 | F28 | F29 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | *
* ------------------------------------------------- *
* | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | *
* ------------------------------------------------- *
* | F30 | F31 | fpscr | R13 | R14 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | *
* ------------------------------------------------- *
* | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | *
* ------------------------------------------------- *
* | R15 | R16 | R17 | R18 | R19 | R20 | R21 | R22 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | *
* ------------------------------------------------- *
* | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | *
* ------------------------------------------------- *
* | R23 | R24 | R25 | R26 | R27 | R28 | R29 | R30 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | *
* ------------------------------------------------- *
* | 224 | 228 | 232 | 236 | 240 | 244 | 248 | 252 | *
* ------------------------------------------------- *
* | R31 |hiddn| CR | LR | PC |bchai|linkr| FCTX| *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 64 | | *
* ------------------------------------------------- *
* | 256 | | *
* ------------------------------------------------- *
* | DATA| | *
* ------------------------------------------------- *
* *
*******************************************************/
.globl .jump_fcontext
.globl jump_fcontext[DS]
.align 2
.csect jump_fcontext[DS]
jump_fcontext:
.long .jump_fcontext
.jump_fcontext:
# reserve space on stack
subi r1, r1, 244
stfd f14, 0(r1) # save F14
stfd f15, 8(r1) # save F15
stfd f16, 16(r1) # save F16
stfd f17, 24(r1) # save F17
stfd f18, 32(r1) # save F18
stfd f19, 40(r1) # save F19
stfd f20, 48(r1) # save F20
stfd f21, 56(r1) # save F21
stfd f22, 64(r1) # save F22
stfd f23, 72(r1) # save F23
stfd f24, 80(r1) # save F24
stfd f25, 88(r1) # save F25
stfd f26, 96(r1) # save F26
stfd f27, 104(r1) # save F27
stfd f28, 112(r1) # save F28
stfd f29, 120(r1) # save F29
stfd f30, 128(r1) # save F30
stfd f31, 136(r1) # save F31
mffs f0 # load FPSCR
stfd f0, 144(r1) # save FPSCR
stw r13, 152(r1) # save R13
stw r14, 156(r1) # save R14
stw r15, 160(r1) # save R15
stw r16, 164(r1) # save R16
stw r17, 168(r1) # save R17
stw r18, 172(r1) # save R18
stw r19, 176(r1) # save R19
stw r20, 180(r1) # save R20
stw r21, 184(r1) # save R21
stw r22, 188(r1) # save R22
stw r23, 192(r1) # save R23
stw r24, 196(r1) # save R24
stw r25, 200(r1) # save R25
stw r26, 204(r1) # save R26
stw r27, 208(r1) # save R27
stw r28, 212(r1) # save R28
stw r29, 216(r1) # save R29
stw r30, 220(r1) # save R30
stw r31, 224(r1) # save R31
stw r3, 228(r1) # save hidden
# save CR
mfcr r0
stw r0, 232(r1)
# save LR
mflr r0
stw r0, 236(r1)
# save LR as PC
stw r0, 240(r1)
# store RSP (pointing to context-data) in R6
mr r6, r1
# restore RSP (pointing to context-data) from R4
mr r1, r4
lfd f14, 0(r1) # restore F14
lfd f15, 8(r1) # restore F15
lfd f16, 16(r1) # restore F16
lfd f17, 24(r1) # restore F17
lfd f18, 32(r1) # restore F18
lfd f19, 40(r1) # restore F19
lfd f20, 48(r1) # restore F20
lfd f21, 56(r1) # restore F21
lfd f22, 64(r1) # restore F22
lfd f23, 72(r1) # restore F23
lfd f24, 80(r1) # restore F24
lfd f25, 88(r1) # restore F25
lfd f26, 96(r1) # restore F26
lfd f27, 104(r1) # restore F27
lfd f28, 112(r1) # restore F28
lfd f29, 120(r1) # restore F29
lfd f30, 128(r1) # restore F30
lfd f31, 136(r1) # restore F31
lfd f0, 144(r1) # load FPSCR
mtfsf 0xff, f0 # restore FPSCR
lwz r13, 152(r1) # restore R13
lwz r14, 156(r1) # restore R14
lwz r15, 160(r1) # restore R15
lwz r16, 164(r1) # restore R16
lwz r17, 168(r1) # restore R17
lwz r18, 172(r1) # restore R18
lwz r19, 176(r1) # restore R19
lwz r20, 180(r1) # restore R20
lwz r21, 184(r1) # restore R21
lwz r22, 188(r1) # restore R22
lwz r23, 192(r1) # restore R23
lwz r24, 196(r1) # restore R24
lwz r25, 200(r1) # restore R25
lwz r26, 204(r1) # restore R26
lwz r27, 208(r1) # restore R27
lwz r28, 212(r1) # restore R28
lwz r29, 216(r1) # restore R29
lwz r30, 220(r1) # restore R30
lwz r31, 224(r1) # restore R31
lwz r3, 228(r1) # restore hidden
# restore CR
lwz r0, 232(r1)
mtcr r0
# restore LR
lwz r0, 236(r1)
mtlr r0
# load PC
lwz r0, 240(r1)
# restore CTR
mtctr r0
# adjust stack
addi r1, r1, 244
# return transfer_t
stw r6, 0(r3)
stw r5, 4(r3)
# jump to context
bctr
|
whupdup/frame
|
real/third_party/boost_context/asm/not_modified_yet/jump_ppc32_sysv_xcoff_gas.S
|
Assembly
|
gpl-3.0
| 7,641
|
/*
Copyright Oliver Kowalke 2009.
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)
*/
/*******************************************************
* *
* ------------------------------------------------- *
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | *
* ------------------------------------------------- *
* | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | *
* ------------------------------------------------- *
* | TOC | R14 | R15 | R16 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
* ------------------------------------------------- *
* | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | *
* ------------------------------------------------- *
* | R17 | R18 | R19 | R20 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | *
* ------------------------------------------------- *
* | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | *
* ------------------------------------------------- *
* | R21 | R22 | R23 | R24 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | *
* ------------------------------------------------- *
* | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | *
* ------------------------------------------------- *
* | R25 | R26 | R27 | R28 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | *
* ------------------------------------------------- *
* | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | *
* ------------------------------------------------- *
* | R29 | R30 | R31 | hidden | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | *
* ------------------------------------------------- *
* | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | *
* ------------------------------------------------- *
* | CR | LR | PC | back-chain| *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | *
* ------------------------------------------------- *
* | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | *
* ------------------------------------------------- *
* | cr saved | lr saved | compiler | linker | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | *
* ------------------------------------------------- *
* | 224 | 228 | 232 | 236 | 240 | 244 | 248 | 252 | *
* ------------------------------------------------- *
* | TOC saved | FCTX | DATA | | *
* ------------------------------------------------- *
* *
*******************************************************/
.globl jump_fcontext
#if _CALL_ELF == 2
.text
.align 2
jump_fcontext:
addis %r2, %r12, .TOC.-jump_fcontext@ha
addi %r2, %r2, .TOC.-jump_fcontext@l
.localentry jump_fcontext, . - jump_fcontext
#else
.section ".opd","aw"
.align 3
jump_fcontext:
# ifdef _CALL_LINUX
.quad .L.jump_fcontext,.TOC.@tocbase,0
.type jump_fcontext,@function
.text
.align 2
.L.jump_fcontext:
# else
.hidden .jump_fcontext
.globl .jump_fcontext
.quad .jump_fcontext,.TOC.@tocbase,0
.size jump_fcontext,24
.type .jump_fcontext,@function
.text
.align 2
.jump_fcontext:
# endif
#endif
# reserve space on stack
subi %r1, %r1, 184
#if _CALL_ELF != 2
std %r2, 0(%r1) # save TOC
#endif
std %r14, 8(%r1) # save R14
std %r15, 16(%r1) # save R15
std %r16, 24(%r1) # save R16
std %r17, 32(%r1) # save R17
std %r18, 40(%r1) # save R18
std %r19, 48(%r1) # save R19
std %r20, 56(%r1) # save R20
std %r21, 64(%r1) # save R21
std %r22, 72(%r1) # save R22
std %r23, 80(%r1) # save R23
std %r24, 88(%r1) # save R24
std %r25, 96(%r1) # save R25
std %r26, 104(%r1) # save R26
std %r27, 112(%r1) # save R27
std %r29, 120(%r1) # save R28
std %r29, 128(%r1) # save R29
std %r30, 136(%r1) # save R30
std %r31, 144(%r1) # save R31
std %r3, 152(%r1) # save hidden
# save CR
mfcr %r0
std %r0, 160(%r1)
# save LR
mflr %r0
std %r0, 168(%r1)
# save LR as PC
std %r0, 176(%r1)
# store RSP (pointing to context-data) in R6
mr %r6, %r1
# restore RSP (pointing to context-data) from R4
mr %r1, %r4
#if _CALL_ELF != 2
ld %r2, 0(%r1) # restore TOC
#endif
ld %r14, 8(%r1) # restore R14
ld %r15, 16(%r1) # restore R15
ld %r16, 24(%r1) # restore R16
ld %r17, 32(%r1) # restore R17
ld %r18, 40(%r1) # restore R18
ld %r19, 48(%r1) # restore R19
ld %r20, 56(%r1) # restore R20
ld %r21, 64(%r1) # restore R21
ld %r22, 72(%r1) # restore R22
ld %r23, 80(%r1) # restore R23
ld %r24, 88(%r1) # restore R24
ld %r25, 96(%r1) # restore R25
ld %r26, 104(%r1) # restore R26
ld %r27, 112(%r1) # restore R27
ld %r28, 120(%r1) # restore R28
ld %r29, 128(%r1) # restore R29
ld %r30, 136(%r1) # restore R30
ld %r31, 144(%r1) # restore R31
ld %r3, 152(%r1) # restore hidden
# restore CR
ld %r0, 160(%r1)
mtcr %r0
# restore LR
ld %r0, 168(%r1)
mtlr %r0
# load PC
ld %r12, 176(%r1)
# restore CTR
mtctr %r12
# adjust stack
addi %r1, %r1, 184
# return transfer_t
std %r6, 0(%r3)
std %r5, 8(%r3)
# jump to context
bctr
#if _CALL_ELF == 2
.size jump_fcontext, .-jump_fcontext
#else
# ifdef _CALL_LINUX
.size .jump_fcontext, .-.L.jump_fcontext
# else
.size .jump_fcontext, .-.jump_fcontext
# endif
#endif
/* Mark that we don't need executable stack. */
.section .note.GNU-stack,"",%progbits
|
whupdup/frame
|
real/third_party/boost_context/asm/not_modified_yet/jump_ppc64_sysv_elf_gas.S
|
Assembly
|
gpl-3.0
| 6,772
|
/*
Copyright Oliver Kowalke 2009.
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)
*/
/*******************************************************
* *
* ------------------------------------------------- *
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | *
* ------------------------------------------------- *
* | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | *
* ------------------------------------------------- *
* | TOC | R14 | R15 | R16 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
* ------------------------------------------------- *
* | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | *
* ------------------------------------------------- *
* | R17 | R18 | R19 | R20 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | *
* ------------------------------------------------- *
* | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | *
* ------------------------------------------------- *
* | R21 | R22 | R23 | R24 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | *
* ------------------------------------------------- *
* | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | *
* ------------------------------------------------- *
* | R25 | R26 | R27 | R28 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | *
* ------------------------------------------------- *
* | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | *
* ------------------------------------------------- *
* | R29 | R30 | R31 | hidden | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | *
* ------------------------------------------------- *
* | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | *
* ------------------------------------------------- *
* | CR | LR | PC | back-chain| *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | *
* ------------------------------------------------- *
* | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | *
* ------------------------------------------------- *
* | cr saved | lr saved | compiler | linker | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | *
* ------------------------------------------------- *
* | 224 | 228 | 232 | 236 | 240 | 244 | 248 | 252 | *
* ------------------------------------------------- *
* | TOC saved | FCTX | DATA | | *
* ------------------------------------------------- *
* *
*******************************************************/
.text
.align 2
.globl jump_fcontext
_jump_fcontext:
; reserve space on stack
subi r1, r1, 184
std %r14, 8(%r1) ; save R14
std %r15, 16(%r1) ; save R15
std %r16, 24(%r1) ; save R16
std %r17, 32(%r1) ; save R17
std %r18, 40(%r1) ; save R18
std %r19, 48(%r1) ; save R19
std %r20, 56(%r1) ; save R20
std %r21, 64(%r1) ; save R21
std %r22, 72(%r1) ; save R22
std %r23, 80(%r1) ; save R23
std %r24, 88(%r1) ; save R24
std %r25, 96(%r1) ; save R25
std %r26, 104(%r1) ; save R26
std %r27, 112(%r1) ; save R27
std %r29, 120(%r1) ; save R28
std %r29, 128(%r1) ; save R29
std %r30, 136(%r1) ; save R30
std %r31, 144(%r1) ; save R31
std %r3, 152(%r1) ; save hidden
; save CR
mfcr r0
std r0, 160(r1)
; save LR
mflr r0
std r0, 168(r1)
; save LR as PC
std r0, 176(r1)
; store RSP (pointing to context-data) in R6
mr %r6, %r1
; restore RSP (pointing to context-data) from R4
mr r1, r4
ld %r14, 8(%r1) ; restore R14
ld %r15, 16(%r1) ; restore R15
ld %r16, 24(%r1) ; restore R16
ld %r17, 32(%r1) ; restore R17
ld %r18, 40(%r1) ; restore R18
ld %r19, 48(%r1) ; restore R19
ld %r20, 56(%r1) ; restore R20
ld %r21, 64(%r1) ; restore R21
ld %r22, 72(%r1) ; restore R22
ld %r23, 80(%r1) ; restore R23
ld %r24, 88(%r1) ; restore R24
ld %r25, 96(%r1) ; restore R25
ld %r26, 104(%r1) ; restore R26
ld %r27, 112(%r1) ; restore R27
ld %r28, 120(%r1) ; restore R28
ld %r29, 128(%r1) ; restore R29
ld %r30, 136(%r1) ; restore R30
ld %r31, 144(%r1) ; restore R31
ld %r3, 152(%r1) ; restore hidden
; restore CR
ld r0, 160(r1)
mtcr r0
; restore LR
ld r0, 168(r1)
mtlr r0
; load PC
ld r0, 176(r1)
; restore CTR
mtctr r0
; adjust stack
addi r1, r1, 184
; return transfer_t
std %r6, 0(%r3)
std %r5, 8(%r3)
; jump to context
bctr
|
whupdup/frame
|
real/third_party/boost_context/asm/not_modified_yet/jump_ppc64_sysv_macho_gas.S
|
Assembly
|
gpl-3.0
| 5,713
|
.align 2
.globl .jump_fcontext
.jump_fcontext:
# reserve space on stack
subi 1, 1, 184
std 13, 0(1) # save R13
std 14, 8(1) # save R14
std 15, 16(1) # save R15
std 16, 24(1) # save R16
std 17, 32(1) # save R17
std 18, 40(1) # save R18
std 19, 48(1) # save R19
std 20, 56(1) # save R20
std 21, 64(1) # save R21
std 22, 72(1) # save R22
std 23, 80(1) # save R23
std 24, 88(1) # save R24
std 25, 96(1) # save R25
std 26, 104(1) # save R26
std 27, 112(1) # save R27
std 29, 120(1) # save R28
std 29, 128(1) # save R29
std 30, 136(1) # save R30
std 31, 144(1) # save R31
std 3, 152(1) # save hidden
# save CR
mfcr 0
std 0, 160(1)
# save LR
mflr 0
std 0, 168(1)
# save LR as PC
std 0, 176(1)
# store RSP (pointing to context-data) in R6
mr 6, 1
# restore RSP (pointing to context-data) from R4
mr 1, 4
ld 13, 0(1) # restore R13
ld 14, 8(1) # restore R14
ld 15, 16(1) # restore R15
ld 16, 24(1) # restore R16
ld 17, 32(1) # restore R17
ld 18, 40(1) # restore R18
ld 19, 48(1) # restore R19
ld 20, 56(1) # restore R20
ld 21, 64(1) # restore R21
ld 22, 72(1) # restore R22
ld 23, 80(1) # restore R23
ld 24, 88(1) # restore R24
ld 25, 96(1) # restore R25
ld 26, 104(1) # restore R26
ld 27, 112(1) # restore R27
ld 28, 120(1) # restore R28
ld 29, 128(1) # restore R29
ld 30, 136(1) # restore R30
ld 31, 144(1) # restore R31
ld 3, 152(1) # restore hidden
# restore CR
ld 0, 160(1)
mtcr 0
# restore LR
ld 0, 168(1)
mtlr 0
# load PC
ld 0, 176(1)
# restore CTR
mtctr 0
# adjust stack
addi 1, 1, 184
# return transfer_t
std 6, 0(3)
std 5, 8(3)
# jump to context
bctr
|
whupdup/frame
|
real/third_party/boost_context/asm/not_modified_yet/jump_ppc64_sysv_xcoff_gas.S
|
Assembly
|
gpl-3.0
| 1,944
|
/*
Copyright Oliver Kowalke 2009.
Copyright Thomas Sailer 2013.
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)
*/
/*************************************************************************************
* ---------------------------------------------------------------------------------- *
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | *
* ---------------------------------------------------------------------------------- *
* | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | *
* ---------------------------------------------------------------------------------- *
* | SEE registers (XMM6-XMM15) | *
* ---------------------------------------------------------------------------------- *
* ---------------------------------------------------------------------------------- *
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
* ---------------------------------------------------------------------------------- *
* | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | *
* ---------------------------------------------------------------------------------- *
* | SEE registers (XMM6-XMM15) | *
* ---------------------------------------------------------------------------------- *
* ---------------------------------------------------------------------------------- *
* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | *
* ---------------------------------------------------------------------------------- *
* | 0xe40 | 0x44 | 0x48 | 0x4c | 0x50 | 0x54 | 0x58 | 0x5c | *
* ---------------------------------------------------------------------------------- *
* | SEE registers (XMM6-XMM15) | *
* ---------------------------------------------------------------------------------- *
* ---------------------------------------------------------------------------------- *
* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | *
* ---------------------------------------------------------------------------------- *
* | 0x60 | 0x64 | 0x68 | 0x6c | 0x70 | 0x74 | 0x78 | 0x7c | *
* ---------------------------------------------------------------------------------- *
* | SEE registers (XMM6-XMM15) | *
* ---------------------------------------------------------------------------------- *
* ---------------------------------------------------------------------------------- *
* | 32 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | *
* ---------------------------------------------------------------------------------- *
* | 0x80 | 0x84 | 0x88 | 0x8c | 0x90 | 0x94 | 0x98 | 0x9c | *
* ---------------------------------------------------------------------------------- *
* | SEE registers (XMM6-XMM15) | *
* ---------------------------------------------------------------------------------- *
* ---------------------------------------------------------------------------------- *
* | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | *
* ---------------------------------------------------------------------------------- *
* | 0xa0 | 0xa4 | 0xa8 | 0xac | 0xb0 | 0xb4 | 0xb8 | 0xbc | *
* ---------------------------------------------------------------------------------- *
* | fc_mxcsr|fc_x87_cw| <alignment> | fbr_strg | fc_dealloc | *
* ---------------------------------------------------------------------------------- *
* ---------------------------------------------------------------------------------- *
* | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | *
* ---------------------------------------------------------------------------------- *
* | 0xc0 | 0xc4 | 0xc8 | 0xcc | 0xd0 | 0xd4 | 0xd8 | 0xdc | *
* ---------------------------------------------------------------------------------- *
* | limit | base | R12 | R13 | *
* ---------------------------------------------------------------------------------- *
* ---------------------------------------------------------------------------------- *
* | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | *
* ---------------------------------------------------------------------------------- *
* | 0xe0 | 0xe4 | 0xe8 | 0xec | 0xf0 | 0xf4 | 0xf8 | 0xfc | *
* ---------------------------------------------------------------------------------- *
* | R14 | R15 | RDI | RSI | *
* ---------------------------------------------------------------------------------- *
* ---------------------------------------------------------------------------------- *
* | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | *
* ---------------------------------------------------------------------------------- *
* | 0x100 | 0x104 | 0x108 | 0x10c | 0x110 | 0x114 | 0x118 | 0x11c | *
* ---------------------------------------------------------------------------------- *
* | RBX | RBP | hidden | RIP | *
* ---------------------------------------------------------------------------------- *
* ---------------------------------------------------------------------------------- *
* | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | *
* ---------------------------------------------------------------------------------- *
* | 0x120 | 0x124 | 0x128 | 0x12c | 0x130 | 0x134 | 0x138 | 0x13c | *
* ---------------------------------------------------------------------------------- *
* | parameter area | *
* ---------------------------------------------------------------------------------- *
* ---------------------------------------------------------------------------------- *
* | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | *
* ---------------------------------------------------------------------------------- *
* | 0x140 | 0x144 | 0x148 | 0x14c | 0x150 | 0x154 | 0x158 | 0x15c | *
* ---------------------------------------------------------------------------------- *
* | FCTX | DATA | | *
* ---------------------------------------------------------------------------------- *
**************************************************************************************/
.file "jump_x86_64_ms_pe_gas.S"
.text
.p2align 4,,15
.globl jump_fcontext
.def jump_fcontext; .scl 2; .type 32; .endef
.seh_proc jump_fcontext
jump_fcontext:
.seh_endprologue
leaq -0x118(%rsp), %rsp /* prepare stack */
/* save XMM storage */
movaps %xmm6, 0x0(%rsp)
movaps %xmm7, 0x10(%rsp)
movaps %xmm8, 0x20(%rsp)
movaps %xmm9, 0x30(%rsp)
movaps %xmm10, 0x40(%rsp)
movaps %xmm11, 0x50(%rsp)
movaps %xmm12, 0x60(%rsp)
movaps %xmm13, 0x70(%rsp)
movaps %xmm14, 0x80(%rsp)
movaps %xmm15, 0x90(%rsp)
stmxcsr 0xa0(%rsp) /* save MMX control- and status-word */
fnstcw 0xa4(%rsp) /* save x87 control-word */
/* load NT_TIB */
movq %gs:(0x30), %r10
/* save fiber local storage */
movq 0x18(%r10), %rax
movq %rax, 0xb0(%rsp)
/* save current deallocation stack */
movq 0x1478(%r10), %rax
movq %rax, 0xb8(%rsp)
/* save current stack limit */
movq 0x10(%r10), %rax
movq %rax, 0xc0(%rsp)
/* save current stack base */
movq 0x08(%r10), %rax
movq %rax, 0xc8(%rsp)
movq %r12, 0xd0(%rsp) /* save R12 */
movq %r13, 0xd8(%rsp) /* save R13 */
movq %r14, 0xe0(%rsp) /* save R14 */
movq %r15, 0xe8(%rsp) /* save R15 */
movq %rdi, 0xf0(%rsp) /* save RDI */
movq %rsi, 0xf8(%rsp) /* save RSI */
movq %rbx, 0x100(%rsp) /* save RBX */
movq %rbp, 0x108(%rsp) /* save RBP */
/* movq %rcx, 0x110(%rsp) */ /* save hidden address of transport_t */
/* ; preserve RSP (pointing to context-data) in RCX */
movq %rsp, (%rcx)
/* restore RSP (pointing to context-data) from RDX */
movq %rdx, %rsp
/* save XMM storage */
movaps 0x0(%rsp), %xmm6
movaps 0x10(%rsp), %xmm7
movaps 0x20(%rsp), %xmm8
movaps 0x30(%rsp), %xmm9
movaps 0x40(%rsp), %xmm10
movaps 0x50(%rsp), %xmm11
movaps 0x60(%rsp), %xmm12
movaps 0x70(%rsp), %xmm13
movaps 0x80(%rsp), %xmm14
movaps 0x90(%rsp), %xmm15
/* load NT_TIB */
movq %gs:(0x30), %r10
/* restore fiber local storage */
movq 0xb0(%rsp), %rax
movq %rax, 0x18(%r10)
/* restore current deallocation stack */
movq 0xb8(%rsp), %rax
movq %rax, 0x1478(%r10)
/* restore current stack limit */
movq 0xc0(%rsp), %rax
movq %rax, 0x10(%r10)
/* restore current stack base */
movq 0xc8(%rsp), %rax
movq %rax, 0x08(%r10)
movq 0xd0(%rsp), %r12 /* restore R12 */
movq 0xd8(%rsp), %r13 /* restore R13 */
movq 0xe0(%rsp), %r14 /* restore R14 */
movq 0xe8(%rsp), %r15 /* restore R15 */
movq 0xf0(%rsp), %rdi /* restore RDI */
movq 0xf8(%rsp), %rsi /* restore RSI */
movq 0x100(%rsp), %rbx /* restore RBX */
movq 0x108(%rsp), %rbp /* restore RBP */
/* movq 0x110(%rsp), %rax */ /* restore hidden address of transport_t */
leaq 0x118(%rsp), %rsp /* prepare stack */
/* restore return-address */
popq %r10
/* Set the third arg (data) as the first arg of the context function */
movq %r8, %rax
/* indirect jump to context */
jmp *%r10
.seh_endproc
.section .drectve
.ascii " -export:\"jump_fcontext\""
|
whupdup/frame
|
real/third_party/boost_context/asm/not_modified_yet/jump_x86_64_ms_pe_gas.S
|
Assembly
|
gpl-3.0
| 10,342
|
/*
Copyright Edward Nevill + Oliver Kowalke 2015
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)
*/
/*******************************************************
* *
* ------------------------------------------------- *
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | *
* ------------------------------------------------- *
* | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| *
* ------------------------------------------------- *
* | d8 | d9 | d10 | d11 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
* ------------------------------------------------- *
* | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| *
* ------------------------------------------------- *
* | d12 | d13 | d14 | d15 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | *
* ------------------------------------------------- *
* | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| *
* ------------------------------------------------- *
* | x19 | x20 | x21 | x22 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | *
* ------------------------------------------------- *
* | 0x60| 0x64| 0x68| 0x6c| 0x70| 0x74| 0x78| 0x7c| *
* ------------------------------------------------- *
* | x23 | x24 | x25 | x26 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | *
* ------------------------------------------------- *
* | 0x80| 0x84| 0x88| 0x8c| 0x90| 0x94| 0x98| 0x9c| *
* ------------------------------------------------- *
* | x27 | x28 | FP | LR | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 40 | 41 | 42 | 43 | | | *
* ------------------------------------------------- *
* | 0xa0| 0xa4| 0xa8| 0xac| | | *
* ------------------------------------------------- *
* | PC | align | | | *
* ------------------------------------------------- *
* *
*******************************************************/
.text
.globl _make_fcontext
.balign 16
_make_fcontext:
; shift address in x0 (allocated stack) to lower 16 byte boundary
and x0, x0, ~0xF
; reserve space for context-data on context-stack
sub x0, x0, #0xb0
; third arg of make_fcontext() == address of context-function
; store address as a PC to jump in
str x2, [x0, #0xa0]
; compute abs address of label finish
; 0x0c = 3 instructions * size (4) before label 'finish'
; TODO: Numeric offset since llvm still does not support labels in ADR. Fix:
; http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20140407/212336.html
adr x1, 0x0c
; save address of finish as return-address for context-function
; will be entered after context-function returns (LR register)
str x1, [x0, #0x98]
ret lr ; return pointer to context-data (x0)
finish:
; exit code is zero
mov x0, #0
; exit application
bl __exit
|
whupdup/frame
|
real/third_party/boost_context/asm/not_modified_yet/make_arm64_aapcs_macho_gas.S
|
Assembly
|
gpl-3.0
| 3,808
|
/*
Copyright Oliver Kowalke 2009.
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)
*/
/*******************************************************
* *
* ------------------------------------------------- *
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | *
* ------------------------------------------------- *
* | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| *
* ------------------------------------------------- *
* | s16 | s17 | s18 | s19 | s20 | s21 | s22 | s23 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
* ------------------------------------------------- *
* | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| *
* ------------------------------------------------- *
* | s24 | s25 | s26 | s27 | s28 | s29 | s30 | s31 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | *
* ------------------------------------------------- *
* | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| *
* ------------------------------------------------- *
* | sjlj|hiddn| v1 | v2 | v3 | v4 | v5 | v6 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | *
* ------------------------------------------------- *
* | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| *
* ------------------------------------------------- *
* | v7 | v8 | lr | pc | FCTX| DATA| | *
* ------------------------------------------------- *
* *
*******************************************************/
.text
.globl _make_fcontext
.align 2
_make_fcontext:
@ shift address in A1 to lower 16 byte boundary
bic a1, a1, #15
@ reserve space for context-data on context-stack
sub a1, a1, #128
@ third arg of make_fcontext() == address of context-function
str a3, [a1, #108]
@ compute address of returned transfer_t
add a2, a1, #112
mov a3, a2
str a3, [a1, #68]
@ compute abs address of label finish
adr a2, finish
@ save address of finish as return-address for context-function
@ will be entered after context-function returns
str a2, [a1, #104]
bx lr @ return pointer to context-data
finish:
@ exit code is zero
mov a1, #0
@ exit application
bl __exit
|
whupdup/frame
|
real/third_party/boost_context/asm/not_modified_yet/make_arm_aapcs_macho_gas.S
|
Assembly
|
gpl-3.0
| 2,783
|
;/*
; Copyright Oliver Kowalke 2009.
; 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)
;*/
; *******************************************************
; * *
; * ------------------------------------------------- *
; * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | *
; * ------------------------------------------------- *
; * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| *
; * ------------------------------------------------- *
; * |deall|limit| base|hiddn| v1 | v2 | v3 | v4 | *
; * ------------------------------------------------- *
; * ------------------------------------------------- *
; * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
; * ------------------------------------------------- *
; * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| *
; * ------------------------------------------------- *
; * | v5 | v6 | v7 | v8 | lr | pc | FCTX| DATA| *
; * ------------------------------------------------- *
; * *
; *******************************************************
AREA |.text|, CODE
ALIGN 4
EXPORT make_fcontext
IMPORT _exit
make_fcontext PROC
; first arg of make_fcontext() == top of context-stack
; save top of context-stack (base) A4
mov a4, a1
; shift address in A1 to lower 16 byte boundary
bic a1, a1, #0x0f
; reserve space for context-data on context-stack
sub a1, a1, #0x48
; save top address of context_stack as 'base'
str a4, [a1, #0x8]
; second arg of make_fcontext() == size of context-stack
; compute bottom address of context-stack (limit)
sub a4, a4, a2
; save bottom address of context-stack as 'limit'
str a4, [a1, #0x4]
; save bottom address of context-stack as 'dealloction stack'
str a4, [a1, #0x0]
; third arg of make_fcontext() == address of context-function
str a3, [a1, #0x34]
; compute address of returned transfer_t
add a2, a1, #0x38
mov a3, a2
str a3, [a1, #0xc]
; compute abs address of label finish
adr a2, finish
; save address of finish as return-address for context-function
; will be entered after context-function returns
str a2, [a1, #0x30]
bx lr ; return pointer to context-data
finish
; exit code is zero
mov a1, #0
; exit application
bl _exit
ENDP
END
|
whupdup/frame
|
real/third_party/boost_context/asm/not_modified_yet/make_arm_aapcs_pe_armasm.asm
|
Assembly
|
gpl-3.0
| 2,572
|
/*
Copyright Sergue E. Leontiev 2013.
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)
*/
// Stub file for universal binary
#if defined(__i386__)
#include "make_i386_sysv_macho_gas.S"
#elif defined(__x86_64__)
#include "make_x86_64_sysv_macho_gas.S"
#elif defined(__ppc__)
#include "make_ppc32_sysv_macho_gas.S"
#elif defined(__ppc64__)
#include "make_ppc64_sysv_macho_gas.S"
#else
#error "No arch's"
#endif
|
whupdup/frame
|
real/third_party/boost_context/asm/not_modified_yet/make_combined_sysv_macho_gas.S
|
Assembly
|
gpl-3.0
| 559
|
/*
Copyright Oliver Kowalke 2009.
Copyright Thomas Sailer 2013.
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)
*/
/*************************************************************************************
* --------------------------------------------------------------------------------- *
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | *
* --------------------------------------------------------------------------------- *
* | 0h | 04h | 08h | 0ch | 010h | 014h | 018h | 01ch | *
* --------------------------------------------------------------------------------- *
* | fc_mxcsr|fc_x87_cw| fc_strg |fc_deallo| limit | base | fc_seh | EDI | *
* --------------------------------------------------------------------------------- *
* --------------------------------------------------------------------------------- *
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
* --------------------------------------------------------------------------------- *
* | 020h | 024h | 028h | 02ch | 030h | 034h | 038h | 03ch | *
* --------------------------------------------------------------------------------- *
* | ESI | EBX | EBP | EIP | to | data | EH NXT |SEH HNDLR| *
* --------------------------------------------------------------------------------- *
**************************************************************************************/
.file "make_i386_ms_pe_gas.asm"
.text
.p2align 4,,15
.globl _make_fcontext
.def _make_fcontext; .scl 2; .type 32; .endef
_make_fcontext:
/* first arg of make_fcontext() == top of context-stack */
movl 0x04(%esp), %eax
/* reserve space for first argument of context-function */
/* EAX might already point to a 16byte border */
leal -0x8(%eax), %eax
/* shift address in EAX to lower 16 byte boundary */
andl $-16, %eax
/* reserve space for context-data on context-stack */
/* size for fc_mxcsr .. EIP + return-address for context-function */
/* on context-function entry: (ESP -0x4) % 8 == 0 */
/* additional space is required for SEH */
leal -0x40(%eax), %eax
/* save MMX control- and status-word */
stmxcsr (%eax)
/* save x87 control-word */
fnstcw 0x4(%eax)
/* first arg of make_fcontext() == top of context-stack */
movl 0x4(%esp), %ecx
/* save top address of context stack as 'base' */
movl %ecx, 0x14(%eax)
/* second arg of make_fcontext() == size of context-stack */
movl 0x8(%esp), %edx
/* negate stack size for LEA instruction (== substraction) */
negl %edx
/* compute bottom address of context stack (limit) */
leal (%ecx,%edx), %ecx
/* save bottom address of context-stack as 'limit' */
movl %ecx, 0x10(%eax)
/* save bottom address of context-stack as 'dealloction stack' */
movl %ecx, 0xc(%eax)
/* set fiber-storage to zero */
xorl %ecx, %ecx
movl %ecx, 0x8(%eax)
/* third arg of make_fcontext() == address of context-function */
/* stored in EBX */
movl 0xc(%esp), %ecx
movl %ecx, 0x24(%eax)
/* compute abs address of label trampoline */
movl $trampoline, %ecx
/* save address of trampoline as return-address for context-function */
/* will be entered after calling jump_fcontext() first time */
movl %ecx, 0x2c(%eax)
/* compute abs address of label finish */
movl $finish, %ecx
/* save address of finish as return-address for context-function */
/* will be entered after context-function returns */
movl %ecx, 0x28(%eax)
/* traverse current seh chain to get the last exception handler installed by Windows */
/* note that on Windows Server 2008 and 2008 R2, SEHOP is activated by default */
/* the exception handler chain is tested for the presence of ntdll.dll!FinalExceptionHandler */
/* at its end by RaiseException all seh andlers are disregarded if not present and the */
/* program is aborted */
/* load NT_TIB into ECX */
movl %fs:(0x0), %ecx
walk:
/* load 'next' member of current SEH into EDX */
movl (%ecx), %edx
/* test if 'next' of current SEH is last (== 0xffffffff) */
incl %edx
jz found
decl %edx
/* exchange content; ECX contains address of next SEH */
xchgl %ecx, %edx
/* inspect next SEH */
jmp walk
found:
/* load 'handler' member of SEH == address of last SEH handler installed by Windows */
movl 0x04(%ecx), %ecx
/* save address in ECX as SEH handler for context */
movl %ecx, 0x3c(%eax)
/* set ECX to -1 */
movl $0xffffffff, %ecx
/* save ECX as next SEH item */
movl %ecx, 0x38(%eax)
/* load address of next SEH item */
leal 0x38(%eax), %ecx
/* save next SEH */
movl %ecx, 0x18(%eax)
/* return pointer to context-data */
ret
trampoline:
/* move transport_t for entering context-function */
/* FCTX == EAX, DATA == EDX */
movl %eax, (%esp)
movl %edx, 0x4(%esp)
/* label finish as return-address */
pushl %ebp
/* jump to context-function */
jmp *%ebx
finish:
/* ESP points to same address as ESP on entry of context function + 0x4 */
xorl %eax, %eax
/* exit code is zero */
movl %eax, (%esp)
/* exit application */
call __exit
hlt
.def __exit; .scl 2; .type 32; .endef /* standard C library function */
.section .drectve
.ascii " -export:\"make_fcontext\""
|
whupdup/frame
|
real/third_party/boost_context/asm/not_modified_yet/make_i386_ms_pe_gas.asm
|
Assembly
|
gpl-3.0
| 5,666
|
/*
Copyright Oliver Kowalke 2009.
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)
*/
/****************************************************************************************
* *
* ---------------------------------------------------------------------------------- *
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | *
* ---------------------------------------------------------------------------------- *
* | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | *
* ---------------------------------------------------------------------------------- *
* | fc_mxcsr|fc_x87_cw| EDI | ESI | EBX | EBP | EIP | hidden | *
* ---------------------------------------------------------------------------------- *
* ---------------------------------------------------------------------------------- *
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
* ---------------------------------------------------------------------------------- *
* | 0x20 | 0x24 | 0x28 | | *
* ---------------------------------------------------------------------------------- *
* | from | to | data | | *
* ---------------------------------------------------------------------------------- *
* *
****************************************************************************************/
.text
.globl make_fcontext
.align 2
.type make_fcontext,@function
make_fcontext:
/* first arg of make_fcontext() == top of context-stack */
movl 0x4(%esp), %eax
/* reserve space for first argument of context-function
eax might already point to a 16byte border */
leal -0x8(%eax), %eax
/* shift address in EAX to lower 16 byte boundary */
andl $-16, %eax
/* reserve space for context-data on context-stack */
leal -0x28(%eax), %eax
/* third arg of make_fcontext() == address of context-function */
/* stored in EBX */
movl 0xc(%esp), %ecx
movl %ecx, 0x10(%eax)
/* save MMX control- and status-word */
stmxcsr (%eax)
/* save x87 control-word */
fnstcw 0x4(%eax)
/* return transport_t */
/* FCTX == EDI, DATA == ESI */
leal 0x8(%eax), %ecx
movl %ecx, 0x1c(%eax)
/* compute abs address of label trampoline */
call 1f
/* address of trampoline 1 */
1: popl %ecx
/* compute abs address of label trampoline */
addl $trampoline-1b, %ecx
/* save address of trampoline as return address */
/* will be entered after calling jump_fcontext() first time */
movl %ecx, 0x18(%eax)
/* compute abs address of label finish */
call 2f
/* address of label 2 */
2: popl %ecx
/* compute abs address of label finish */
addl $finish-2b, %ecx
/* save address of finish as return-address for context-function */
/* will be entered after context-function returns */
movl %ecx, 0x14(%eax)
ret /* return pointer to context-data */
trampoline:
/* move data for entering context-function */
mov %eax, (%esp)
pushl %ebp
/* jump to context-function */
jmp *%ebx
finish:
call 3f
/* address of label 3 */
3: popl %ebx
/* compute address of GOT and store it in EBX */
addl $_GLOBAL_OFFSET_TABLE_+[.-3b], %ebx
/* exit code is zero */
xorl %eax, %eax
movl %eax, (%esp)
/* exit application */
call _exit@PLT
hlt
.size make_fcontext,.-make_fcontext
/* Mark that we don't need executable stack. */
.section .note.GNU-stack,"",%progbits
|
whupdup/frame
|
real/third_party/boost_context/asm/not_modified_yet/make_i386_sysv_elf_gas.S
|
Assembly
|
gpl-3.0
| 3,988
|
/*
Copyright Oliver Kowalke 2009.
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)
*/
/****************************************************************************************
* *
* ---------------------------------------------------------------------------------- *
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | *
* ---------------------------------------------------------------------------------- *
* | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | *
* ---------------------------------------------------------------------------------- *
* | fc_mxcsr|fc_x87_cw| EDI | ESI | EBX | EBP | EIP | hidden | *
* ---------------------------------------------------------------------------------- *
* ---------------------------------------------------------------------------------- *
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
* ---------------------------------------------------------------------------------- *
* | 0x20 | 0x24 | | *
* ---------------------------------------------------------------------------------- *
* | to | data | | *
* ---------------------------------------------------------------------------------- *
* *
****************************************************************************************/
.text
.globl _make_fcontext
.align 2
_make_fcontext:
/* first arg of make_fcontext() == top of context-stack */
movl 0x4(%esp), %eax
/* reserve space for first argument of context-function
eax might already point to a 16byte border */
leal -0x8(%eax), %eax
/* shift address in EAX to lower 16 byte boundary */
andl $-16, %eax
/* reserve space for context-data on context-stack */
leal -0x28(%eax), %eax
/* third arg of make_fcontext() == address of context-function */
/* stored in EBX */
movl 0xc(%esp), %ecx
movl %ecx, 0x10(%eax)
/* save MMX control- and status-word */
stmxcsr (%eax)
/* save x87 control-word */
fnstcw 0x4(%eax)
/* return transport_t */
/* FCTX == EDI, DATA == ESI */
leal 0x8(%eax), %ecx
movl %ecx, 0x1c(%eax)
/* compute abs address of label trampoline */
call 1f
/* address of trampoline 1 */
1: popl %ecx
/* compute abs address of label trampoline */
addl $trampoline-1b, %ecx
/* save address of trampoline as return address */
/* will be entered after calling jump_fcontext() first time */
movl %ecx, 0x18(%eax)
/* compute abs address of label finish */
call 2f
/* address of label 2 */
2: popl %ecx
/* compute abs address of label finish */
addl $finish-2b, %ecx
/* save address of finish as return-address for context-function */
/* will be entered after context-function returns */
movl %ecx, 0x14(%eax)
ret /* return pointer to context-data */
trampoline:
/* move transport_t for entering context-function */
movl %edi, (%esp)
movl %esi, 0x4(%esp)
pushl %ebp
/* jump to context-function */
jmp *%ebx
finish:
/* exit code is zero */
xorl %eax, %eax
movl %eax, (%esp)
/* exit application */
call __exit
hlt
|
whupdup/frame
|
real/third_party/boost_context/asm/not_modified_yet/make_i386_sysv_macho_gas.S
|
Assembly
|
gpl-3.0
| 3,710
|