11cb0ef41Sopenharmony_ci// Copyright 2019 the V8 project authors. All rights reserved. 21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be 31cb0ef41Sopenharmony_ci// found in the LICENSE file. 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ci#include "src/snapshot/embedded/platform-embedded-file-writer-aix.h" 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ci#include "src/objects/code.h" 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_cinamespace v8 { 101cb0ef41Sopenharmony_cinamespace internal { 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ci#define SYMBOL_PREFIX "" 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_cinamespace { 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ciconst char* DirectiveAsString(DataDirective directive) { 171cb0ef41Sopenharmony_ci switch (directive) { 181cb0ef41Sopenharmony_ci case kByte: 191cb0ef41Sopenharmony_ci return ".byte"; 201cb0ef41Sopenharmony_ci case kLong: 211cb0ef41Sopenharmony_ci return ".long"; 221cb0ef41Sopenharmony_ci case kQuad: 231cb0ef41Sopenharmony_ci return ".llong"; 241cb0ef41Sopenharmony_ci default: 251cb0ef41Sopenharmony_ci UNREACHABLE(); 261cb0ef41Sopenharmony_ci } 271cb0ef41Sopenharmony_ci} 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_ci} // namespace 301cb0ef41Sopenharmony_ci 311cb0ef41Sopenharmony_civoid PlatformEmbeddedFileWriterAIX::SectionText() { 321cb0ef41Sopenharmony_ci fprintf(fp_, ".csect [GL], 6\n"); 331cb0ef41Sopenharmony_ci} 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_civoid PlatformEmbeddedFileWriterAIX::SectionData() { 361cb0ef41Sopenharmony_ci fprintf(fp_, ".csect .data[RW]\n"); 371cb0ef41Sopenharmony_ci} 381cb0ef41Sopenharmony_ci 391cb0ef41Sopenharmony_civoid PlatformEmbeddedFileWriterAIX::SectionRoData() { 401cb0ef41Sopenharmony_ci fprintf(fp_, ".csect[RO]\n"); 411cb0ef41Sopenharmony_ci} 421cb0ef41Sopenharmony_ci 431cb0ef41Sopenharmony_civoid PlatformEmbeddedFileWriterAIX::DeclareUint32(const char* name, 441cb0ef41Sopenharmony_ci uint32_t value) { 451cb0ef41Sopenharmony_ci DeclareSymbolGlobal(name); 461cb0ef41Sopenharmony_ci fprintf(fp_, ".align 2\n"); 471cb0ef41Sopenharmony_ci fprintf(fp_, "%s:\n", name); 481cb0ef41Sopenharmony_ci IndentedDataDirective(kLong); 491cb0ef41Sopenharmony_ci fprintf(fp_, "%d\n", value); 501cb0ef41Sopenharmony_ci Newline(); 511cb0ef41Sopenharmony_ci} 521cb0ef41Sopenharmony_ci 531cb0ef41Sopenharmony_civoid PlatformEmbeddedFileWriterAIX::DeclarePointerToSymbol(const char* name, 541cb0ef41Sopenharmony_ci const char* target) { 551cb0ef41Sopenharmony_ci AlignToCodeAlignment(); 561cb0ef41Sopenharmony_ci DeclareLabel(name); 571cb0ef41Sopenharmony_ci fprintf(fp_, " %s %s\n", DirectiveAsString(PointerSizeDirective()), target); 581cb0ef41Sopenharmony_ci Newline(); 591cb0ef41Sopenharmony_ci} 601cb0ef41Sopenharmony_ci 611cb0ef41Sopenharmony_civoid PlatformEmbeddedFileWriterAIX::DeclareSymbolGlobal(const char* name) { 621cb0ef41Sopenharmony_ci // These symbols are not visible outside of the final binary, this allows for 631cb0ef41Sopenharmony_ci // reduced binary size, and less work for the dynamic linker. 641cb0ef41Sopenharmony_ci fprintf(fp_, ".globl %s, hidden\n", name); 651cb0ef41Sopenharmony_ci} 661cb0ef41Sopenharmony_ci 671cb0ef41Sopenharmony_civoid PlatformEmbeddedFileWriterAIX::AlignToCodeAlignment() { 681cb0ef41Sopenharmony_ci#if V8_TARGET_ARCH_X64 691cb0ef41Sopenharmony_ci // On x64 use 64-bytes code alignment to allow 64-bytes loop header alignment. 701cb0ef41Sopenharmony_ci STATIC_ASSERT((1 << 6) >= kCodeAlignment); 711cb0ef41Sopenharmony_ci fprintf(fp_, ".align 6\n"); 721cb0ef41Sopenharmony_ci#elif V8_TARGET_ARCH_PPC64 731cb0ef41Sopenharmony_ci // 64 byte alignment is needed on ppc64 to make sure p10 prefixed instructions 741cb0ef41Sopenharmony_ci // don't cross 64-byte boundaries. 751cb0ef41Sopenharmony_ci STATIC_ASSERT((1 << 6) >= kCodeAlignment); 761cb0ef41Sopenharmony_ci fprintf(fp_, ".align 6\n"); 771cb0ef41Sopenharmony_ci#else 781cb0ef41Sopenharmony_ci STATIC_ASSERT((1 << 5) >= kCodeAlignment); 791cb0ef41Sopenharmony_ci fprintf(fp_, ".align 5\n"); 801cb0ef41Sopenharmony_ci#endif 811cb0ef41Sopenharmony_ci} 821cb0ef41Sopenharmony_ci 831cb0ef41Sopenharmony_civoid PlatformEmbeddedFileWriterAIX::AlignToDataAlignment() { 841cb0ef41Sopenharmony_ci STATIC_ASSERT((1 << 3) >= Code::kMetadataAlignment); 851cb0ef41Sopenharmony_ci fprintf(fp_, ".align 3\n"); 861cb0ef41Sopenharmony_ci} 871cb0ef41Sopenharmony_ci 881cb0ef41Sopenharmony_civoid PlatformEmbeddedFileWriterAIX::Comment(const char* string) { 891cb0ef41Sopenharmony_ci fprintf(fp_, "// %s\n", string); 901cb0ef41Sopenharmony_ci} 911cb0ef41Sopenharmony_ci 921cb0ef41Sopenharmony_civoid PlatformEmbeddedFileWriterAIX::DeclareLabel(const char* name) { 931cb0ef41Sopenharmony_ci // .global is required on AIX, if the label is used/referenced in another file 941cb0ef41Sopenharmony_ci // later to be linked. 951cb0ef41Sopenharmony_ci fprintf(fp_, ".globl %s\n", name); 961cb0ef41Sopenharmony_ci fprintf(fp_, "%s:\n", name); 971cb0ef41Sopenharmony_ci} 981cb0ef41Sopenharmony_ci 991cb0ef41Sopenharmony_civoid PlatformEmbeddedFileWriterAIX::SourceInfo(int fileid, const char* filename, 1001cb0ef41Sopenharmony_ci int line) { 1011cb0ef41Sopenharmony_ci fprintf(fp_, ".xline %d, \"%s\"\n", line, filename); 1021cb0ef41Sopenharmony_ci} 1031cb0ef41Sopenharmony_ci 1041cb0ef41Sopenharmony_ci// TODO(mmarchini): investigate emitting size annotations for AIX 1051cb0ef41Sopenharmony_civoid PlatformEmbeddedFileWriterAIX::DeclareFunctionBegin(const char* name, 1061cb0ef41Sopenharmony_ci uint32_t size) { 1071cb0ef41Sopenharmony_ci Newline(); 1081cb0ef41Sopenharmony_ci if (ENABLE_CONTROL_FLOW_INTEGRITY_BOOL) { 1091cb0ef41Sopenharmony_ci DeclareSymbolGlobal(name); 1101cb0ef41Sopenharmony_ci } 1111cb0ef41Sopenharmony_ci fprintf(fp_, ".csect %s[DS]\n", name); // function descriptor 1121cb0ef41Sopenharmony_ci fprintf(fp_, "%s:\n", name); 1131cb0ef41Sopenharmony_ci fprintf(fp_, ".llong .%s, 0, 0\n", name); 1141cb0ef41Sopenharmony_ci SectionText(); 1151cb0ef41Sopenharmony_ci fprintf(fp_, ".%s:\n", name); 1161cb0ef41Sopenharmony_ci} 1171cb0ef41Sopenharmony_ci 1181cb0ef41Sopenharmony_civoid PlatformEmbeddedFileWriterAIX::DeclareFunctionEnd(const char* name) {} 1191cb0ef41Sopenharmony_ci 1201cb0ef41Sopenharmony_civoid PlatformEmbeddedFileWriterAIX::FilePrologue() {} 1211cb0ef41Sopenharmony_ci 1221cb0ef41Sopenharmony_civoid PlatformEmbeddedFileWriterAIX::DeclareExternalFilename( 1231cb0ef41Sopenharmony_ci int fileid, const char* filename) { 1241cb0ef41Sopenharmony_ci // File name cannot be declared with an identifier on AIX. 1251cb0ef41Sopenharmony_ci // We use the SourceInfo method to emit debug info in 1261cb0ef41Sopenharmony_ci //.xline <line-number> <file-name> format. 1271cb0ef41Sopenharmony_ci} 1281cb0ef41Sopenharmony_ci 1291cb0ef41Sopenharmony_civoid PlatformEmbeddedFileWriterAIX::FileEpilogue() {} 1301cb0ef41Sopenharmony_ci 1311cb0ef41Sopenharmony_ciint PlatformEmbeddedFileWriterAIX::IndentedDataDirective( 1321cb0ef41Sopenharmony_ci DataDirective directive) { 1331cb0ef41Sopenharmony_ci return fprintf(fp_, " %s ", DirectiveAsString(directive)); 1341cb0ef41Sopenharmony_ci} 1351cb0ef41Sopenharmony_ci 1361cb0ef41Sopenharmony_ciDataDirective PlatformEmbeddedFileWriterAIX::ByteChunkDataDirective() const { 1371cb0ef41Sopenharmony_ci // PPC uses a fixed 4 byte instruction set, using .long 1381cb0ef41Sopenharmony_ci // to prevent any unnecessary padding. 1391cb0ef41Sopenharmony_ci return kLong; 1401cb0ef41Sopenharmony_ci} 1411cb0ef41Sopenharmony_ci 1421cb0ef41Sopenharmony_ci#undef SYMBOL_PREFIX 1431cb0ef41Sopenharmony_ci 1441cb0ef41Sopenharmony_ci} // namespace internal 1451cb0ef41Sopenharmony_ci} // namespace v8 146