[KERNEL] cleaned code and added description of some functions

git-svn-id: svn://kolibrios.org@9911 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Doczom 2023-04-09 18:19:13 +00:00
parent cf0e9867b0
commit 7028e04565
8 changed files with 483 additions and 400 deletions

View File

@ -152,7 +152,7 @@ align 4
xor eax, eax xor eax, eax
inc eax ; error inc eax ; error
.exit_1: .exit_1:
mov [esp + 32], eax mov [esp + SYSCALL_STACK.eax], eax
.exit: .exit:
ret ret
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------

View File

@ -44,12 +44,14 @@ get_debuggee_slot:
cli cli
mov eax, ecx mov eax, ecx
call pid_to_slot call pid_to_slot
;call pid_to_appdata
test eax, eax test eax, eax
jz .ret_bad jz .ret_bad
shl eax, BSF sizeof.APPDATA shl eax, BSF sizeof.APPDATA
push ebx push ebx
mov ebx, [current_slot_idx] mov ebx, [current_slot_idx]
cmp [SLOT_BASE + eax + APPDATA.debugger_slot], ebx cmp [SLOT_BASE + eax + APPDATA.debugger_slot], ebx
;cmp [eax + APPDATA.debugger_slot], ebx
pop ebx pop ebx
jnz .ret_bad jnz .ret_bad
; clc ; automatically ; clc ; automatically
@ -64,6 +66,7 @@ debug_detach:
call get_debuggee_slot call get_debuggee_slot
jc .ret jc .ret
and dword [eax + SLOT_BASE + APPDATA.debugger_slot], 0 and dword [eax + SLOT_BASE + APPDATA.debugger_slot], 0
;and dword [eax + APPDATA.debugger_slot], 0
call do_resume call do_resume
.ret: .ret:
sti sti
@ -74,10 +77,13 @@ debug_terminate:
call get_debuggee_slot call get_debuggee_slot
jc debug_detach.ret jc debug_detach.ret
mov ecx, eax mov ecx, eax
shr ecx, BSF sizeof.APPDATA shr ecx, BSF sizeof.APPDATA
;movzx ecx, ch ; del when sysfn_term... will using APPDATA
; push 2 ; push 2
; pop ebx ; pop ebx
mov edx, esi mov edx, esi ; what?
jmp sysfn_terminate jmp sysfn_terminate
debug_suspend: debug_suspend:
@ -93,13 +99,15 @@ debug_suspend:
jc .ret jc .ret
; } End patch ; } End patch
mov cl, [SLOT_BASE + eax + APPDATA.state] ; process state mov cl, [SLOT_BASE + eax + APPDATA.state] ; process state
;mov cl, [eax + APPDATA.state] ; process state
test cl, cl test cl, cl
jz .1 jz .1
cmp cl, 5 cmp cl, TSTATE_WAITING
jnz .ret jnz .ret
mov cl, 2 mov cl, TSTATE_WAIT_SUSPENDED
.2: .2:
mov [SLOT_BASE + eax + APPDATA.state], cl mov [SLOT_BASE + eax + APPDATA.state], cl
;mov [eax + APPDATA.state], cl
.ret: .ret:
sti sti
ret ret
@ -109,13 +117,15 @@ debug_suspend:
do_resume: do_resume:
mov cl, [SLOT_BASE + eax + APPDATA.state] mov cl, [SLOT_BASE + eax + APPDATA.state]
cmp cl, 1 ;mov cl, [eax + APPDATA.state]
cmp cl, TSTATE_RUN_SUSPENDED
jz .1 jz .1
cmp cl, 2 cmp cl, TSTATE_WAIT_SUSPENDED
jnz .ret jnz .ret
mov cl, 5 mov cl, TSTATE_WAITING
.2: .2:
mov [SLOT_BASE + eax + APPDATA.state], cl mov [SLOT_BASE + eax + APPDATA.state], cl
;mov [eax + APPDATA.state], cl
.ret: .ret:
ret ret
.1: .1:
@ -140,7 +150,7 @@ debug_getcontext:
; ecx=pid ; ecx=pid
; edx=sizeof(CONTEXT) ; edx=sizeof(CONTEXT)
; esi->CONTEXT ; esi->CONTEXT
; destroys eax,ebx,ecx,edx,esi,edi ; destroys eax,ebx,ecx,edx,esi,edi, ebp
xor ebx, ebx ; 0 - get only gp regs xor ebx, ebx ; 0 - get only gp regs
cmp edx, 40 cmp edx, 40
@ -156,13 +166,17 @@ debug_getcontext:
jc .ret jc .ret
shr eax, BSF sizeof.APPDATA shr eax, BSF sizeof.APPDATA
;movzx ebp, ah
cmp eax, [fpu_owner] cmp eax, [fpu_owner]
;cmp ebp, [fpu_owner]
jne @f jne @f
inc bh ; set swap context flag inc bh ; set swap context flag
@@: @@:
shl eax, BSF sizeof.APPDATA shl eax, BSF sizeof.APPDATA
mov edi, esi mov edi, esi
mov eax, [SLOT_BASE + eax + APPDATA.pl0_stack] mov eax, [SLOT_BASE + eax + APPDATA.pl0_stack]
;mov eax, [eax + APPDATA.pl0_stack]
lea esi, [eax + RING0_STACK_SIZE] lea esi, [eax + RING0_STACK_SIZE]
.ring0: .ring0:
@ -232,6 +246,7 @@ debug_setcontext:
jc .stiret jc .stiret
; mov esi, edx ; mov esi, edx
mov eax, [eax + SLOT_BASE+APPDATA.pl0_stack] mov eax, [eax + SLOT_BASE+APPDATA.pl0_stack]
;mov eax, [eax + APPDATA.pl0_stack]
lea edi, [eax + RING0_STACK_SIZE] lea edi, [eax + RING0_STACK_SIZE]
.ring0: .ring0:
@ -268,6 +283,7 @@ debug_set_drx:
jc .errret jc .errret
mov ebp, eax mov ebp, eax
lea eax, [eax + SLOT_BASE + APPDATA.dbg_regs] lea eax, [eax + SLOT_BASE + APPDATA.dbg_regs]
;lea eax, [eax + APPDATA.dbg_regs]
; [eax]=dr0, [eax+4]=dr1, [eax+8]=dr2, [eax+C]=dr3 ; [eax]=dr0, [eax+4]=dr1, [eax+8]=dr2, [eax+C]=dr3
; [eax+10]=dr7 ; [eax+10]=dr7
cmp esi, OS_BASE cmp esi, OS_BASE
@ -295,17 +311,18 @@ debug_set_drx:
; imul eax, ebp, tss_step/32 ; imul eax, ebp, tss_step/32
; and byte [eax + tss_data + TSS._trap], not 1 ; and byte [eax + tss_data + TSS._trap], not 1
and [SLOT_BASE + ebp + APPDATA.dbg_state], not 1 and [SLOT_BASE + ebp + APPDATA.dbg_state], not 1
;and [ebp + APPDATA.dbg_state], not 1
.okret: .okret:
and dword [esp+32], 0 and dword [esp + SYSCALL_STACK.eax], 0
sti sti
ret ret
.errret: .errret:
sti sti
mov dword [esp+32], 1 mov dword [esp + SYSCALL_STACK.eax], 1
ret ret
.errret2: .errret2:
sti sti
mov dword [esp+32], 2 mov dword [esp + SYSCALL_STACK.eax], 2
ret ret
.new: .new:
; add new breakpoint ; add new breakpoint
@ -342,6 +359,7 @@ debug_set_drx:
; imul eax, ebp, tss_step/32 ; imul eax, ebp, tss_step/32
; or byte [eax + tss_data + TSS._trap], 1 ; or byte [eax + tss_data + TSS._trap], 1
or [SLOT_BASE + ebp + APPDATA.dbg_state], 1 or [SLOT_BASE + ebp + APPDATA.dbg_state], 1
;or [ebp + APPDATA.dbg_state], 1
jmp .okret jmp .okret
debug_read_process_memory: debug_read_process_memory:
@ -355,13 +373,14 @@ debug_read_process_memory:
call get_debuggee_slot call get_debuggee_slot
jc .err jc .err
shr eax, BSF sizeof.APPDATA shr eax, BSF sizeof.APPDATA
;movzx eax,ah
mov ecx, edi mov ecx, edi
call read_process_memory call read_process_memory
sti sti
mov dword [esp+32], eax mov dword [esp + SYSCALL_STACK.eax], eax
ret ret
.err: .err:
or dword [esp+32], -1 or dword [esp + SYSCALL_STACK.eax], -1
ret ret
debug_write_process_memory: debug_write_process_memory:
@ -375,10 +394,11 @@ debug_write_process_memory:
call get_debuggee_slot call get_debuggee_slot
jc debug_read_process_memory.err jc debug_read_process_memory.err
shr eax, BSF sizeof.APPDATA shr eax, BSF sizeof.APPDATA
;movzx eax,ah
mov ecx, edi mov ecx, edi
call write_process_memory call write_process_memory
sti sti
mov [esp+32], eax mov [esp + SYSCALL_STACK.eax], eax
ret ret
debugger_notify: debugger_notify:

