libc.obj: Update fasm sample for auto load & linking

git-svn-id: svn://kolibrios.org@9718 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Coldy 2022-02-15 16:43:51 +00:00
parent 143d7b8027
commit d37b797def

View File

@ -1,81 +1,100 @@
format binary as "kex" ; 2022, Edited by Coldy
; Added changes for auto load & linking
use32
org 0x0 format binary as "kex"
db 'MENUET01'
dd 0x01 use32
dd START org 0x0
dd IM_END db 'MENUET01'
dd MEM dd 0x02 ; 2 - for enable autoload feature
dd MEM dd START
dd 0 dd IM_END
dd 0 dd MEM
dd MEM
include '../../../../../macros.inc' dd 0
include '../../../../../proc32.inc' dd 0
include '../../../../../KOSfuncs.inc'
include '../../../../../dll.inc' ; { Begin of KX header (this need for recognition by dll.obj)
;include '../../../../../debug-fdo.inc'
db 'KX',0 ; Signature/Magic
;__DEBUG__ = 1 db 0 ; Revision
;__DEBUG_LEVEL__ = 2 db 1000000b ; Flags0 (user app w/import)
db 0 ; Flags1
START: dw 0 ; Reserved
stdcall dll.Load, @IMPORT
test eax, eax dd @IMPORT ; Pointer to import table
jnz exit
; } End of KX header
cinvoke libc_strlen, test_str1
;DEBUGF 2, "%d", eax include '../../../../../../macros.inc'
mcall SF_SYS_MISC, SSF_MEM_ALLOC, eax include '../../../../../../proc32.inc'
mov [test_str2], eax include '../../../../../../KOSfuncs.inc'
cinvoke libc_sprintf, [test_str2], format_str, str_var, [dec_var], dword [float_var], dword[float_var+4], [hex_var] ; no needed for autolod
cinvoke libc_puts, test_str1 ;include '../../../../../dll.inc'
cinvoke libc_puts, [test_str2] ;include '../../../../../debug-fdo.inc'
cinvoke libc_strcmp, test_str1, [test_str2] ;__DEBUG__ = 1
;__DEBUG_LEVEL__ = 2
test eax, eax
jz print_succ START:
jmp print_fail ; Disabled, dll.obj doing this
;stdcall dll.Load, @IMPORT
print_succ: ;test eax, eax
cinvoke libc_puts, success_msg ;jnz exit
jmp exit
cinvoke libc_strlen, test_str1
print_fail: ;DEBUGF 2, "%d", eax
cinvoke libc_puts, failed_msg mcall SF_SYS_MISC, SSF_MEM_ALLOC, eax
mov [test_str2], eax
exit:
mcall SF_SYS_MISC, SSF_MEM_FREE, [test_str2] cinvoke libc_sprintf, [test_str2], format_str, str_var, [dec_var], dword [float_var], dword[float_var+4], [hex_var]
mcall SF_TERMINATE_PROCESS cinvoke libc_puts, test_str1
cinvoke libc_puts, [test_str2]
; data
cinvoke libc_strcmp, test_str1, [test_str2]
format_str db "%s %d %f 0x%x", 0
test_str1 db "Test 463 -26.432100 0x9d81", 0 test eax, eax
test_str2 dd 0 jz print_succ
jmp print_fail
str_var db "Test",0
dec_var dd 463 print_succ:
float_var dq -26.4321 cinvoke libc_puts, success_msg
hex_var dd 40321 jmp exit
success_msg db "Test successful!", 0 print_fail:
failed_msg db "Test failed!", 0 cinvoke libc_puts, failed_msg
align 4 exit:
mcall SF_SYS_MISC, SSF_MEM_FREE, [test_str2]
@IMPORT: //mcall SF_TERMINATE_PROCESS - disabled, dll.obj also doing this
library libc, 'libc.obj' ret
import libc, \
libc_sprintf, 'sprintf', \ ; data
libc_strcmp, 'strcmp', \
libc_strlen, 'strlen', \ format_str db "%s %d %f 0x%x", 0
libc_puts, 'puts' test_str1 db "Test 463 -26.432100 0x9d81", 0
test_str2 dd 0
IM_END:
align 4 str_var db "Test",0
rb 1024 ; stack dec_var dd 463
MEM: float_var dq -26.4321
hex_var dd 40321
success_msg db "Test successful!", 0
failed_msg db "Test failed!", 0
align 4
@IMPORT:
library libc, 'libc.obj'
import libc, \
libc_sprintf, 'sprintf', \
libc_strcmp, 'strcmp', \
libc_strlen, 'strlen', \
libc_puts, 'puts'
IM_END:
align 4
rb 1024 ; stack
MEM: