progress on hello_files
This commit is contained in:
@ -11,6 +11,7 @@ DEFAULT REL ; Use RIP-relative addressing by default
|
||||
%define rcounter_32 ecx
|
||||
%define rdata_32 edx
|
||||
%define r8_32 r8d
|
||||
%define r9_32
|
||||
|
||||
%define raccumulator rax
|
||||
%define rbase rbx
|
||||
@ -20,6 +21,10 @@ DEFAULT REL ; Use RIP-relative addressing by default
|
||||
%define rsrc_id rsi
|
||||
%define rstack_ptr rsp
|
||||
%define rstack_base_ptr rbp
|
||||
|
||||
%define false 0
|
||||
%define true 1
|
||||
%define true_overflow 2
|
||||
;endregion DSL
|
||||
|
||||
;region Registers
|
||||
@ -154,6 +159,12 @@ DEFAULT REL ; Use RIP-relative addressing by default
|
||||
%define debug_trap 3
|
||||
|
||||
%ifidn BUILD_DEBUG, 1
|
||||
%macro assert_cmp 3
|
||||
cmp %2, %3
|
||||
%1 %%.passed
|
||||
int debug_trap
|
||||
%%.passed:
|
||||
%endmacro
|
||||
%macro assert_not_null 1
|
||||
cmp %1, nullptr
|
||||
jnz %%.passed
|
||||
@ -166,6 +177,9 @@ DEFAULT REL ; Use RIP-relative addressing by default
|
||||
%define dbg_wipe_ymms wipe_ymms
|
||||
%define dbg_wipe_avx512s wipe_avx512s
|
||||
%else
|
||||
%macro assert_cmp 3
|
||||
%cmp %2, %3
|
||||
%endmacro
|
||||
%macro assert_not_null 1
|
||||
%endmacro
|
||||
%macro slice_assert 1
|
||||
@ -406,8 +420,8 @@ endstruc
|
||||
; path: Slice_Str8 = { .ptr = rdata, .len = r8 }
|
||||
; backing: r9 = [Slice_Byte]
|
||||
%push proc_scope
|
||||
%define path_ptr rdata
|
||||
%define result rcounter
|
||||
%define path_ptr rdata
|
||||
%define path_len r8
|
||||
%define backing r9
|
||||
|
||||
@ -419,16 +433,20 @@ file_read_contents:
|
||||
push rbx
|
||||
push r12
|
||||
push r13
|
||||
push r14
|
||||
mov r12, result
|
||||
mov r13, backing
|
||||
%define result r12
|
||||
%define backing r13
|
||||
; rcounter = str8_to_cstr_capped(path, slice_fmem(scratch));
|
||||
; We're using backing to store the cstr temporarily until ReadFile.
|
||||
; TODO(Ed): This cannot be done with an allocator interface...
|
||||
call str8_to_cstr_capped ; (rdata, r8, r9)
|
||||
; path_cstr = rcounter; path_len has will be discarded in the CreateFileA call
|
||||
%define path_cstr rcounter
|
||||
|
||||
wapi_shadow_space
|
||||
; rcounter = [path_cstr]
|
||||
; rcounter = path_cstr
|
||||
mov rdata_32, MS_GENERIC_READ ; dwDesiredAccess = MS_GENERIC_READ
|
||||
mov r8_32, MS_FILE_SHARE_READ ; dwShareMode = MS_FILE_SHARE_READ
|
||||
xor r9, r9 ; lpSecurityAttributes = nullptr
|
||||
@ -440,21 +458,50 @@ file_read_contents:
|
||||
|
||||
; B32 open_failed = raccumulator == MS_INVALID_HANDLE_VALUE
|
||||
; if (open_failed) goto %%.error_exit
|
||||
cmp raccumulator, MS_INVALID_HANDLE_VALUE
|
||||
assert_cmp jnz, raccumulator, MS_INVALID_HANDLE_VALUE
|
||||
je .error_exit
|
||||
|
||||
mov rbase, raccumulator ; rbase = id_file
|
||||
%define id_file rbase
|
||||
|
||||
wapi_shadow_space
|
||||
mov rcounter, rbase ; hfile: rcounter = rbase
|
||||
; rcounter = path_str ; hfile
|
||||
lea rdata, [result + FileOpInfo.content + Slice_Byte.len]; lpFileSize = result.content.len
|
||||
call GetFileSizeEx
|
||||
|
||||
; B32 not_enough_backing = backing.len < result.content.len
|
||||
; if (not_enough_backing) goto .error_exit
|
||||
mov r8, [backing + Slice_Byte.len]
|
||||
mov r9, [result + FileOpInfo.content + Slice_Byte.len]
|
||||
assert_cmp jg, r9, r8
|
||||
jg .error_exit
|
||||
|
||||
; MS_BOOL get_size_failed = rax
|
||||
; if (get_size_failed) goto .error_exit
|
||||
assert_cmp jnz, raccumulator, false
|
||||
je .error_exit
|
||||
|
||||
%define file_size r14d
|
||||
mov r14d, r9d
|
||||
|
||||
wapi_shadow_space
|
||||
mov rcounter, id_file ; hfile: rcounter = rbase
|
||||
mov rdata, [backing + Slice_Byte.ptr ] ; lpBuffer: rdata = backing.ptr
|
||||
mov r8_32, [backing + Slice_Byte.len ] ; nNumberOfBytesRead: r8_32 = backing.len
|
||||
mov r9, [result + FileOpInfo.content + Slice_Byte.len] ; lpNumberOfBytesRead: result.content.len = backing.len
|
||||
mov qword [rstack_ptr + wapi_ReadFile_lpOverlapped], 0
|
||||
mov r8_32, file_size ; nNumberOfBytesRead: r8_32 = file_size
|
||||
mov r9, [result + FileOpInfo.content + Slice_Byte.len] ; lpNumberOfBytesToRead: r9 = & result.content.len
|
||||
mov qword [rstack_ptr + wapi_ReadFile_lpOverlapped], 0 ; lpOverlapped: nullptr
|
||||
call ReadFile
|
||||
stack_pop
|
||||
|
||||
; Close the handle.
|
||||
; B32 read_failed = ! read_result
|
||||
; read_failed |= amount_read != result.content.len
|
||||
; if (read_failed) goto .error_exit
|
||||
assert_cmp jnz, raccumulator, false
|
||||
je .error_exit
|
||||
assert_cmp je, amount_read, r9
|
||||
je .error_exit
|
||||
|
||||
; CloseHandle(id_file)
|
||||
wapi_shadow_space
|
||||
mov rcounter, rbase
|
||||
call CloseHandle
|
||||
@ -471,6 +518,7 @@ file_read_contents:
|
||||
mov qword [result + FileOpInfo.content + Slice_Byte.len], 0
|
||||
|
||||
.cleanup:
|
||||
pop file_size
|
||||
pop result
|
||||
pop backing
|
||||
pop rbase
|
||||
|
89
code/asm/hello_files.proj
Normal file
89
code/asm/hello_files.proj
Normal file
@ -0,0 +1,89 @@
|
||||
// raddbg 0.9.18 project file
|
||||
|
||||
recent_file: path: "hello_files.asm"
|
||||
recent_file: path: "../../../code/asm/hello_files.asm"
|
||||
recent_file: path: "../../../WATL_Exercise/c/watl.v0.msvc.c"
|
||||
recent_file: path: "asm/hello_files.asm"
|
||||
recent_file: path: "../hello_files.asm"
|
||||
recent_file: path: "hello_slices.asm"
|
||||
recent_file: path: "hello_nasm.asm"
|
||||
recent_file: path: "../asm"
|
||||
recent_file: path: "../../../../dev/raddbg/minkernel/crts/ucrt/src/appcrt/startup/abort.cpp"
|
||||
recent_file: path: "../../../vefontcache-odin/backend/sokol/backend_sokol.odin"
|
||||
recent_file: path: "../../../vefontcache-odin/examples/sokol_demo/sokol_demo.odin"
|
||||
recent_file: path: "../../../vefontcache-odin/thirdparty/sokol/c/sokol_gfx.h"
|
||||
recent_file: path: "../../../vefontcache-odin/thirdparty/sokol/c/sokol_log.h"
|
||||
recent_file: path: "../../../vefontcache-odin/thirdparty/sokol/c/sokol_app.h"
|
||||
recent_file: path: "D:/a/_work/1/s/src/vctools/crt/vcruntime/src/string/amd64/memcpy.asm"
|
||||
recent_file: path: "D:/a/_work/1/s/src/vctools/crt/vcruntime/src/string/amd64/memset.asm"
|
||||
breakpoint:
|
||||
{
|
||||
source_location: "../../../vefontcache-odin/backend/sokol/backend_sokol.odin:66:1"
|
||||
hit_count: 0
|
||||
}
|
||||
target:
|
||||
{
|
||||
executable: "../../../WATL_Exercise/build/watl.v0.msvc.exe"
|
||||
working_directory: "../../../WATL_Exercise/C"
|
||||
}
|
||||
type_view:
|
||||
{
|
||||
type: Slice_A2_Str8
|
||||
expr: "$.slice()"
|
||||
}
|
||||
type_view:
|
||||
{
|
||||
type: Slice_UTF8
|
||||
expr: "array($.ptr, $.len)"
|
||||
}
|
||||
type_view:
|
||||
{
|
||||
type: Slice_WATL_Node
|
||||
expr: "array($.ptr, $.len)"
|
||||
}
|
||||
type_view:
|
||||
{
|
||||
type: Slice_WATL_Tok
|
||||
expr: "slice($)"
|
||||
}
|
||||
type_view:
|
||||
{
|
||||
type: Slice_KT1CX_Cell_Str8
|
||||
expr: "slice($)"
|
||||
}
|
||||
type_view:
|
||||
{
|
||||
type: Slice_KT1L_Slot_Str8
|
||||
expr: "slice($)"
|
||||
}
|
||||
target:
|
||||
{
|
||||
executable: "../../build/hello_nasm.exe"
|
||||
working_directory: "../../build"
|
||||
}
|
||||
target:
|
||||
{
|
||||
executable: "../../build/hello_slices.exe"
|
||||
working_directory: "../../build"
|
||||
}
|
||||
target:
|
||||
{
|
||||
executable: "../../build/hello_files.exe"
|
||||
working_directory: ../../
|
||||
enabled: 1
|
||||
}
|
||||
breakpoint:
|
||||
{
|
||||
source_location: "hello_slices.asm:60:1"
|
||||
hit_count: 0
|
||||
}
|
||||
breakpoint:
|
||||
{
|
||||
source_location: "hello_files.asm:429:1"
|
||||
hit_count: 1
|
||||
}
|
||||
breakpoint:
|
||||
{
|
||||
source_location: "hello_files.asm:467:1"
|
||||
hit_count: 0
|
||||
}
|
@ -5,19 +5,27 @@ $path_build = join-path $path_root 'build'
|
||||
$path_code = join-path $path_root 'code'
|
||||
$path_asm = join-path $path_code 'asm'
|
||||
$path_toolchain = join-path $path_root 'toolchain'
|
||||
$path_radlink = join-path $path_toolchain 'radlink'
|
||||
$path_rad = join-path $path_toolchain 'rad'
|
||||
|
||||
if ((test-path $path_build) -eq $false) {
|
||||
new-item -itemtype directory -path $path_build
|
||||
}
|
||||
|
||||
$hello_nasm = join-path $path_asm 'hello_files.asm'
|
||||
$listing = join-path $path_build 'hello_files.list'
|
||||
$link_obj = join-path $path_build 'hello_files.o'
|
||||
$exe = join-path $path_build 'hello_files.exe'
|
||||
$unit_name = 'hello_files'
|
||||
|
||||
$unit = join-path $path_asm "$unit_name.asm"
|
||||
$listing = join-path $path_build "$unit_name.asm.list"
|
||||
$link_obj = join-path $path_build "$unit_name.o"
|
||||
$map = join-path $path_build "$unit_name.map"
|
||||
$pdb = join-path $path_build "$unit_name.pdb"
|
||||
$rdi = join-path $path_build "$unit_name.rdi"
|
||||
$rdi_listing = join-path $path_build "$unit_name.rdi.list"
|
||||
$exe = join-path $path_build "$unit_name.exe"
|
||||
|
||||
$nasm = 'nasm'
|
||||
$radlink = join-path $path_radlink 'radlink.exe'
|
||||
$link = 'link.exe'
|
||||
$radbin = join-path $path_rad 'radbin.exe'
|
||||
$radlink = join-path $path_rad 'radlink.exe'
|
||||
|
||||
push-location $path_root
|
||||
$f_assemble_only = '-a'
|
||||
@ -36,37 +44,42 @@ $f_optimize_multi_disp = '-Ov'
|
||||
$f_outfile = '-o '
|
||||
$f_warnings_as_errors = '-Werror'
|
||||
$args = @(
|
||||
$hello_nasm,
|
||||
$unit,
|
||||
$f_optimize_none,
|
||||
# $f_preprocess_only,
|
||||
# ($f_dmacro + "BUILD_DEBUG 1"),
|
||||
$f_bin_fmt_win64,
|
||||
$f_debug_fmt_win64,
|
||||
($f_listing + $listing),
|
||||
($f_outfile + $link_obj)
|
||||
)
|
||||
write-host 'Assembling'
|
||||
& $nasm $args
|
||||
|
||||
$lib_kernel32 = 'kernel32.lib'
|
||||
$lib_msvcrt = 'msvcrt.lib'
|
||||
|
||||
$link = 'link.exe'
|
||||
|
||||
$link_nologo = '/NOLOGO'
|
||||
$link_debug = '/DEBUG:'
|
||||
$link_entrypoint = '/ENTRY:'
|
||||
$link_library = '/'
|
||||
$link_mapfile = '/MAP:'
|
||||
$link_no_incremental = '/INCREMENTAL:NO'
|
||||
$link_large_address_aware = '/LARGEADDRESSAWARE:NO'
|
||||
$link_listing = '/LIST'
|
||||
$link_outfile = '/OUT:'
|
||||
$link_win_machine_64 = '/MACHINE:X64'
|
||||
$link_win_pdb = '/PDB:'
|
||||
$link_win_subsystem_console = '/SUBSYSTEM:CONSOLE'
|
||||
$link_win_subsystem_windows = '/SUBSYSTEM:WINDOWS'
|
||||
$rad_debug = '/RAD_DEBUG'
|
||||
$rad_debug_name = '/RAD_DEBUG_NAME:'
|
||||
$rad_large_pages = '/RAD_LARGE_PAGES:'
|
||||
$args = @(
|
||||
$link_debug,
|
||||
# $rad_debug,
|
||||
# ($link_debug + 'FULL'),
|
||||
$link_nologo,
|
||||
($link_debug + 'FULL'),
|
||||
($link_mapfile + $map),
|
||||
($link_win_pdb + $pdb),
|
||||
# $link_listing,
|
||||
$link_no_incremental,
|
||||
$link_large_address_aware,
|
||||
$link_win_machine_64,
|
||||
$link_win_subsystem_console,
|
||||
@ -76,5 +89,17 @@ $args = @(
|
||||
($link_outfile + $exe),
|
||||
$link_obj
|
||||
)
|
||||
& $radlink $args
|
||||
write-host 'Linking'
|
||||
& $link $args
|
||||
pop-location
|
||||
|
||||
$rbin_out = '--out:'
|
||||
$rbin_dump = '--dump'
|
||||
|
||||
write-host 'Dumping RDI'
|
||||
$args = @($pdb, ($rbin_out + $rdi))
|
||||
& $radbin $args
|
||||
$args = @($rbin_dump, $rdi)
|
||||
$dump = & $radbin $args
|
||||
$dump > $rdi_listing
|
||||
|
||||
|
@ -5,19 +5,26 @@ $path_build = join-path $path_root 'build'
|
||||
$path_code = join-path $path_root 'code'
|
||||
$path_asm = join-path $path_code 'asm'
|
||||
$path_toolchain = join-path $path_root 'toolchain'
|
||||
$path_radlink = join-path $path_toolchain 'radlink'
|
||||
$path_rad = join-path $path_toolchain 'rad'
|
||||
|
||||
if ((test-path $path_build) -eq $false) {
|
||||
new-item -itemtype directory -path $path_build
|
||||
}
|
||||
|
||||
$hello_nasm = join-path $path_asm 'hello_nasm.asm'
|
||||
$listing = join-path $path_build 'hello_nasm.list'
|
||||
$link_obj = join-path $path_build 'hello_nasm.o'
|
||||
$exe = join-path $path_build 'hello_nasm.exe'
|
||||
$unit_name = 'hello_nasm'
|
||||
|
||||
$unit = join-path $path_asm "$unit_name.asm"
|
||||
$listing = join-path $path_build "$unit_name.list"
|
||||
$link_obj = join-path $path_build "$unit_name.o"
|
||||
$map = join-path $path_build "$unit_name.map"
|
||||
$pdb = join-path $path_build "$unit_name.pdb"
|
||||
$rdi = join-path $path_build "$unit_name.rdi"
|
||||
$exe = join-path $path_build "$unit_name.exe"
|
||||
|
||||
$nasm = 'nasm'
|
||||
$radlink = join-path $path_radlink 'radlink.exe'
|
||||
$link = 'link.exe'
|
||||
$radbin = join-path $path_rad 'radbin.exe'
|
||||
$radlink = join-path $path_rad 'radlink.exe'
|
||||
|
||||
push-location $path_root
|
||||
$f_assemble_only = '-a'
|
||||
@ -36,22 +43,23 @@ $f_optimize_multi_disp = '-Ov'
|
||||
$f_outfile = '-o '
|
||||
$f_warnings_as_errors = '-Werror'
|
||||
$args = @(
|
||||
$hello_nasm,
|
||||
$unit,
|
||||
$f_optimize_none,
|
||||
$f_bin_fmt_win64,
|
||||
$f_debug_fmt_win64,
|
||||
($f_listing + $listing),
|
||||
($f_outfile + $link_obj)
|
||||
)
|
||||
write-host 'Assembling'
|
||||
& $nasm $args
|
||||
|
||||
$lib_kernel32 = 'kernel32.lib'
|
||||
$lib_msvcrt = 'msvcrt.lib'
|
||||
|
||||
$link = 'link.exe'
|
||||
|
||||
$link_nologo = '/NOLOGO'
|
||||
$link_debug = '/DEBUG:'
|
||||
$link_entrypoint = '/ENTRY:'
|
||||
$link_mapfile = '/MAP:'
|
||||
$link_library = '/'
|
||||
$link_outfile = '/OUT:'
|
||||
$link_win_machine_64 = '/MACHINE:X64'
|
||||
@ -61,8 +69,10 @@ $rad_debug = '/RAD_DEBUG'
|
||||
$rad_debug_name = '/RAD_DEBUG_NAME:'
|
||||
$rad_large_pages = '/RAD_LARGE_PAGES:'
|
||||
$args = @(
|
||||
$rad_debug,
|
||||
# ($link_debug + 'FULL'),
|
||||
# $rad_debug,
|
||||
$link_nologo,
|
||||
($link_debug + 'FULL'),
|
||||
($link_mapfile + $map)
|
||||
$link_win_machine_64,
|
||||
$link_win_subsystem_console,
|
||||
$lib_kernel32,
|
||||
@ -71,5 +81,11 @@ $args = @(
|
||||
($link_outfile + $exe),
|
||||
$link_obj
|
||||
)
|
||||
& $radlink $args
|
||||
write-host 'Linking'
|
||||
& $link $args
|
||||
pop-location
|
||||
|
||||
$rbin_out = '--out:'
|
||||
$rbin_dump = '--dump '
|
||||
|
||||
# $radbin
|
||||
|
@ -1 +0,0 @@
|
||||
$nams
|
@ -7,9 +7,12 @@ $path_scripts = join-path $path_root 'scripts'
|
||||
$path_source = join-path $path_root 'source'
|
||||
$path_toolchain = join-path $path_root 'toolchain'
|
||||
|
||||
# Note: No longer using nasm
|
||||
if ($false) {
|
||||
$url_yasm = 'https://github.com/yasm/yasm.git'
|
||||
|
||||
$path_yasm = join-path $path_toolchain 'yasm'
|
||||
$path_libyasm = join-path $path_yasm 'libyasm'
|
||||
|
||||
clone-gitrepo $path_yasm $url_yasm
|
||||
}
|
||||
|
BIN
toolchain/rad/radbin.exe
Normal file
BIN
toolchain/rad/radbin.exe
Normal file
Binary file not shown.
Reference in New Issue
Block a user