View File

@ -392,7 +392,7 @@ proc create_trampoline_pgmap
stdcall kernel_alloc, PAGE_SIZE stdcall kernel_alloc, PAGE_SIZE
mov edi, eax mov edi, eax
mov esi, master_tab mov esi, master_tab
mov ecx, 1024 mov ecx, PAGE_SIZE/4
rep movsd rep movsd
mov ecx, [master_tab + (OS_BASE shr 20)] mov ecx, [master_tab + (OS_BASE shr 20)]
mov [eax], ecx mov [eax], ecx
@ -419,12 +419,12 @@ proc new_mem_resize stdcall, new_size:dword
mov edi, [new_size] mov edi, [new_size]
add edi, PAGE_SIZE-1 add edi, PAGE_SIZE-1
and edi, not 4095 and edi, -PAGE_SIZE
mov [new_size], edi mov [new_size], edi
mov esi, [ebx + PROC.mem_used] mov esi, [ebx + PROC.mem_used]
add esi, PAGE_SIZE-1 add esi, PAGE_SIZE-1
and esi, not 4095 and esi, -PAGE_SIZE
cmp edi, esi cmp edi, esi
ja .expand ja .expand

View File

@ -1071,4 +1071,35 @@ get_curr_slot:
mov eax, [current_slot] mov eax, [current_slot]
ret ret
pid_to_appdata:
;Input:
; eax - pid of process
;Output:
; eax - 0 - not found or pointer on APPDATA
push ebx
push ecx
mov ebx, [thread_count]
shl ebx, BSF sizeof.APPDATA ; multiply by size
; skip first process in the task table
.loop:
add ecx, sizeof.APPDATA
cmp [SLOT_BASE + ecx + APPDATA.state], TSTATE_FREE
jz .loop ;skip empty slots
cmp [SLOT_BASE + ecx + APPDATA.tid], eax
jz .pid_found
;ecx = offset of current process info entry
;ebx = maximum permitted offset
cmp ecx, ebx
jb .loop
pop ecx
pop ebx
xor eax, eax
ret
.pid_found:
mov eax, ecx
pop ecx
pop ebx
ret
include "debug.inc" include "debug.inc"

