misc changes, preparing for 8086 module.

This commit is contained in:
ed
2026-09-04 21:02:31 -04:00
parent aa9c4d48f6
commit bfd02f4472
6 changed files with 160 additions and 145 deletions
+1 -1
View File
@@ -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; } 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) { utf8_decode(U1* str, U1 max) {
UnicodeDecode result = {1, Max_U4}; UnicodeDecode result = {1, Max_U4};
U1 byte = str[0]; U1 byte = str[0];
+1 -1
View File
@@ -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 FileProperties properties_from_file(File file);
os_layer U8 file_read(File file, R1_U8 rng, U1* out_data); 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) { data_from_file_range(FArena* arena, File file, R1_U8 range) {
U8 pre_pos = farena_save(arena[0]); U8 pre_pos = farena_save(arena[0]);
U8 len = span_r1u8(range); U8 len = span_r1u8(range);
+2 -1
View File
@@ -2,6 +2,7 @@
# pragma once # pragma once
# include "dsl.h" # include "dsl.h"
# include "memory.h" # include "memory.h"
# include "files.h"
#endif #endif
WinAPI void ms_exit_process(U4 uExitCode) asm("ExitProcess"); // Kernel 32 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 I_ void
w32_dense_time_from_file_time(DenseTime* out, MS_FILETIME* in) { 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}; 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 I_ FilePropertyFlags
+2 -3
View File
@@ -10,6 +10,8 @@
#include "duffle/win32.h" #include "duffle/win32.h"
// #include "8086/decoder.h"
typedef Struct_(U2_HL) { U1 Low; U1 High; }; typedef Struct_(U2_HL) { U1 Low; U1 High; };
#define bitmask_(pos) (1 << pos) #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; jret: return result;
} }
typedef Enum_(U4, x86_Op) {
x86_mov
};
enum { enum {
+37 -22
View File
@@ -18,6 +18,7 @@ if ((test-path $path_build) -eq $false) {
$compiler = "clang" $compiler = "clang"
$linker = 'lld-link.exe' $linker = 'lld-link.exe'
$objcopy = 'llvm-objcopy' $objcopy = 'llvm-objcopy'
$objdump = 'llvm-objdump'
$archiver = 'llvm-ar' $archiver = 'llvm-ar'
# --- Compiler Flags: General / Compilation Mode --- # --- 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_set_stack_size = '-stack=' # Stack size (linker-side, but accepted by clang)
$f_symbol_prefix = '-femit-all-decls' $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) --- # --- 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 # These are GNU ld-style flags. When invoking lld-link.exe directly, prefer
# the Win32-flavored flags below. # the Win32-flavored flags below.
@@ -273,6 +256,16 @@ $f_objcopy_add_section = '--add-section'
$f_objcopy_update_section = '--update-section' $f_objcopy_update_section = '--update-section'
$f_objcopy_set_section_flags = '--set-section-flags' $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) --- # --- Baseline Libraries (lld-link, Win32) ---
$libraries_win32 = @( $libraries_win32 = @(
'kernel32.lib' 'kernel32.lib'
@@ -283,8 +276,7 @@ $libraries_win32 = @(
# --- Functions --- # --- Functions ---
function compile-unit { function compile-unit { param(
param(
[string] $unit, [string] $unit,
[string] $link_module, [string] $link_module,
[string[]] $include_paths, [string[]] $include_paths,
@@ -313,8 +305,7 @@ function compile-unit {
if ($LASTEXITCODE -ne 0) { write-error "Compilation failed for $unit. Aborting."; exit 1 } if ($LASTEXITCODE -ne 0) { write-error "Compilation failed for $unit. Aborting."; exit 1 }
} }
function link-modules { function link-modules { param(
param(
[string[]] $link_modules, [string[]] $link_modules,
[string] $module, [string] $module,
[string] $pdb, [string] $pdb,
@@ -348,6 +339,28 @@ function link-modules {
if ($LASTEXITCODE -ne 0) { write-error "Linking failed. Aborting."; exit 1 } 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 { function build-part_1 {
# The base lib uses subdir-prefixed includes (e.g. "duffle/dsl.h"), # The base lib uses subdir-prefixed includes (e.g. "duffle/dsl.h"),
# so the include root is <code>, not <code>/duffle. # 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' $exe = join-path $path_build 'sim_8086.exe'
link-modules $module_c $exe $pdb @() link-modules $module_c $exe $pdb @()
dump-disassembly $module_c $exe
} }
build-part_1 build-part_1