mirror of
https://github.com/Ed94/perfaware.git
synced 2026-09-14 03:39:23 +00:00
misc changes, preparing for 8086 module.
This commit is contained in:
@@ -16,7 +16,7 @@ FI_ void u64_to_hex(U8 val, char* buf, S4 chars) {
|
||||
for(S1 i = chars - 1; i >= 0; --i) { buf[i] = hex_chars[val & 0xF]; val >>= 4; }
|
||||
}
|
||||
|
||||
internal UnicodeDecode
|
||||
I_ UnicodeDecode
|
||||
utf8_decode(U1* str, U1 max) {
|
||||
UnicodeDecode result = {1, Max_U4};
|
||||
U1 byte = str[0];
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@ os_layer File file_open(FArena* scratch, AccessFlags flags, Str8 path);
|
||||
os_layer FileProperties properties_from_file(File file);
|
||||
os_layer U8 file_read(File file, R1_U8 rng, U1* out_data);
|
||||
|
||||
internal Slice_U1
|
||||
I_ Slice_U1
|
||||
data_from_file_range(FArena* arena, File file, R1_U8 range) {
|
||||
U8 pre_pos = farena_save(arena[0]);
|
||||
U8 len = span_r1u8(range);
|
||||
|
||||
+2
-1
@@ -2,6 +2,7 @@
|
||||
# pragma once
|
||||
# include "dsl.h"
|
||||
# include "memory.h"
|
||||
# include "files.h"
|
||||
#endif
|
||||
|
||||
WinAPI void ms_exit_process(U4 uExitCode) asm("ExitProcess"); // Kernel 32
|
||||
@@ -245,7 +246,7 @@ w32_date_time_from_system_time(DateTime* out, MS_SYSTEMTIME* in) {
|
||||
I_ void
|
||||
w32_dense_time_from_file_time(DenseTime* out, MS_FILETIME* in) {
|
||||
MS_SYSTEMTIME systime = {0}; ms_filetime_to_systemtime(in, &systime); DateTime date_time = {0};
|
||||
w32_date_time_from_system_time(&date_time, &systime); *out = dense_time_from_date_time(date_time);
|
||||
w32_date_time_from_system_time(&date_time, &systime); out[0] = dense_time_from_date_time(date_time);
|
||||
}
|
||||
|
||||
I_ FilePropertyFlags
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
|
||||
#include "duffle/win32.h"
|
||||
|
||||
// #include "8086/decoder.h"
|
||||
|
||||
typedef Struct_(U2_HL) { U1 Low; U1 High; };
|
||||
|
||||
#define bitmask_(pos) (1 << pos)
|
||||
@@ -54,9 +56,6 @@ I_ Str8 binary_as_str8(Slice_U1 data, FArena* str8_mem) { Str8 result = {0};
|
||||
jret: return result;
|
||||
}
|
||||
|
||||
typedef Enum_(U4, x86_Op) {
|
||||
x86_mov
|
||||
};
|
||||
|
||||
|
||||
enum {
|
||||
|
||||
+37
-22
@@ -18,6 +18,7 @@ if ((test-path $path_build) -eq $false) {
|
||||
$compiler = "clang"
|
||||
$linker = 'lld-link.exe'
|
||||
$objcopy = 'llvm-objcopy'
|
||||
$objdump = 'llvm-objdump'
|
||||
$archiver = 'llvm-ar'
|
||||
|
||||
# --- Compiler Flags: General / Compilation Mode ---
|
||||
@@ -163,24 +164,6 @@ $f_verbose = '-v'
|
||||
$f_set_stack_size = '-stack=' # Stack size (linker-side, but accepted by clang)
|
||||
$f_symbol_prefix = '-femit-all-decls'
|
||||
|
||||
# --- Compiler Flags: MIPS Architecture (catalog parity with ps1/build_psyq.ps1) ---
|
||||
# Used by the PS1 cross-compile path (C:\projects\Pikuma\ps1). Not used by
|
||||
# the current Win32 build. Kept here so the catalog is complete.
|
||||
$f_arch_mips1 = '-march=mips1'
|
||||
$f_arch_mips2 = '-march=mips2'
|
||||
$f_arch_mips3 = '-march=mips3'
|
||||
$f_arch_abi32 = '-mabi=32'
|
||||
$f_arch_abi64 = '-mabi=64'
|
||||
$f_arch_little_endian = '-EL'
|
||||
$f_arch_big_endian = '-EB'
|
||||
$f_arch_fp32 = '-mfp32'
|
||||
$f_arch_no_pic = '-fno-pic'
|
||||
$f_arch_no_shared = '-mno-shared'
|
||||
$f_arch_no_abicalls = '-mno-abicalls'
|
||||
$f_arch_no_llsc = '-mno-llsc'
|
||||
$f_arch_no_gpopt = '-mno-gpopt'
|
||||
$f_arch_no_stack_prot = '-fno-stack-protector'
|
||||
|
||||
# --- Linker Flags (passed via -Wl, to clang; or directly to gcc-style linkers) ---
|
||||
# These are GNU ld-style flags. When invoking lld-link.exe directly, prefer
|
||||
# the Win32-flavored flags below.
|
||||
@@ -273,6 +256,16 @@ $f_objcopy_add_section = '--add-section'
|
||||
$f_objcopy_update_section = '--update-section'
|
||||
$f_objcopy_set_section_flags = '--set-section-flags'
|
||||
|
||||
# --- Objdump Flags ---
|
||||
$f_objdump_disassemble = '-d' # Disassemble all executable sections
|
||||
$f_objdump_machine = '-M' # Usage: $f_objdump_machine + 'intel'
|
||||
$f_objdump_source_lines = '-l' # Interleave source lines (requires -g)
|
||||
$f_objdump_no_raw_insn = '--no-show-raw-insn' # Omit hex bytes
|
||||
$f_objdump_reloc = '-r' # Inline relocations
|
||||
$f_objdump_symbols = '--disassemble-symbols=' # Usage: $f_objdump_symbols + 'main'
|
||||
$f_objdump_headers = '-x' # All headers + sections (verbose)
|
||||
$f_objdump_section_contents = '-s' # Raw section contents (hex dump)
|
||||
|
||||
# --- Baseline Libraries (lld-link, Win32) ---
|
||||
$libraries_win32 = @(
|
||||
'kernel32.lib'
|
||||
@@ -283,8 +276,7 @@ $libraries_win32 = @(
|
||||
|
||||
# --- Functions ---
|
||||
|
||||
function compile-unit {
|
||||
param(
|
||||
function compile-unit { param(
|
||||
[string] $unit,
|
||||
[string] $link_module,
|
||||
[string[]] $include_paths,
|
||||
@@ -313,8 +305,7 @@ function compile-unit {
|
||||
if ($LASTEXITCODE -ne 0) { write-error "Compilation failed for $unit. Aborting."; exit 1 }
|
||||
}
|
||||
|
||||
function link-modules {
|
||||
param(
|
||||
function link-modules { param(
|
||||
[string[]] $link_modules,
|
||||
[string] $module,
|
||||
[string] $pdb,
|
||||
@@ -348,6 +339,28 @@ function link-modules {
|
||||
if ($LASTEXITCODE -ne 0) { write-error "Linking failed. Aborting."; exit 1 }
|
||||
}
|
||||
|
||||
function dump-disassembly { param([string] $obj, [string] $exe)
|
||||
$base = [System.IO.Path]::GetFileNameWithoutExtension($exe)
|
||||
$asm_obj = join-path $path_build "$base.obj.asm"
|
||||
$asm_exe = join-path $path_build "$base.exe.asm"
|
||||
|
||||
$objdump_args = @()
|
||||
$objdump_args += $f_objdump_disassemble
|
||||
$objdump_args += ($f_objdump_machine + 'intel')
|
||||
$objdump_args += $f_objdump_source_lines
|
||||
$objdump_args += $f_objdump_no_raw_insn
|
||||
|
||||
write-host "Dumping object disassembly -> '$asm_obj'" -ForegroundColor DarkCyan
|
||||
$time_to_objdump = Measure-Command { & $objdump $objdump_args $obj | Out-File -FilePath $asm_obj -Encoding utf8 }
|
||||
write-host "Object disassembly took $($time_to_objdump.TotalMilliseconds)ms"
|
||||
if ($LASTEXITCODE -ne 0) { write-error "objdump failed for $obj. Aborting."; exit 1 }
|
||||
|
||||
write-host "Dumping executable disassembly -> '$asm_exe'" -ForegroundColor DarkCyan
|
||||
$time_to_objdump = Measure-Command { & $objdump $objdump_args $exe | Out-File -FilePath $asm_exe -Encoding utf8 }
|
||||
write-host "Executable disassembly took $($time_to_objdump.TotalMilliseconds)ms"
|
||||
if ($LASTEXITCODE -ne 0) { write-error "objdump failed for $exe. Aborting."; exit 1 }
|
||||
}
|
||||
|
||||
function build-part_1 {
|
||||
# The base lib uses subdir-prefixed includes (e.g. "duffle/dsl.h"),
|
||||
# so the include root is <code>, not <code>/duffle.
|
||||
@@ -370,6 +383,8 @@ function build-part_1 {
|
||||
$exe = join-path $path_build 'sim_8086.exe'
|
||||
|
||||
link-modules $module_c $exe $pdb @()
|
||||
|
||||
dump-disassembly $module_c $exe
|
||||
}
|
||||
|
||||
build-part_1
|
||||
|
||||
Reference in New Issue
Block a user