View File

@ -20,9 +20,45 @@ struct SYS_BUTTON
id_hi dw ? id_hi dw ?
dw ? dw ?
ends ends
;--------------------------------------------------------------- ;---------------------------------------------------------------
syscall_button: ;////////////// system function 8 ////////////// align 4
; @brief system function 17 - Get the identifier of the pressed button
; @param eax 17 - number function
; @return eax = 1 - buffer empty,
; eax = high 24 bits contain button identifier,
; al = 0 - the button was pressed with left mouse button,
; al = bit corresponding to used mouse button otherwise
sys_getbutton:
mov ebx, [current_slot_idx] ; TOP OF WINDOW STACK
mov [esp + SYSCALL_STACK.eax], dword 1
movzx ecx, word [WIN_STACK + ebx * 2]
mov edx, [thread_count] ; less than 256 processes
cmp ecx, edx
jne .exit
movzx eax, byte [BTN_COUNT]
test eax, eax
jz .exit
mov eax, [BTN_BUFF]
and al, 0xFE ; delete left button bit
mov [BTN_COUNT], byte 0
mov [esp + SYSCALL_STACK.eax], eax
;--------------------------------------
align 4
.exit:
ret
;---------------------------------------------------------------
; @brief system function 8 - define/delete the button
; @param eax = 8 - number function
; @param ebx = [offset_x]*65536 + [width]
; @param ecx = [offset_y]*65536 + [height]
; @param edx = 0xXYnnnnnn, where:
; nnnnnn = identifier of the button
; 31 bit - delete button
; 30 bit - don't draw button
; 29 bit - don't draw button frame when pressed
; @param esi = 0x00RRGGBB - button color
; @return function does not return value
syscall_button:
;--------------------------------------------------------------- ;---------------------------------------------------------------
;? Define/undefine GUI button object ;? Define/undefine GUI button object
;--------------------------------------------------------------- ;---------------------------------------------------------------

View File

@ -277,7 +277,7 @@ dd .setSkinUnicode
.getCaptionHeight: .getCaptionHeight:
mov eax, [_skinh] mov eax, [_skinh]
mov [esp + 32], eax mov [esp + SYSCALL_STACK.eax], eax
ret ret
.getScreenWorkingArea: .getScreenWorkingArea:

View File

@ -102,6 +102,9 @@ hotkey_do_test:
ret ret
;--------------------------------------------------------------------- ;---------------------------------------------------------------------
align 4 align 4
; @brief Export function - Add new scancode in buffer
; @param ecx - scancode
; @return not return
set_keyboard_data: set_keyboard_data:
movzx eax, word[thread_count]; top window process movzx eax, word[thread_count]; top window process
movzx eax, word[WIN_POS + eax*2] movzx eax, word[WIN_POS + eax*2]
@ -122,6 +125,7 @@ prev dd ?
functions dd ? functions dd ?
userdata dd ? userdata dd ?
ends ends
struct KBDFUNC struct KBDFUNC
strucsize dd ? strucsize dd ?
close dd ? close dd ?
@ -137,6 +141,10 @@ uglobal
keyboard_list_mutex MUTEX keyboard_list_mutex MUTEX
endg endg
; @brief Export function - Registration new keyboard
; @param [esp + 4] - pointer on KBDFUNC this keyboard
; @param [esp + 8] - userdata for callback function
; @return eax = pointer on KEYBOARD structure or 0 on error
register_keyboard: register_keyboard:
push ebx push ebx
movi eax, sizeof.KEYBOARD movi eax, sizeof.KEYBOARD
@ -171,6 +179,9 @@ register_keyboard:
pop ebx pop ebx
ret 8 ret 8
; @brief Export function - Delete keyboard
; @param [esp + 4] - pointer on KEYBOARD structure
; @return not return
delete_keyboard: delete_keyboard:
push ebx push ebx
mov ebx, [esp+4+4] mov ebx, [esp+4+4]
@ -577,3 +588,248 @@ iglobal
numlock_map db '789-456+1230.' numlock_map db '789-456+1230.'
endg endg
;--------------------------------------------------------------------- ;---------------------------------------------------------------------
align 4
kb_write_wait_ack:
push ecx edx
mov dl, al
mov ecx, 0x1ffff; last 0xffff, new value in view of fast CPU's
.wait_output_ready:
in al, 0x64
test al, 2
jz @f
loop .wait_output_ready
mov ah, 1
jmp .nothing
@@:
mov al, dl
out 0x60, al
mov ecx, 0xfffff; last 0xffff, new value in view of fast CPU's
.wait_ack:
in al, 0x64
test al, 1
jnz @f
loop .wait_ack
mov ah, 1
jmp .nothing
@@:
in al, 0x60
xor ah, ah
.nothing:
pop edx ecx
ret
;-----------------------------------------------------------------------------
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 66 sys function. ;;
;; in eax=66,ebx in [0..5],ecx,edx ;;
;; out eax ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
iglobal
align 4
f66call:
dd sys_process_def.1 ; 1 = set keyboard mode
dd sys_process_def.2 ; 2 = get keyboard mode
dd sys_process_def.3 ; 3 = get keyboard ctrl, alt, shift
dd sys_process_def.4 ; 4 = set system-wide hotkey
dd sys_process_def.5 ; 5 = delete installed hotkey
dd sys_process_def.6 ; 6 = disable input, work only hotkeys
dd sys_process_def.7 ; 7 = enable input, opposition to f.66.6
endg
;-----------------------------------------------------------------------------
align 4
sys_process_def:
dec ebx
cmp ebx, 7
jae .not_support ;if >=8 then or eax,-1
mov edi, [current_slot]
jmp dword [f66call + ebx*4]
.not_support:
or [esp + SYSCALL_STACK.eax], -1
ret
;-----------------------------------------------------------------------------
align 4
.1:
mov [edi + APPDATA.keyboard_mode], cl
ret
;-----------------------------------------------------------------------------
align 4
.2: ; 2 = get keyboard mode
movzx eax, byte [edi + APPDATA.keyboard_mode]
mov [esp + SYSCALL_STACK.eax], eax
ret
;-----------------------------------------------------------------------------
align 4
.3: ;3 = get keyboard ctrl, alt, shift
mov eax, [kb_state]
mov [esp + SYSCALL_STACK.eax], eax
ret
;-----------------------------------------------------------------------------
align 4
.4:
mov edi, [current_slot_idx]
mov eax, hotkey_list
@@:
cmp dword [eax + 8], 0
jz .found_free
add eax, 16
cmp eax, hotkey_list+16*256
jb @b
mov dword [esp + SYSCALL_STACK.eax], 1
ret
.found_free:
mov [eax + 8], edi
mov [eax + 4], edx
movzx ecx, cl
lea ecx, [hotkey_scancodes+ecx*4]
mov edx, [ecx]
mov [eax], edx
mov [ecx], eax
mov [eax + 12], ecx
test edx, edx
jz @f
mov [edx + 12], eax
@@:
and dword [esp + SYSCALL_STACK.eax], 0
ret
;-----------------------------------------------------------------------------
align 4
.5:
mov edi, [current_slot_idx]
movzx ebx, cl
lea ebx, [hotkey_scancodes+ebx*4]
mov eax, [ebx]
.scan:
test eax, eax
jz .notfound
cmp [eax + 8], edi
jnz .next
cmp [eax + 4], edx
jz .found
.next:
mov eax, [eax]
jmp .scan
.notfound:
mov dword [esp + SYSCALL_STACK.eax], 1
ret
.found:
mov ecx, [eax]
jecxz @f
mov edx, [eax + 12]
mov [ecx + 12], edx
@@:
mov ecx, [eax + 12]
mov edx, [eax]
mov [ecx], edx
xor edx, edx
mov [eax + 4], edx
mov [eax + 8], edx
mov [eax + 12], edx
mov [eax], edx
mov [esp + SYSCALL_STACK.eax], edx
ret
;-----------------------------------------------------------------------------
align 4
.6:
pushfd
cli
mov eax, [PID_lock_input]
test eax, eax
jnz @f
; get current PID
mov eax, [current_slot]
mov eax, [eax + APPDATA.tid]
; set current PID for lock input
mov [PID_lock_input], eax
@@:
popfd
ret
;-----------------------------------------------------------------------------
align 4
.7:
mov eax, [PID_lock_input]
test eax, eax
jz @f
; get current PID
mov ebx, [current_slot]
mov ebx, [ebx + APPDATA.tid]
; compare current lock input with current PID
cmp ebx, eax
jne @f
xor eax, eax
mov [PID_lock_input], eax
@@:
ret
;-----------------------------------------------------------------------------
uglobal
PID_lock_input dd 0x0
endg
;-----------------------------------------------------------------------------
align 4
; @brief System function 2 - Get pressed key
; @param eax = 2- number function
; @return eax = 1 - buffer empty, else
; al = 0, ah = code pressed key,
; 16-23 bits - scancode pressed key(in ASCII mode)
; if al=2 ah=scancode pressed key, 16-31 bits - state control keys
sys_getkey:
mov [esp + SYSCALL_STACK.eax], dword 1
; test main buffer
mov ebx, [current_slot_idx] ; TOP OF WINDOW STACK
movzx ecx, word [WIN_STACK + ebx * 2]
mov edx, [thread_count]
cmp ecx, edx
jne .finish
cmp [KEY_COUNT], byte 0
je .finish
movzx ax, byte [KEY_BUFF + 120 + 2]
shl eax, 8
mov al, byte [KEY_BUFF]
shl eax, 8
push eax
dec byte [KEY_COUNT]
and byte [KEY_COUNT], 127
movzx ecx, byte [KEY_COUNT]
add ecx, 2
mov eax, KEY_BUFF + 1
mov ebx, KEY_BUFF
call memmove
add eax, 120 + 2
add ebx, 120 + 2
call memmove
pop eax
;--------------------------------------
align 4
.ret_eax:
mov [esp + SYSCALL_STACK.eax], eax
ret
;--------------------------------------
align 4
.finish:
; test hotkeys buffer
mov ecx, hotkey_buffer
;--------------------------------------
align 4
@@:
cmp [ecx], ebx
jz .found
add ecx, 8
cmp ecx, hotkey_buffer + 120 * 8
jb @b
ret
;--------------------------------------
align 4
.found:
mov ax, [ecx + 6]
shl eax, 16
mov ah, [ecx + 4]
mov al, 2
and dword [ecx + 4], 0
and dword [ecx], 0
jmp .ret_eax
;------------------------------------------------------------------------------

View File

@ -1073,14 +1073,11 @@ if preboot_blogesc
end if end if
mov [timer_ticks_enable], 1 ; for cd driver mov [timer_ticks_enable], 1 ; for cd driver
sti sti
call mtrr_validate call mtrr_validate
jmp osloop jmp osloop
; Fly :) ; Fly :)
uglobal uglobal
@ -1266,13 +1263,13 @@ idle_thread:
; Beware. Don't do anything here. Anything at all. ; Beware. Don't do anything here. Anything at all.
idle_loop: idle_loop:
cmp [use_mwait_for_idle], 0 cmp [use_mwait_for_idle], 0
jnz idle_loop_mwait jnz .mwait
idle_loop_hlt: .hlt:
hlt hlt
jmp idle_loop_hlt jmp .hlt
idle_loop_mwait: .mwait:
mov eax, idle_addr mov eax, idle_addr
xor ecx, ecx xor ecx, ecx
xor edx, edx xor edx, edx
@ -1280,7 +1277,7 @@ idle_loop_mwait:
xor ecx, ecx xor ecx, ecx
mov eax, 20h ; or 10h mov eax, 20h ; or 10h
mwait mwait
jmp idle_loop_mwait jmp .mwait
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -1334,9 +1331,9 @@ endg
set_variables: set_variables:
mov ecx, 0x16 ; flush port 0x60 mov ecx, 0x16 ; flush port 0x60
.fl60: @@:
in al, 0x60 in al, 0x60
loop .fl60 loop @b
push eax push eax
mov ax, [BOOT.y_res] mov ax, [BOOT.y_res]
@ -1403,30 +1400,31 @@ display_number_force:
and eax, 0x3fffffff and eax, 0x3fffffff
cmp eax, 0xffff ; length > 0 ? cmp eax, 0xffff ; length > 0 ?
pop eax pop eax
jge cont_displ jge .cont_displ
ret ret
cont_displ: .cont_displ:
push eax push eax
and eax, 0x3fffffff and eax, 0x3fffffff
cmp eax, 61*0x10000 ; length <= 60 ? cmp eax, 61*0x10000 ; length <= 60 ?
pop eax pop eax
jb cont_displ2 jb .cont_displ2
ret ret
cont_displ2: .cont_displ2:
pushad pushad
cmp al, 1 ; ecx is a pointer ? cmp al, 1 ; ecx is a pointer ?
jne displnl1 jne @f
mov ebp, ebx mov ebp, ebx
add ebp, 4 add ebp, 4
mov ebp, [ebp + std_application_base_address] mov ebp, [ebp] ;[ebp + std_application_base_address]
mov ebx, [ebx + std_application_base_address] mov ebx, [ebx] ;[ebx + std_application_base_address]
displnl1: @@:
sub esp, 64 sub esp, 64
test ah, ah ; DECIMAL test ah, ah ; DECIMAL
jnz no_display_desnum jnz .no_display_desnum
shr eax, 16 shr eax, 16
and eax, 0xC03f and eax, 0xC03f
; and eax,0x3f ; and eax,0x3f
@ -1437,24 +1435,26 @@ display_number_force:
mov ecx, eax mov ecx, eax
mov eax, ebx mov eax, ebx
mov ebx, 10 mov ebx, 10
d_desnum: @@:
xor edx, edx xor edx, edx
call division_64_bits call division_64_bits
div ebx div ebx
add dl, 48 add dl, 48
mov [edi], dl mov [edi], dl
dec edi dec edi
loop d_desnum loop @b
pop eax pop eax
call normalize_number call normalize_number
call draw_num_text call draw_num_text
add esp, 64 add esp, 64
popad popad
ret ret
no_display_desnum: .no_display_desnum:
cmp ah, 0x01 ; HEXADECIMAL cmp ah, 0x01 ; HEXADECIMAL
jne no_display_hexnum jne .no_display_hexnum
shr eax, 16 shr eax, 16
and eax, 0xC03f and eax, 0xC03f
; and eax,0x3f ; and eax,0x3f
@ -1465,26 +1465,28 @@ display_number_force:
mov ecx, eax mov ecx, eax
mov eax, ebx mov eax, ebx
mov ebx, 16 mov ebx, 16
d_hexnum: @@:
xor edx, edx xor edx, edx
call division_64_bits call division_64_bits
div ebx div ebx
hexletters = __fdo_hexdigits ;hexletters = __fdo_hexdigits
add edx, hexletters add edx, __fdo_hexdigits ;hexletters
mov dl, [edx] mov dl, [edx]
mov [edi], dl mov [edi], dl
dec edi dec edi
loop d_hexnum loop @b
pop eax pop eax
call normalize_number call normalize_number
call draw_num_text call draw_num_text
add esp, 64 add esp, 64
popad popad
ret ret
no_display_hexnum: .no_display_hexnum:
cmp ah, 0x02 ; BINARY cmp ah, 0x02 ; BINARY
jne no_display_binnum jne .no_display_binnum
shr eax, 16 shr eax, 16
and eax, 0xC03f and eax, 0xC03f
; and eax,0x3f ; and eax,0x3f
@ -1495,21 +1497,22 @@ display_number_force:
mov ecx, eax mov ecx, eax
mov eax, ebx mov eax, ebx
mov ebx, 2 mov ebx, 2
d_binnum: @@:
xor edx, edx xor edx, edx
call division_64_bits call division_64_bits
div ebx div ebx
add dl, 48 add dl, 48
mov [edi], dl mov [edi], dl
dec edi dec edi
loop d_binnum loop @b
pop eax pop eax
call normalize_number call normalize_number
call draw_num_text call draw_num_text
add esp, 64 add esp, 64
popad popad
ret ret
no_display_binnum: .no_display_binnum:
add esp, 64 add esp, 64
popad popad
@ -1572,10 +1575,6 @@ draw_num_text:
@@: @@:
jmp dtext jmp dtext
;----------------------------------------------------------------------------- ;-----------------------------------------------------------------------------
iglobal
midi_base dw 0
endg
;-----------------------------------------------------------------------------
align 4 align 4
sys_setup: sys_setup:
; 1 = roland mpu midi base , base io address ; 1 = roland mpu midi base , base io address
@ -1809,8 +1808,60 @@ get_timer_ticks:
mov eax, [timer_ticks] mov eax, [timer_ticks]
ret ret
;----------------------------------------------------------------------------- ;-----------------------------------------------------------------------------
iglobal
midi_base dw 0
endg
is_input: align 4
sys_midi:
cmp word [mididp], 0
jnz @f
mov [esp + SYSCALL_STACK.eax], 1
ret
@@:
and [esp + SYSCALL_STACK.eax], 0
dec ebx
jnz .smn1
; call setuart
@@:
call .is_output
test al, al
jnz @b
mov dx, word [midisp]
mov al, 0xff
out dx, al
@@:
mov dx, word [midisp]
mov al, 0xff
out dx, al
call .is_input
test al, al
jnz @b
call .get_mpu_in
cmp al, 0xfe
jnz @b
@@:
call .is_output
test al, al
jnz @b
mov dx, word [midisp]
mov al, 0x3f
out dx, al
ret
.smn1:
dec ebx
jnz .ret
@@:
call .get_mpu_in
call .is_output
test al, al
jnz @b
mov al, bl
call .put_mpu_out
.ret:
ret
.is_input:
push edx push edx
mov dx, word [midisp] mov dx, word [midisp]
in al, dx in al, dx
@ -1818,7 +1869,7 @@ is_input:
pop edx pop edx
ret ret
is_output: .is_output:
push edx push edx
mov dx, word [midisp] mov dx, word [midisp]
in al, dx in al, dx
@ -1826,71 +1877,22 @@ is_output:
pop edx pop edx
ret ret
get_mpu_in: .get_mpu_in:
push edx push edx
mov dx, word [mididp] mov dx, word [mididp]
in al, dx in al, dx
pop edx pop edx
ret ret
put_mpu_out: .put_mpu_out:
push edx push edx
mov dx, word [mididp] mov dx, word [mididp]
out dx, al out dx, al
pop edx pop edx
ret ret
align 4 ;-----------------------------------------------------------------------------
sys_midi:
cmp [mididp], 0
jnz sm0
mov [esp+36], dword 1
ret
sm0:
and [esp+36], dword 0
dec ebx
jnz smn1
; call setuart
su1:
call is_output
test al, al
jnz su1
mov dx, word [midisp]
mov al, 0xff
out dx, al
su2:
mov dx, word [midisp]
mov al, 0xff
out dx, al
call is_input
test al, al
jnz su2
call get_mpu_in
cmp al, 0xfe
jnz su2
su3:
call is_output
test al, al
jnz su3
mov dx, word [midisp]
mov al, 0x3f
out dx, al
ret
smn1:
dec ebx
jnz smn2
sm10:
call get_mpu_in
call is_output
test al, al
jnz sm10
mov al, bl
call put_mpu_out
smn2:
ret
sys_end: sys_end:
;--------------------------------------
cmp [_display.select_cursor], 0 cmp [_display.select_cursor], 0
je @f je @f
; restore default cursor before killing ; restore default cursor before killing
@ -2028,6 +2030,7 @@ sysfn_terminate: ; 18.2 = TERMINATE
mov eax, [thread_count] mov eax, [thread_count]
shl ecx, BSF sizeof.APPDATA shl ecx, BSF sizeof.APPDATA
add ecx, SLOT_BASE add ecx, SLOT_BASE
mov edx, [ecx + APPDATA.tid] mov edx, [ecx + APPDATA.tid]
cmp byte [ecx + APPDATA.state], TSTATE_FREE cmp byte [ecx + APPDATA.state], TSTATE_FREE
jz .noprocessterminate jz .noprocessterminate
@ -2054,7 +2057,7 @@ sysfn_terminate: ; 18.2 = TERMINATE
; restore default cursor before killing ; restore default cursor before killing
pusha pusha
mov ecx, [esp+32] mov ecx, [esp+32]
shl ecx, 8 shl ecx, BSF sizeof.APPDATA
add ecx, SLOT_BASE add ecx, SLOT_BASE
mov eax, [def_cursor] mov eax, [def_cursor]
cmp [ecx + APPDATA.cursor], eax cmp [ecx + APPDATA.cursor], eax
@ -2078,8 +2081,6 @@ sysfn_terminate: ; 18.2 = TERMINATE
ret ret
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
sysfn_terminate2: sysfn_terminate2:
;lock application_table_status mutex
.table_status:
call lock_application_table call lock_application_table
mov eax, ecx mov eax, ecx
call pid_to_slot call pid_to_slot
@ -2247,16 +2248,16 @@ sysfn_getactive: ; 18.7 = get active window
sysfn_sound_flag: ; 18.8 = get/set sound_flag sysfn_sound_flag: ; 18.8 = get/set sound_flag
; cmp ecx,1 ; cmp ecx,1
dec ecx dec ecx
jnz nogetsoundflag jnz .set_flag
movzx eax, byte [sound_flag]; get sound_flag movzx eax, byte [sound_flag]; get sound_flag
mov [esp + SYSCALL_STACK.eax], eax mov [esp + SYSCALL_STACK.eax], eax
ret ret
nogetsoundflag: .set_flag:
; cmp ecx,2 ; cmp ecx,2
dec ecx dec ecx
jnz nosoundflag jnz .err
xor byte [sound_flag], 1 xor byte [sound_flag], 1
nosoundflag: .err:
ret ret
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
sysfn_minimize: ; 18.10 = minimize window sysfn_minimize: ; 18.10 = minimize window
@ -2295,12 +2296,11 @@ sysfn_getversion: ; 18.13 = get kernel ID and version
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
sysfn_waitretrace: ; 18.14 = sys wait retrace sysfn_waitretrace: ; 18.14 = sys wait retrace
;wait retrace functions ;wait retrace functions
sys_wait_retrace:
mov edx, 0x3da mov edx, 0x3da
WaitRetrace_loop: .loop:
in al, dx in al, dx
test al, 1000b test al, 1000b
jz WaitRetrace_loop jz .loop
and [esp + SYSCALL_STACK.eax], dword 0 and [esp + SYSCALL_STACK.eax], dword 0
ret ret
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
@ -2490,84 +2490,6 @@ sys_cachetodiskette:
mov [esp + SYSCALL_STACK.eax], dword 1 mov [esp + SYSCALL_STACK.eax], dword 1
ret ret
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
align 4
sys_getkey:
mov [esp + SYSCALL_STACK.eax], dword 1
; test main buffer
mov ebx, [current_slot_idx] ; TOP OF WINDOW STACK
movzx ecx, word [WIN_STACK + ebx * 2]
mov edx, [thread_count]
cmp ecx, edx
jne .finish
cmp [KEY_COUNT], byte 0
je .finish
movzx ax, byte [KEY_BUFF + 120 + 2]
shl eax, 8
mov al, byte [KEY_BUFF]
shl eax, 8
push eax
dec byte [KEY_COUNT]
and byte [KEY_COUNT], 127
movzx ecx, byte [KEY_COUNT]
add ecx, 2
mov eax, KEY_BUFF + 1
mov ebx, KEY_BUFF
call memmove
add eax, 120 + 2
add ebx, 120 + 2
call memmove
pop eax
;--------------------------------------
align 4
.ret_eax:
mov [esp + SYSCALL_STACK.eax], eax
ret
;--------------------------------------
align 4
.finish:
; test hotkeys buffer
mov ecx, hotkey_buffer
;--------------------------------------
align 4
@@:
cmp [ecx], ebx
jz .found
add ecx, 8
cmp ecx, hotkey_buffer + 120 * 8
jb @b
ret
;--------------------------------------
align 4
.found:
mov ax, [ecx + 6]
shl eax, 16
mov ah, [ecx + 4]
mov al, 2
and dword [ecx + 4], 0
and dword [ecx], 0
jmp .ret_eax
;------------------------------------------------------------------------------
align 4
sys_getbutton:
mov ebx, [current_slot_idx] ; TOP OF WINDOW STACK
mov [esp + SYSCALL_STACK.eax], dword 1
movzx ecx, word [WIN_STACK + ebx * 2]
mov edx, [thread_count] ; less than 256 processes
cmp ecx, edx
jne .exit
movzx eax, byte [BTN_COUNT]
test eax, eax
jz .exit
mov eax, [BTN_BUFF]
and al, 0xFE ; delete left button bit
mov [BTN_COUNT], byte 0
mov [esp + SYSCALL_STACK.eax], eax
;--------------------------------------
align 4
.exit:
ret
;------------------------------------------------------------------------------
align 4 align 4
sys_cpuusage: sys_cpuusage:
@ -3308,7 +3230,7 @@ calculatebackground: ; background
mov ecx, [_display.win_map_size] mov ecx, [_display.win_map_size]
shr ecx, 2 shr ecx, 2
rep stosd rep stosd
mov byte[window_data + 32 + WDATA.z_modif], ZPOS_DESKTOP mov byte[window_data + sizeof.WDATA + WDATA.z_modif], ZPOS_DESKTOP
mov [REDRAW_BACKGROUND], 0 mov [REDRAW_BACKGROUND], 0
ret ret
;----------------------------------------------------------------------------- ;-----------------------------------------------------------------------------
@ -4037,41 +3959,6 @@ putimage_get16bpp:
; call [draw_pointer] ; call [draw_pointer]
; ret ; ret
;----------------------------------------------------------------------------- ;-----------------------------------------------------------------------------
align 4
kb_write_wait_ack:
push ecx edx
mov dl, al
mov ecx, 0x1ffff; last 0xffff, new value in view of fast CPU's
.wait_output_ready:
in al, 0x64
test al, 2
jz @f
loop .wait_output_ready
mov ah, 1
jmp .nothing
@@:
mov al, dl
out 0x60, al
mov ecx, 0xfffff; last 0xffff, new value in view of fast CPU's
.wait_ack:
in al, 0x64
test al, 1
jnz @f
loop .wait_ack
mov ah, 1
jmp .nothing
@@:
in al, 0x60
xor ah, ah
.nothing:
pop edx ecx
ret
;-----------------------------------------------------------------------------
if used _rdtsc if used _rdtsc
_rdtsc: _rdtsc:
bt [cpu_caps], CAPS_TSC bt [cpu_caps], CAPS_TSC
@ -4241,153 +4128,6 @@ end if
mov [esp + SYSCALL_STACK.ebx], 1 mov [esp + SYSCALL_STACK.ebx], 1
ret ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 66 sys function. ;;
;; in eax=66,ebx in [0..5],ecx,edx ;;
;; out eax ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
iglobal
align 4
f66call:
dd sys_process_def.1 ; 1 = set keyboard mode
dd sys_process_def.2 ; 2 = get keyboard mode
dd sys_process_def.3 ; 3 = get keyboard ctrl, alt, shift
dd sys_process_def.4 ; 4 = set system-wide hotkey
dd sys_process_def.5 ; 5 = delete installed hotkey
dd sys_process_def.6 ; 6 = disable input, work only hotkeys
dd sys_process_def.7 ; 7 = enable input, opposition to f.66.6
endg
;-----------------------------------------------------------------------------
align 4
sys_process_def:
dec ebx
cmp ebx, 7
jae .not_support ;if >=8 then or eax,-1
mov edi, [current_slot]
jmp dword [f66call + ebx*4]
.not_support:
or [esp + SYSCALL_STACK.eax], -1
ret
;-----------------------------------------------------------------------------
align 4
.1:
mov [edi + APPDATA.keyboard_mode], cl
ret
;-----------------------------------------------------------------------------
align 4
.2: ; 2 = get keyboard mode
movzx eax, byte [edi + APPDATA.keyboard_mode]
mov [esp + SYSCALL_STACK.eax], eax
ret
;-----------------------------------------------------------------------------
align 4
.3: ;3 = get keyboard ctrl, alt, shift
mov eax, [kb_state]
mov [esp + SYSCALL_STACK.eax], eax
ret
;-----------------------------------------------------------------------------
align 4
.4:
mov edi, [current_slot_idx]
mov eax, hotkey_list
@@:
cmp dword [eax + 8], 0
jz .found_free
add eax, 16
cmp eax, hotkey_list+16*256
jb @b
mov dword [esp + SYSCALL_STACK.eax], 1
ret
.found_free:
mov [eax + 8], edi
mov [eax + 4], edx
movzx ecx, cl
lea ecx, [hotkey_scancodes+ecx*4]
mov edx, [ecx]
mov [eax], edx
mov [ecx], eax
mov [eax + 12], ecx
test edx, edx
jz @f
mov [edx + 12], eax
@@:
and dword [esp + SYSCALL_STACK.eax], 0
ret
;-----------------------------------------------------------------------------
align 4
.5:
mov edi, [current_slot_idx]
movzx ebx, cl
lea ebx, [hotkey_scancodes+ebx*4]
mov eax, [ebx]
.scan:
test eax, eax
jz .notfound
cmp [eax + 8], edi
jnz .next
cmp [eax + 4], edx
jz .found
.next:
mov eax, [eax]
jmp .scan
.notfound:
mov dword [esp + SYSCALL_STACK.eax], 1
ret
.found:
mov ecx, [eax]
jecxz @f
mov edx, [eax + 12]
mov [ecx + 12], edx
@@:
mov ecx, [eax + 12]
mov edx, [eax]
mov [ecx], edx
xor edx, edx
mov [eax + 4], edx
mov [eax + 8], edx
mov [eax + 12], edx
mov [eax], edx
mov [esp + SYSCALL_STACK.eax], edx
ret
;-----------------------------------------------------------------------------
align 4
.6:
pushfd
cli
mov eax, [PID_lock_input]
test eax, eax
jnz @f
; get current PID
mov eax, [current_slot]
mov eax, [eax + APPDATA.tid]
; set current PID for lock input
mov [PID_lock_input], eax
@@:
popfd
ret
;-----------------------------------------------------------------------------
align 4
.7:
mov eax, [PID_lock_input]
test eax, eax
jz @f
; get current PID
mov ebx, [current_slot]
mov ebx, [ebx + APPDATA.tid]
; compare current lock input with current PID
cmp ebx, eax
jne @f
xor eax, eax
mov [PID_lock_input], eax
@@:
ret
;-----------------------------------------------------------------------------
uglobal
PID_lock_input dd 0x0
endg
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 61 sys function. ;; ;; 61 sys function. ;;
;; in eax=61,ebx in [1..3] ;; ;; in eax=61,ebx in [1..3] ;;
@ -4737,7 +4477,7 @@ sys_apm:
inc eax inc eax
or dword [esp + 44], eax ; error or dword [esp + 44], eax ; error
add eax, 7 add eax, 7
mov dword [esp + 32], eax ; 32-bit protected-mode interface not supported mov dword [esp + SYSCALL_STACK.eax], eax ; 32-bit protected-mode interface not supported
ret ret
@@: @@:
@ -4748,9 +4488,9 @@ sys_apm:
ja @f ja @f
and [esp + 44], byte 0xfe ; emulate func 0..3 as func 0 and [esp + 44], byte 0xfe ; emulate func 0..3 as func 0
mov eax, [apm_vf] mov eax, [apm_vf]
mov [esp + 32], eax mov [esp + SYSCALL_STACK.eax], eax
shr eax, 16 shr eax, 16
mov [esp + 28], eax mov [esp + SYSCALL_STACK.ecx], eax
ret ret
@@: @@:
@ -4769,12 +4509,12 @@ sys_apm:
mov cr3, eax mov cr3, eax
pop eax pop eax
mov [esp + 4 ], edi mov [esp + SYSCALL_STACK.edi], edi
mov [esp + 8], esi mov [esp + SYSCALL_STACK.esi], esi
mov [esp + 20], ebx mov [esp + SYSCALL_STACK.ebx], ebx
mov [esp + 24], edx mov [esp + SYSCALL_STACK.edx], edx
mov [esp + 28], ecx mov [esp + SYSCALL_STACK.ecx], ecx
mov [esp + 32], eax mov [esp + SYSCALL_STACK.eax], eax
setc al setc al
and [esp + 44], byte 0xfe and [esp + 44], byte 0xfe
or [esp + 44], al or [esp + 44], al