diff --git a/kernel/branches/net/blkdev/cd_drv.inc b/kernel/branches/net/blkdev/cd_drv.inc index 7585e677c2..38f7c90684 100644 --- a/kernel/branches/net/blkdev/cd_drv.inc +++ b/kernel/branches/net/blkdev/cd_drv.inc @@ -12,7 +12,7 @@ $Revision$ ; Непосредственная работа с устройством СD (ATAPI) ;********************************************************** ; Автор части исходного текста Кулаков Владимир Геннадьевич -; Адаптация, доработка и разработка Mario79 +; Адаптация, доработка и разработка Mario79, ; Максимальное количество повторений операции чтения MaxRetr equ 10 @@ -20,46 +20,7 @@ MaxRetr equ 10 ; (в тиках) BSYWaitTime equ 1000 ;2 NoTickWaitTime equ 0xfffff - -;************************************************* -;* ПОЛНОЕ ЧТЕНИЕ СЕКТОРА КОМПАКТ-ДИСКА * -;* Считываются данные пользователя, информация * -;* субканала и контрольная информация * -;* Входные параметры передаются через глобальные * -;* перменные: * -;* ChannelNumber - номер канала; * -;* DiskNumber - номер диска на канале; * -;* CDSectorAddress - адрес считываемого сектора. * -;* Данные считывается в массив CDDataBuf. * -;************************************************* -ReadCD: - pusha -; Задать размер сектора - mov [CDBlockSize],2048 ;2352 -; Очистить буфер пакетной команды - call clear_packet_buffer -; Сформировать пакетную команду для считывания -; сектора данных - ; Задать код команды Read CD - mov [PacketCommand],byte 0x28 ;0xBE - ; Задать адрес сектора - mov AX,word [CDSectorAddress+2] - xchg AL,AH - mov word [PacketCommand+2],AX - mov AX,word [CDSectorAddress] - xchg AL,AH - mov word [PacketCommand+4],AX -; mov eax,[CDSectorAddress] -; mov [PacketCommand+2],eax - ; Задать количество считываемых секторов - mov [PacketCommand+8],byte 1 - ; Задать считывание данных в полном объеме -; mov [PacketCommand+9],byte 0xF8 -; Подать команду - call SendPacketDatCommand - popa - ret - +CDBlockSize equ 2048 ;******************************************** ;* ЧТЕНИЕ СЕКТОРА С ПОВТОРАМИ * ;* Многократное повторение чтения при сбоях * @@ -73,8 +34,9 @@ ReadCDWRetr: mov eax,[CDSectorAddress] mov ebx,[CDDataBuf_pointer] call cd_calculate_cache + xor edi,edi add esi,8 - mov edi,1 + inc edi .hdreadcache: ; cmp dword [esi+4],0 ; empty ; je .nohdcache @@ -128,9 +90,49 @@ ReadCDWRetr_1: mov ECX,MaxRetr @@NextRetr: ; Подать команду - call ReadCD - cmp [DevErrorCode],0 - je @@End_4 +;************************************************* +;* ПОЛНОЕ ЧТЕНИЕ СЕКТОРА КОМПАКТ-ДИСКА * +;* Считываются данные пользователя, информация * +;* субканала и контрольная информация * +;* Входные параметры передаются через глобальные * +;* перменные: * +;* ChannelNumber - номер канала; * +;* DiskNumber - номер диска на канале; * +;* CDSectorAddress - адрес считываемого сектора. * +;* Данные считывается в массив CDDataBuf. * +;************************************************* +;ReadCD: + push ecx +; pusha +; Задать размер сектора +; mov [CDBlockSize],2048 ;2352 +; Очистить буфер пакетной команды + call clear_packet_buffer +; Сформировать пакетную команду для считывания +; сектора данных +; Задать код команды Read CD + mov [PacketCommand],byte 0x28 ;0xBE +; Задать адрес сектора + mov AX,word [CDSectorAddress+2] + xchg AL,AH + mov word [PacketCommand+2],AX + mov AX,word [CDSectorAddress] + xchg AL,AH + mov word [PacketCommand+4],AX +; mov eax,[CDSectorAddress] +; mov [PacketCommand+2],eax +; Задать количество считываемых секторов + mov [PacketCommand+8],byte 1 +; Задать считывание данных в полном объеме +; mov [PacketCommand+9],byte 0xF8 +; Подать команду + call SendPacketDatCommand + pop ecx +; ret + +; cmp [DevErrorCode],0 + test eax,eax + jz @@End_4 or ecx,ecx ;{SPraid.simba} (for cd load) jz @@End_4 @@ -141,8 +143,8 @@ ReadCDWRetr_1: mov eax,NoTickWaitTime .wait: dec eax - cmp eax,0 - je @@NextRetr +; test eax,eax + jz @@NextRetr jmp .wait @@: ; Задержка на 2,5 секунды @@ -154,23 +156,25 @@ ReadCDWRetr_1: ; ja @@Wait loop @@NextRetr @@End_4: + mov dword [DevErrorCode],eax popad ret -; Универсальные процедуры, обеспечивающие выполнение +; Универсальные процедуры, обеспечивающие выполнение ; пакетных команд в режиме PIO ; Максимально допустимое время ожидания реакции ; устройства на пакетную команду (в тиках) -MaxCDWaitTime equ 1000 ;200 ;10 секунд +MaxCDWaitTime equ 1000 ;200 ;10 секунд +uglobal ; Область памяти для формирования пакетной команды PacketCommand: rb 12 ;DB 12 DUP (?) ; Область памяти для приема данных от дисковода ;CDDataBuf DB 4096 DUP (0) ; Размер принимаемого блока данных в байтах -CDBlockSize DW ? +;CDBlockSize DW ? ; Адрес считываемого сектора данных CDSectorAddress: DD ? ; Время начала очередной операции с диском @@ -179,7 +183,7 @@ TickCounter_1 DD 0 WURStartTime DD 0 ; указатель буфера для считывания CDDataBuf_pointer dd 0 - +endg ;**************************************************** ;* ПОСЛАТЬ УСТРОЙСТВУ ATAPI ПАКЕТНУЮ КОМАНДУ, * ;* ПРЕДУСМАТРИВАЮЩУЮ ПЕРЕДАЧУ ОДНОГО СЕКТОРА ДАННЫХ * @@ -190,24 +194,26 @@ CDDataBuf_pointer dd 0 ;* DiskNumber - номер диска на канале; * ;* PacketCommand - 12-байтный командный пакет; * ;* CDBlockSize - размер принимаемого блока данных. * +; return eax DevErrorCode ;**************************************************** SendPacketDatCommand: - pushad - mov [DevErrorCode],0 + xor eax,eax +; mov byte [DevErrorCode],al ; Задать режим CHS - mov [ATAAddressMode],0 + mov byte [ATAAddressMode],al ; Послать ATA-команду передачи пакетной команды - mov [ATAFeatures],0 - mov [ATASectorCount],0 - mov [ATASectorNumber],0 + mov byte [ATAFeatures],al + mov byte [ATASectorCount],al + mov byte [ATASectorNumber],al ; Загрузить размер передаваемого блока - mov AX,[CDBlockSize] - mov [ATACylinder],AX - mov [ATAHead],0 + mov [ATAHead],al +; mov AX,[CDBlockSize] + mov [ATACylinder],CDBlockSize mov [ATACommand],0A0h call SendCommandToHDD_1 - cmp [DevErrorCode],0 ;проверить код ошибки - jne @@End_8 ;закончить, сохранив код ошибки + test eax,eax +; cmp [DevErrorCode],0 ;проверить код ошибки + jnz @@End_8 ;закончить, сохранив код ошибки ; Ожидание готовности дисковода к приему ; пакетной команды @@ -218,8 +224,8 @@ SendPacketDatCommand: cmp [timer_ticks_enable],0 jne @f dec ecx - cmp ecx,0 - je @@Err1_1 +; test ecx,ecx + jz @@Err1_1 jmp .test @@: call change_task @@ -261,8 +267,8 @@ SendPacketDatCommand: cmp [timer_ticks_enable],0 jne @f dec ecx - cmp ecx,0 - je @@Err1_1 +; test ecx,ecx + jz @@Err1_1 jmp .test_1 @@: call change_task @@ -286,7 +292,7 @@ SendPacketDatCommand: mov DX,[ATABasePortAddr] ;порт 1x0h ; Загрузить в счетчик размер блока в байтах xor ecx,ecx - mov CX,[CDBlockSize] + mov CX,CDBlockSize ; Вычислить размер блока в 16-разрядных словах shr CX,1 ;разделить размер блока на 2 ; Принять блок данных @@ -294,21 +300,29 @@ SendPacketDatCommand: cld rep insw sti - ; Успешное завершение приема данных - jmp @@End_8 +; Успешное завершение приема данных +@@End_8: + xor eax,eax + ret ; Записать код ошибки @@Err1_1: - mov [DevErrorCode],1 - jmp @@End_8 + xor eax,eax + inc eax + ret +; mov [DevErrorCode],1 +; ret @@Err6_temp: - mov [DevErrorCode],7 - jmp @@End_8 + mov eax,7 + ret +; mov [DevErrorCode],7 +; ret @@Err6: - mov [DevErrorCode],6 -@@End_8: - popad - ret + mov eax,6 + ret +; mov [DevErrorCode],6 +;@@End_8: +; ret @@ -323,19 +337,21 @@ SendPacketDatCommand: ;*********************************************** SendPacketNoDatCommand: pushad - mov [DevErrorCode],0 + xor eax,eax +; mov byte [DevErrorCode],al ; Задать режим CHS - mov [ATAAddressMode],0 + mov byte [ATAAddressMode],al ; Послать ATA-команду передачи пакетной команды - mov [ATAFeatures],0 - mov [ATASectorCount],0 - mov [ATASectorNumber],0 - mov [ATACylinder],0 - mov [ATAHead],0 + mov byte [ATAFeatures],al + mov byte [ATASectorCount],al + mov byte [ATASectorNumber],al + mov word [ATACylinder],ax + mov byte [ATAHead],al mov [ATACommand],0A0h call SendCommandToHDD_1 - cmp [DevErrorCode],0 ;проверить код ошибки - jne @@End_9 ;закончить, сохранив код ошибки +; cmp [DevErrorCode],0 ;проверить код ошибки + test eax,eax + jnz @@End_9 ;закончить, сохранив код ошибки ; Ожидание готовности дисковода к приему ; пакетной команды mov DX,[ATABasePortAddr] @@ -371,8 +387,8 @@ SendPacketNoDatCommand: mov AX,word [PacketCommand+10] out DX,AX ; sti - cmp [ignore_CD_eject_wait],1 - je @@End_9 + cmp [ignore_CD_eject_wait],1 + je @@clear_DEC ; Ожидание подтверждения приема команды mov DX,[ATABasePortAddr] add DX,7 ;порт 1х7h @@ -391,15 +407,19 @@ SendPacketNoDatCommand: jnz @@Err6_1 test AL,40h ;состояние сигнала DRDY jz @@WaitDevice1_1 - jmp @@End_9 - +@@clear_DEC: + and [DevErrorCode],0 + popad + ret ; Записать код ошибки @@Err1_3: - mov [DevErrorCode],1 + xor eax,eax + inc eax jmp @@End_9 @@Err6_1: - mov [DevErrorCode],6 + mov eax,6 @@End_9: + mov [DevErrorCode],eax popad ret @@ -420,11 +440,11 @@ SendPacketNoDatCommand: ;* в ATABasePortAddr - базовый адрес HDD; * ;* в DevErrorCode - ноль. * ;* При возникновении ошибки в DevErrorCode будет * -;* возвращен код ошибки. * +;* возвращен код ошибки в eax * ;**************************************************** SendCommandToHDD_1: - pushad - mov [DevErrorCode],0 +; pushad +; mov [DevErrorCode],0 not need ; Проверить значение кода режима cmp [ATAAddressMode],1 ja @@Err2_4 @@ -459,8 +479,8 @@ SendCommandToHDD_1: cmp [timer_ticks_enable],0 jne @f dec ecx - cmp ecx,0 - je @@Err1_4 +; test ecx,ecx + jz @@Err1_4 jmp .test @@: call change_task @@ -514,28 +534,35 @@ SendCommandToHDD_1: out DX,AL sti ; Сбросить признак ошибки - mov [DevErrorCode],0 - jmp @@End_10 +; mov [DevErrorCode],0 +@@End_10: + xor eax,eax + ret ; Записать код ошибки @@Err1_4: - mov [DevErrorCode],1 - jmp @@End_10 + xor eax,eax + inc eax +; mov [DevErrorCode],1 + ret @@Err2_4: - mov [DevErrorCode],2 - jmp @@End_10 + mov eax,2 +; mov [DevErrorCode],2 + ret @@Err3_4: - mov [DevErrorCode],3 - jmp @@End_10 + mov eax,3 +; mov [DevErrorCode],3 + ret @@Err4_4: - mov [DevErrorCode],4 - jmp @@End_10 + mov eax,4 +; mov [DevErrorCode],4 + ret @@Err5_4: - mov [DevErrorCode],5 + mov eax,5 +; mov [DevErrorCode],5 ; Завершение работы программы -@@End_10: + ret ; sti - popad - ret +; popad ;************************************************* ;* ОЖИДАНИЕ ГОТОВНОСТИ УСТРОЙСТВА К РАБОТЕ * @@ -563,8 +590,8 @@ WaitUnitReady: cmp [DevErrorCode],0 je @@End_11 dec ecx - cmp ecx,0 - je .Error +; cmp ecx,0 + jz .Error jmp @@SendCommand @@: call change_task @@ -815,14 +842,14 @@ check_ATAPI_device_event: call EjectMedium mov [ignore_CD_eject_wait],0 ret - +iglobal timer_ATAPI_check dd 0 ATAPI_IDE0_lock db 0 ATAPI_IDE1_lock db 0 ATAPI_IDE2_lock db 0 ATAPI_IDE3_lock db 0 ignore_CD_eject_wait db 0 - +endg ;************************************************* ;* Получить сообщение о событии или состоянии * ;* устройства * @@ -896,7 +923,7 @@ Read_TOC: clear_packet_buffer: ; Очистить буфер пакетной команды - mov [PacketCommand],dword 0 - mov [PacketCommand+4],dword 0 - mov [PacketCommand+8],dword 0 + and [PacketCommand],dword 0 + and [PacketCommand+4],dword 0 + and [PacketCommand+8],dword 0 ret diff --git a/kernel/branches/net/boot/bootcode.inc b/kernel/branches/net/boot/bootcode.inc index 8a9c6e2ea5..4cb0dd3d9d 100644 --- a/kernel/branches/net/boot/bootcode.inc +++ b/kernel/branches/net/boot/bootcode.inc @@ -42,7 +42,7 @@ printplain: @@: call putchar lodsb - cmp al, 0 + test al,al jnz @b popa ret diff --git a/kernel/branches/net/boot/preboot.inc b/kernel/branches/net/boot/preboot.inc index 73fbbcfaf5..036ba51c18 100644 --- a/kernel/branches/net/boot/preboot.inc +++ b/kernel/branches/net/boot/preboot.inc @@ -28,7 +28,7 @@ preboot_dma db 0 ; use DMA for access to HDD (1-always, 2-only for read, 3-n preboot_device db 0 ; boot device ; (1-floppy 2-harddisk 3-kernel restart 4-format ram disk) ;!!!! 0 - autodetect !!!! -preboot_blogesc = 0 ; start immediately after bootlog +preboot_blogesc = 0 ; start immediately after bootlog preboot_biosdisk db 0 ; use V86 to access disks through BIOS (1-yes, 2-no) if $>0x200 diff --git a/kernel/branches/net/bus/pci/pci32.inc b/kernel/branches/net/bus/pci/pci32.inc index e9752b2d10..718b94f142 100644 --- a/kernel/branches/net/bus/pci/pci32.inc +++ b/kernel/branches/net/bus/pci/pci32.inc @@ -30,55 +30,66 @@ $Revision$ ; Description ; entry point for system PCI calls ;*************************************************************************** +;mmio_pci_addr equ 0x400 ; set actual PCI address here to activate user-MMIO + align 4 pci_api: - cmp [pci_access_enabled],1 - jne no_pci_access_for_applications + cmp [pci_access_enabled],1 + jne no_pci_access_for_applications - or al,al - jnz pci_fn_1 - ; PCI function 0: get pci version (AH.AL) - movzx eax,word [BOOT_VAR+0x9022] - ret + or al,al + jnz pci_fn_1 + ; PCI function 0: get pci version (AH.AL) + movzx eax,word [BOOT_VAR+0x9022] + ret pci_fn_1: - cmp al,1 - jnz pci_fn_2 + cmp al,1 + jnz pci_fn_2 - ; PCI function 1: get last bus in AL - mov al,[BOOT_VAR+0x9021] - ret + ; PCI function 1: get last bus in AL + mov al,[BOOT_VAR+0x9021] + ret pci_fn_2: - cmp al,2 - jne pci_fn_3 - ; PCI function 2: get pci access mechanism - mov al,[BOOT_VAR+0x9020] - ret + cmp al,2 + jne pci_fn_3 + ; PCI function 2: get pci access mechanism + mov al,[BOOT_VAR+0x9020] + ret pci_fn_3: - cmp al,4 - jz pci_read_reg ;byte - cmp al,5 - jz pci_read_reg ;word - cmp al,6 - jz pci_read_reg ;dword + cmp al,4 + jz pci_read_reg ;byte + cmp al,5 + jz pci_read_reg ;word + cmp al,6 + jz pci_read_reg ;dword - cmp al,8 - jz pci_write_reg ;byte - cmp al,9 - jz pci_write_reg ;word - cmp al,10 - jz pci_write_reg ;dword + cmp al,8 + jz pci_write_reg ;byte + cmp al,9 + jz pci_write_reg ;word + cmp al,10 + jz pci_write_reg ;dword + +if defined mmio_pci_addr + cmp al,11 ; user-level MMIO functions + jz pci_mmio_init + cmp al,12 + jz pci_mmio_map + cmp al,13 + jz pci_mmio_unmap +end if no_pci_access_for_applications: - mov eax,-1 + or eax,-1 - ret + ret ;*************************************************************************** ; Function @@ -96,10 +107,10 @@ pci_fn_3: align 4 pci_make_config_cmd: - shl eax,8 ; move bus to bits 16-23 - mov ax,bx ; combine all + shl eax,8 ; move bus to bits 16-23 + mov ax,bx ; combine all and eax,0xffffff - or eax,0x80000000 + or eax,0x80000000 ret ;*************************************************************************** @@ -116,120 +127,120 @@ pci_make_config_cmd: align 4 pci_read_reg: - cmp byte [BOOT_VAR+0x9020],2 ;what mechanism will we use? - je pci_read_reg_2 + cmp byte [BOOT_VAR+0x9020],2 ;what mechanism will we use? + je pci_read_reg_2 - ; mechanism 1 - push esi ; save register size into ESI - mov esi,eax - and esi,3 + ; mechanism 1 + push esi ; save register size into ESI + mov esi,eax + and esi,3 - call pci_make_config_cmd - mov ebx,eax - ; get current state - mov dx,0xcf8 - in eax, dx - push eax - ; set up addressing to config data - mov eax,ebx - and al,0xfc ; make address dword-aligned - out dx,eax - ; get requested DWORD of config data - mov dl,0xfc - and bl,3 - or dl,bl ; add to port address first 2 bits of register address + call pci_make_config_cmd + mov ebx,eax + ; get current state + mov dx,0xcf8 + in eax, dx + push eax + ; set up addressing to config data + mov eax,ebx + and al,0xfc ; make address dword-aligned + out dx,eax + ; get requested DWORD of config data + mov dl,0xfc + and bl,3 + or dl,bl ; add to port address first 2 bits of register address - or esi,esi - jz pci_read_byte1 - cmp esi,1 - jz pci_read_word1 - cmp esi,2 - jz pci_read_dword1 - jmp pci_fin_read1 + or esi,esi + jz pci_read_byte1 + cmp esi,1 + jz pci_read_word1 + cmp esi,2 + jz pci_read_dword1 + jmp pci_fin_read1 pci_read_byte1: - in al,dx - jmp pci_fin_read1 + in al,dx + jmp pci_fin_read1 pci_read_word1: - in ax,dx - jmp pci_fin_read1 + in ax,dx + jmp pci_fin_read1 pci_read_dword1: - in eax,dx - jmp pci_fin_read1 + in eax,dx + jmp pci_fin_read1 pci_fin_read1: - ; restore configuration control - xchg eax,[esp] - mov dx,0xcf8 - out dx,eax + ; restore configuration control + xchg eax,[esp] + mov dx,0xcf8 + out dx,eax - pop eax - pop esi - ret + pop eax + pop esi + ret pci_read_reg_2: - test bh,128 ;mech#2 only supports 16 devices per bus - jnz pci_read_reg_err + test bh,128 ;mech#2 only supports 16 devices per bus + jnz pci_read_reg_err - push esi ; save register size into ESI - mov esi,eax - and esi,3 + push esi ; save register size into ESI + mov esi,eax + and esi,3 - push eax - ;store current state of config space - mov dx,0xcf8 - in al,dx - mov ah,al - mov dl,0xfa - in al,dx + push eax + ;store current state of config space + mov dx,0xcf8 + in al,dx + mov ah,al + mov dl,0xfa + in al,dx - xchg eax,[esp] - ; out 0xcfa,bus - mov al,ah - out dx,al - ; out 0xcf8,0x80 - mov dl,0xf8 - mov al,0x80 - out dx,al - ; compute addr - shr bh,3 ; func is ignored in mechanism 2 - or bh,0xc0 - mov dx,bx + xchg eax,[esp] + ; out 0xcfa,bus + mov al,ah + out dx,al + ; out 0xcf8,0x80 + mov dl,0xf8 + mov al,0x80 + out dx,al + ; compute addr + shr bh,3 ; func is ignored in mechanism 2 + or bh,0xc0 + mov dx,bx - or esi,esi - jz pci_read_byte2 - cmp esi,1 - jz pci_read_word2 - cmp esi,2 - jz pci_read_dword2 - jmp pci_fin_read2 + or esi,esi + jz pci_read_byte2 + cmp esi,1 + jz pci_read_word2 + cmp esi,2 + jz pci_read_dword2 + jmp pci_fin_read2 pci_read_byte2: - in al,dx - jmp pci_fin_read2 + in al,dx + jmp pci_fin_read2 pci_read_word2: - in ax,dx - jmp pci_fin_read2 + in ax,dx + jmp pci_fin_read2 pci_read_dword2: - in eax,dx + in eax,dx ; jmp pci_fin_read2 pci_fin_read2: - ; restore configuration space - xchg eax,[esp] - mov dx,0xcfa - out dx,al - mov dl,0xf8 - mov al,ah - out dx,al + ; restore configuration space + xchg eax,[esp] + mov dx,0xcfa + out dx,al + mov dl,0xf8 + mov al,ah + out dx,al - pop eax - pop esi - ret + pop eax + pop esi + ret pci_read_reg_err: - xor eax,eax - dec eax - ret + xor eax,eax + dec eax + ret ;*************************************************************************** @@ -247,150 +258,281 @@ pci_read_reg_err: align 4 pci_write_reg: - cmp byte [BOOT_VAR+0x9020],2 ;what mechanism will we use? - je pci_write_reg_2 + cmp byte [BOOT_VAR+0x9020],2 ;what mechanism will we use? + je pci_write_reg_2 - ; mechanism 1 - push esi ; save register size into ESI - mov esi,eax - and esi,3 + ; mechanism 1 + push esi ; save register size into ESI + mov esi,eax + and esi,3 - call pci_make_config_cmd - mov ebx,eax - ; get current state into ecx - mov dx,0xcf8 - in eax, dx - push eax - ; set up addressing to config data - mov eax,ebx - and al,0xfc ; make address dword-aligned - out dx,eax - ; write DWORD of config data - mov dl,0xfc - and bl,3 - or dl,bl - mov eax,ecx + call pci_make_config_cmd + mov ebx,eax + ; get current state into ecx + mov dx,0xcf8 + in eax, dx + push eax + ; set up addressing to config data + mov eax,ebx + and al,0xfc ; make address dword-aligned + out dx,eax + ; write DWORD of config data + mov dl,0xfc + and bl,3 + or dl,bl + mov eax,ecx - or esi,esi - jz pci_write_byte1 - cmp esi,1 - jz pci_write_word1 - cmp esi,2 - jz pci_write_dword1 - jmp pci_fin_write1 + or esi,esi + jz pci_write_byte1 + cmp esi,1 + jz pci_write_word1 + cmp esi,2 + jz pci_write_dword1 + jmp pci_fin_write1 pci_write_byte1: - out dx,al - jmp pci_fin_write1 + out dx,al + jmp pci_fin_write1 pci_write_word1: - out dx,ax - jmp pci_fin_write1 + out dx,ax + jmp pci_fin_write1 pci_write_dword1: - out dx,eax - jmp pci_fin_write1 + out dx,eax + jmp pci_fin_write1 pci_fin_write1: - ; restore configuration control - pop eax - mov dl,0xf8 - out dx,eax + ; restore configuration control + pop eax + mov dl,0xf8 + out dx,eax - xor eax,eax - pop esi + xor eax,eax + pop esi - ret + ret pci_write_reg_2: - test bh,128 ;mech#2 only supports 16 devices per bus - jnz pci_write_reg_err + test bh,128 ;mech#2 only supports 16 devices per bus + jnz pci_write_reg_err - push esi ; save register size into ESI - mov esi,eax - and esi,3 + push esi ; save register size into ESI + mov esi,eax + and esi,3 - push eax - ;store current state of config space - mov dx,0xcf8 - in al,dx - mov ah,al - mov dl,0xfa - in al,dx - xchg eax,[esp] - ; out 0xcfa,bus - mov al,ah - out dx,al - ; out 0xcf8,0x80 - mov dl,0xf8 - mov al,0x80 - out dx,al - ; compute addr - shr bh,3 ; func is ignored in mechanism 2 - or bh,0xc0 - mov dx,bx - ; write register - mov eax,ecx + push eax + ;store current state of config space + mov dx,0xcf8 + in al,dx + mov ah,al + mov dl,0xfa + in al,dx + xchg eax,[esp] + ; out 0xcfa,bus + mov al,ah + out dx,al + ; out 0xcf8,0x80 + mov dl,0xf8 + mov al,0x80 + out dx,al + ; compute addr + shr bh,3 ; func is ignored in mechanism 2 + or bh,0xc0 + mov dx,bx + ; write register + mov eax,ecx - or esi,esi - jz pci_write_byte2 - cmp esi,1 - jz pci_write_word2 - cmp esi,2 - jz pci_write_dword2 - jmp pci_fin_write2 + or esi,esi + jz pci_write_byte2 + cmp esi,1 + jz pci_write_word2 + cmp esi,2 + jz pci_write_dword2 + jmp pci_fin_write2 pci_write_byte2: - out dx,al - jmp pci_fin_write2 + out dx,al + jmp pci_fin_write2 pci_write_word2: - out dx,ax - jmp pci_fin_write2 + out dx,ax + jmp pci_fin_write2 pci_write_dword2: - out dx,eax - jmp pci_fin_write2 + out dx,eax + jmp pci_fin_write2 pci_fin_write2: - ; restore configuration space - pop eax - mov dx,0xcfa - out dx,al - mov dl,0xf8 - mov al,ah - out dx,al + ; restore configuration space + pop eax + mov dx,0xcfa + out dx,al + mov dl,0xf8 + mov al,ah + out dx,al - xor eax,eax - pop esi - ret + xor eax,eax + pop esi + ret pci_write_reg_err: - xor eax,eax - dec eax - ret + xor eax,eax + dec eax + ret + +if defined mmio_pci_addr ; must be set above +;*************************************************************************** +; Function +; pci_mmio_init +; +; Description +; IN: bx = device's PCI bus address (bbbbbbbbdddddfff) +; Returns eax = user heap space available (bytes) +; Error codes +; eax = -1 : PCI user access blocked, +; eax = -2 : device not registered for uMMIO service +; eax = -3 : user heap initialization failure +;*************************************************************************** +pci_mmio_init: + cmp bx, mmio_pci_addr + jz @f + mov eax,-2 + ret +@@: + call init_heap ; (if not initialized yet) + or eax,eax + jz @f + ret +@@: + mov eax,-3 + ret + + +;*************************************************************************** +; Function +; pci_mmio_map +; +; Description +; maps a block of PCI memory to user-accessible linear address +; +; WARNING! This VERY EXPERIMENTAL service is for one chosen PCI device only! +; The target device address should be set in kernel var mmio_pci_addr +; +; IN: ah = BAR#; +; IN: ebx = block size (bytes); +; IN: ecx = offset in MMIO block (in 4K-pages, to avoid misaligned pages); +; +; Returns eax = MMIO block's linear address in the userspace (if no error) +; +; +; Error codes +; eax = -1 : user access to PCI blocked, +; eax = -2 : an invalid BAR register referred +; eax = -3 : no i/o space on that BAR +; eax = -4 : a port i/o BAR register referred +; eax = -5 : dynamic userspace allocation problem +;*************************************************************************** + +pci_mmio_map: + and edx,0x0ffff + cmp ah,6 + jc .bar_0_5 + jz .bar_rom + mov eax,-2 + ret +.bar_rom: + mov ah, 8 ; bar6 = Expansion ROM base address +.bar_0_5: + push ecx + add ebx, 4095 + and ebx,-4096 + push ebx + mov bl, ah ; bl = BAR# (0..5), however bl=8 for BAR6 + shl bl, 1 + shl bl, 1 + add bl, 0x10 ; now bl = BAR offset in PCI config. space + mov ax, mmio_pci_addr + mov bh, al ; bh = dddddfff + mov al, 2 ; al : DW to read + call pci_read_reg + or eax, eax + jnz @f + mov eax,-3 ; empty I/O space + jmp mmio_ret_fail +@@: + test eax, 1 + jz @f + mov eax,-4 ; damned ports (not MMIO space) + jmp mmio_ret_fail +@@: + pop ecx ; ecx = block size, bytes (expanded to whole page) + mov ebx, ecx ; user_alloc destroys eax, ecx, edx, but saves ebx + push eax ; store MMIO physical address + keep 2DWords in the stack + stdcall user_alloc, ecx + or eax, eax + jnz mmio_map_over + mov eax,-5 ; problem with page allocation + +mmio_ret_fail: + pop ecx + pop edx + ret + +mmio_map_over: + mov ecx, ebx ; ecx = size (bytes, expanded to whole page) + shr ecx, 12 ; ecx = number of pages + mov ebx, eax ; ebx = linear address + pop eax ; eax = MMIO start + pop edx ; edx = MMIO shift (pages) + shl edx, 12 ; edx = MMIO shift (bytes) + add eax, edx ; eax = uMMIO physical address + or eax, PG_SHARED + or eax, PG_UW + or eax, PG_NOCACHE + mov edi, ebx + call commit_pages + mov eax, edi + ret + +;*************************************************************************** +; Function +; pci_mmio_unmap_page +; +; Description +; unmaps the linear space previously tied to a PCI memory block +; +; IN: ebx = linear address of space previously allocated by pci_mmio_map +; returns eax = 1 if successfully unmapped +; +; Error codes +; eax = -1 if no user PCI access allowed, +; eax = 0 if unmapping failed +;*************************************************************************** + +pci_mmio_unmap: + stdcall user_free, ebx + ret + +end if ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - +uglobal +align 4 ; VendID (2), DevID (2), Revision = 0 (1), Class Code (3), FNum (1), Bus (1) pci_emu_dat: times 30*10 db 0 - +endg ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= align 4 sys_pcibios: - xchg ebx, eax - xchg ecx, eax - xchg edx, eax - xchg esi, eax - xchg edi, eax cmp [pci_access_enabled], 1 - jne .unsupported_func - cmp [pci_bios_entry], 0 + jne .unsupported_func + cmp [pci_bios_entry], 0 jz .emulate_bios - push ds - mov ax, pci_data_sel - mov ds, ax - mov eax, ebp - mov ah, 0B1h - call pword [cs:pci_bios_entry] - pop ds + push ds + mov ax, pci_data_sel + mov ds, ax + mov eax, ebp + mov ah, 0B1h + call pword [cs:pci_bios_entry] + pop ds jmp .return ;-=-=-=-=-=-=-=-= @@ -398,10 +540,10 @@ sys_pcibios: cmp ebp, 1 ; PCI_FUNCTION_ID jnz .not_PCI_BIOS_PRESENT mov edx, 'PCI ' - mov al, [OS_BASE+0x2F0000 + 0x9020] - mov bx, [OS_BASE+0x2F0000 + 0x9022] - mov cl, [OS_BASE+0x2F0000 + 0x9021] - xor ah, ah + mov al, [OS_BASE+0x2F0000 + 0x9020] + mov bx, [OS_BASE+0x2F0000 + 0x9022] + mov cl, [OS_BASE+0x2F0000 + 0x9021] + xor ah, ah jmp .return_abcd .not_PCI_BIOS_PRESENT: @@ -415,7 +557,7 @@ sys_pcibios: dec si jns ..no mov bx, [ebx + 4] - xor ah, ah + xor ah, ah jmp .return_ab ..no: cmp word[ebx], 0 je ..dev_not_found @@ -430,10 +572,10 @@ sys_pcibios: jne .not_FIND_PCI_CLASS_CODE mov esi, pci_emu_dat shl ecx, 8 -..nxt2: cmp [esi], ecx +..nxt2: cmp [esi], ecx jne ..no2 mov bx, [esi] - xor ah, ah + xor ah, ah jmp .return_ab ..no2: cmp dword[esi], 0 je ..dev_not_found @@ -445,11 +587,11 @@ sys_pcibios: jb .not_READ_CONFIG cmp ebp, 0x0A ja .not_READ_CONFIG - mov eax, ebp - mov ah, bh - mov edx, edi - mov bh, bl - mov bl, dl + mov eax, ebp + mov ah, bh + mov edx, edi + mov bh, bl + mov bl, dl call pci_read_reg mov ecx, eax xor ah, ah ; SUCCESSFUL @@ -459,25 +601,25 @@ sys_pcibios: jb .not_WRITE_CONFIG cmp ebp, 0x0D ja .not_WRITE_CONFIG - lea eax, [ebp+1] - mov ah, bh - mov edx, edi - mov bh, bl - mov bl, dl + lea eax, [ebp+1] + mov ah, bh + mov edx, edi + mov bh, bl + mov bl, dl call pci_write_reg xor ah, ah ; SUCCESSFUL jmp .return_abc .not_WRITE_CONFIG: .unsupported_func: mov ah, 0x81 ; FUNC_NOT_SUPPORTED -.return:mov dword[esp + 8 ], edi - mov dword[esp + 12], esi +.return:mov dword[esp + 4 ], edi + mov dword[esp + 8], esi .return_abcd: - mov dword[esp + 28], edx + mov dword[esp + 24], edx .return_abc: - mov dword[esp + 32], ecx + mov dword[esp + 28], ecx .return_ab: - mov dword[esp + 24], ebx + mov dword[esp + 20], ebx .return_a: - mov dword[esp + 36], eax + mov dword[esp + 32], eax ret diff --git a/kernel/branches/net/const.inc b/kernel/branches/net/const.inc index 957d5a5820..ae3b8bd8c7 100644 --- a/kernel/branches/net/const.inc +++ b/kernel/branches/net/const.inc @@ -1,6 +1,6 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; -;; Copyright (C) KolibriOS team 2004-2008. All rights reserved. ;; +;; Copyright (C) KolibriOS team 2004-2009. All rights reserved. ;; ;; Distributed under terms of the GNU General Public License ;; ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -309,15 +309,13 @@ draw_data equ (OS_BASE+0x0338000); BgrDrawMode equ (OS_BASE+0x033BFF4) BgrDataWidth equ (OS_BASE+0x033BFF8) BgrDataHeight equ (OS_BASE+0x033BFFC) -WinMapAddress equ (OS_BASE+0x033C000) -display_data equ (OS_BASE+0x033C000) ;1024*1280=0x140000 -virtual at (OS_BASE+0x047CF80) +sys_pgmap equ (OS_BASE+0x033C000) + +virtual at (OS_BASE+0x05FFF80) tss TSS end virtual -sys_pgmap equ (OS_BASE+0x047F000) - HEAP_BASE equ (OS_BASE+0x0800000) HEAP_MIN_SIZE equ 0x01000000 @@ -439,7 +437,8 @@ APP_OBJ_OFFSET equ 48 APP_EV_OFFSET equ 40 struc CURSOR -{;common object header +{ +;common object header .magic dd ? ;'CURS' .destroy dd ? ;internal destructor .fd dd ? ;next object in list @@ -450,12 +449,17 @@ struc CURSOR .base dd ? ;allocated memory .hot_x dd ? ;hotspot coords .hot_y dd ? + + .list_next dd ? ;next cursor in cursor list + .list_prev dd ? ;prev cursor in cursor list + .dev_obj dd ? ;device depended data + + .sizeof: } virtual at 0 CURSOR CURSOR end virtual -CURSOR_SIZE equ 32 struc EVENT { @@ -511,6 +515,77 @@ virtual at 0 SMAP SMAP end virtual +struc DLLDESCR +{ + .bk dd ? + .fd dd ? ;+4 + .data dd ? ;+8 + .size dd ? ;+12 + .timestamp dq ? + .refcount dd ? + .defaultbase dd ? + .coff_hdr dd ? + .symbols_ptr dd ? + .symbols_num dd ? + .symbols_lim dd ? + .exports dd ? ;export table + .name: + .sizeof: +} + +struc HDLL +{ + .fd dd ? ;next object in list + .bk dd ? ;prev object in list + .pid dd ? ;owner id + + .base dd ? ;mapped base + .size dd ? ;mapped size + .refcount dd ? ;reference counter for this process and this lib + .parent dd ? ;DLLDESCR + .sizeof: +} + +virtual at 0 + DLLDESCR DLLDESCR +end virtual + +virtual at 0 + HDLL HDLL +end virtual + +struc display_t +{ + .x dd ? + .y dd ? + .width dd ? + .height dd ? + .bpp dd ? + .vrefresh dd ? + .pitch dd ? + .lfb dd ? + + .modes dd ? + .ddev dd ? + .connector dd ? + .crtc dd ? + + .cr_list.next dd ? + .cr_list.prev dd ? + + .cursor dd ? + + .init_cursor dd ? + .select_cursor dd ? + .show_cursor dd ? + .move_cursor dd ? + .restore_cursor dd ? + .disable_mouse dd ? +} + +virtual at 0 + display_t display_t +end virtual struc HEAP_DATA { @@ -595,18 +670,20 @@ struc PG_DATA ;} struc SRV -{ .srv_name rb 16 ;ASCIIZ string +{ + .srv_name rb 16 ;ASCIIZ string .magic dd ? ;+0x10 ;'SRV ' .size dd ? ;+0x14 ;size of structure SRV .fd dd ? ;+0x18 ;next SRV descriptor .bk dd ? ;+0x1C ;prev SRV descriptor .base dd ? ;+0x20 ;service base address .entry dd ? ;+0x24 ;service START function - .srv_proc dd ? ;+0x28 ;main service handler + .srv_proc dd ? ;+0x28 ;user mode service handler + .srv_proc_ex dd ? ;+0x2C ;kernel mode service handler + .sizeof: } SRV_FD_OFFSET equ 0x18 -SRV_SIZE equ 44 DRV_ENTRY equ 1 DRV_EXIT equ -1 diff --git a/kernel/branches/net/core/conf_lib.inc b/kernel/branches/net/core/conf_lib.inc index 3f62c3e42e..1fbe6de683 100644 --- a/kernel/branches/net/core/conf_lib.inc +++ b/kernel/branches/net/core/conf_lib.inc @@ -12,59 +12,59 @@ $Revision$ - +iglobal conf_path_sect: db 'path',0 conf_fname db '/sys/sys.conf',0 - +endg ; set soke kernel configuration proc set_kernel_conf - locals - par db 30 dup(?) - endl + locals + par db 30 dup(?) + endl - pushad + pushad ;[gui] ;mouse_speed - lea eax,[par] - push eax - invoke ini.get_str,conf_fname, ugui, ugui_mouse_speed,\ - eax,30, ugui_mouse_speed_def - pop eax - stdcall strtoint,eax - mov [mouse_speed_factor], ax + lea eax,[par] + push eax + invoke ini.get_str,conf_fname, ugui, ugui_mouse_speed,\ + eax,30, ugui_mouse_speed_def + pop eax + stdcall strtoint,eax + mov [mouse_speed_factor], ax ;mouse_delay - lea eax,[par] - push eax - invoke ini.get_str,conf_fname, ugui, ugui_mouse_delay,\ - eax,30, ugui_mouse_delay_def - pop eax - stdcall strtoint,eax - mov [mouse_delay], eax + lea eax,[par] + push eax + invoke ini.get_str,conf_fname, ugui, ugui_mouse_delay,\ + eax,30, ugui_mouse_delay_def + pop eax + stdcall strtoint,eax + mov [mouse_delay], eax ;midibase - lea eax,[par] - push eax - invoke ini.get_str,conf_fname, udev, udev_midibase, eax,30, udev_midibase_def - pop eax - stdcall strtoint,eax + lea eax,[par] + push eax + invoke ini.get_str,conf_fname, udev, udev_midibase, eax,30, udev_midibase_def + pop eax + stdcall strtoint,eax - cmp eax, 0x100 - jb @f - cmp eax, 0x10000 - jae @f - mov [midi_base], ax - mov [mididp], eax - inc eax - mov [midisp], eax + cmp eax, 0x100 + jb @f + cmp eax, 0x10000 + jae @f + mov [midi_base], ax + mov [mididp], eax + inc eax + mov [midisp], eax @@: - popad - ret + popad + ret endp - +iglobal ugui db 'gui',0 ugui_mouse_speed db 'mouse_speed',0 ugui_mouse_speed_def db '2',0 @@ -74,8 +74,63 @@ ugui_mouse_delay_def db '0x00A',0 udev db 'dev',0 udev_midibase db 'midibase',0 udev_midibase_def db '0x320',0 +endg +;set up netvork configuration +proc set_network_conf +locals + par db 30 dup(?) +endl + pushad + + ;[net] + ;active + lea eax,[par] + invoke ini.get_int,conf_fname, unet, unet_active, 0 + or eax,eax + jz .do_not_set_net + mov eax, [stack_config] + and eax, 0xFFFFFF80 + add eax, 3 + mov [stack_config], eax + call ash_eth_enable + + ;addr + lea eax,[par] + push eax + invoke ini.get_str,conf_fname, unet, unet_addr, eax,30, unet_def + pop eax + stdcall do_inet_adr,eax + mov [stack_ip], eax + + ;mask + lea eax,[par] + push eax + invoke ini.get_str,conf_fname, unet, unet_mask, eax,30, unet_def + pop eax + stdcall do_inet_adr,eax + mov [subnet_mask], eax + + ;gate + lea eax,[par] + push eax + invoke ini.get_str,conf_fname, unet, unet_gate, eax,30, unet_def + pop eax + stdcall do_inet_adr,eax + mov [gateway_ip], eax +.do_not_set_net: + popad + ret +endp +iglobal +unet db 'net',0 +unet_active db 'active',0 +unet_addr db 'addr',0 +unet_mask db 'mask',0 +unet_gate db 'gate',0 +unet_def db 0 +endg ; convert string to DWord proc strtoint stdcall,strs pushad @@ -184,15 +239,15 @@ proc strtoint_hex stdcall,strs cmp al,'A' jae .bb jmp .cc -.bm: ; 57h +.bm: ; 57h sub al,57h jmp .do -.bb: ; 37h +.bb: ; 37h sub al,37h jmp .do -.cc: ; 30h +.cc: ; 30h sub al,30h .do: diff --git a/kernel/branches/net/core/debug.inc b/kernel/branches/net/core/debug.inc index 15d0b9c178..9830c64e96 100644 --- a/kernel/branches/net/core/debug.inc +++ b/kernel/branches/net/core/debug.inc @@ -10,10 +10,12 @@ $Revision$ ; diamond, 2006 sys_debug_services: - cmp eax, 9 + cmp ebx, 9 ja @f - jmp dword [sys_debug_services_table+eax*4] + jmp dword [sys_debug_services_table+ebx*4] @@: ret +iglobal +align 4 sys_debug_services_table: dd debug_set_event_data dd debug_getcontext @@ -25,21 +27,21 @@ sys_debug_services_table: dd debug_write_process_memory dd debug_terminate dd debug_set_drx - +endg debug_set_event_data: -; in: ebx = pointer +; in: ecx = pointer ; destroys eax mov eax, [current_slot] - mov [eax+APPDATA.dbg_event_mem], ebx + mov [eax+APPDATA.dbg_event_mem], ecx ret get_debuggee_slot: -; in: ebx=PID +; in: ecx=PID ; out: CF=1 if error ; CF=0 and eax=slot*0x20 if ok ; out: interrupts disabled cli - mov eax, ebx + mov eax, ecx call pid_to_slot test eax, eax jz .ret_bad @@ -56,7 +58,7 @@ get_debuggee_slot: ret debug_detach: -; in: ebx=pid +; in: ecx=pid ; destroys eax,ebx call get_debuggee_slot jc .ret @@ -67,54 +69,55 @@ debug_detach: ret debug_terminate: -; in: ebx=pid +; in: ecx=pid call get_debuggee_slot jc debug_detach.ret mov ecx, eax shr ecx, 5 - push 2 - pop ebx - jmp sys_system +; push 2 +; pop ebx + mov edx,esi + jmp sysfn_terminate debug_suspend: -; in: ebx=pid -; destroys eax,ebx +; in: ecx=pid +; destroys eax,ecx cli - mov eax, ebx + mov eax, ecx call pid_to_slot shl eax, 5 jz .ret - mov bl, [CURRENT_TASK+eax+TASKDATA.state] ; process state - test bl, bl + mov cl, [CURRENT_TASK+eax+TASKDATA.state] ; process state + test cl, cl jz .1 - cmp bl, 5 + cmp cl, 5 jnz .ret - mov bl, 2 -.2: mov [CURRENT_TASK+eax+TASKDATA.state], bl + mov cl, 2 +.2: mov [CURRENT_TASK+eax+TASKDATA.state], cl .ret: sti ret .1: - inc ebx + inc ecx jmp .2 do_resume: - mov bl, [CURRENT_TASK+eax+TASKDATA.state] - cmp bl, 1 + mov cl, [CURRENT_TASK+eax+TASKDATA.state] + cmp cl, 1 jz .1 - cmp bl, 2 + cmp cl, 2 jnz .ret - mov bl, 5 -.2: mov [CURRENT_TASK+eax+TASKDATA.state], bl + mov cl, 5 +.2: mov [CURRENT_TASK+eax+TASKDATA.state], cl .ret: ret -.1: dec ebx +.1: dec ecx jmp .2 debug_resume: -; in: ebx=pid +; in: ecx=pid ; destroys eax,ebx cli - mov eax, ebx + mov eax, ecx call pid_to_slot shl eax, 5 jz .ret @@ -124,23 +127,24 @@ debug_resume: debug_getcontext: ; in: -; ebx=pid -; ecx=sizeof(CONTEXT) -; edx->CONTEXT +; ecx=pid +; edx=sizeof(CONTEXT) +; esi->CONTEXT ; destroys eax,ecx,edx,esi,edi - cmp ecx, 28h + cmp edx, 28h jnz .ret - push ebx - mov ebx, edx +; push ecx +; mov ecx, esi call check_region - pop ebx +; pop ecx dec eax jnz .ret call get_debuggee_slot jc .ret + mov edi, esi mov eax, [eax*8+SLOT_BASE+APPDATA.pl0_stack] lea esi, [eax+RING0_STACK_SIZE] - mov edi, edx + .ring0: ; note that following code assumes that all interrupt/exception handlers ; saves ring-3 context by pushad in this order @@ -174,23 +178,24 @@ debug_getcontext: debug_setcontext: ; in: -; ebx=pid -; ecx=sizeof(CONTEXT) -; edx->CONTEXT +; ecx=pid +; edx=sizeof(CONTEXT) +; esi->CONTEXT ; destroys eax,ecx,edx,esi,edi - cmp ecx, 28h + cmp edx, 28h jnz .ret - push ebx - mov ebx, edx +; push ebx +; mov ebx, edx call check_region - pop ebx +; pop ebx dec eax jnz .ret call get_debuggee_slot jc .stiret +; mov esi, edx mov eax, [eax*8+SLOT_BASE+APPDATA.pl0_stack] lea edi, [eax+RING0_STACK_SIZE] - mov esi, edx + .ring0: sub edi, 8+12+20h mov eax, [esi+24h] ;edi @@ -227,67 +232,75 @@ debug_set_drx: lea eax, [eax*8+SLOT_BASE+APPDATA.dbg_regs] ; [eax]=dr0, [eax+4]=dr1, [eax+8]=dr2, [eax+C]=dr3 ; [eax+10]=dr7 - cmp edx, OS_BASE + cmp esi, OS_BASE jae .errret - cmp cl, 3 + cmp dl, 3 ja .errret - mov ebx, dr7 - shr ebx, cl - shr ebx, cl - test ebx, 2 ; bit 1+2*index = G0..G3, global break enable + mov ecx, dr7 +;fix me + xchg ecx,edx + shr edx, cl + shr edx, cl + xchg ecx,edx + + test ecx, 2 ; bit 1+2*index = G0..G3, global break enable jnz .errret2 - test ch, ch + test dh, dh jns .new ; clear breakpoint - movzx ecx, cl - add ecx, ecx - and dword [eax+ecx*2], 0 ; clear DR - btr dword [eax+10h], ecx ; clear L bit + movzx edx, dl + add edx, edx + and dword [eax+edx*2], 0 ; clear DR + btr dword [eax+10h], edx ; clear L bit test byte [eax+10h], 55h jnz .okret ; imul eax, ebp, tss_step/32 ; and byte [eax + tss_data + TSS._trap], not 1 and [ebp*8 + SLOT_BASE+APPDATA.dbg_state], not 1 .okret: - and dword [esp+36], 0 + and dword [esp+32], 0 sti ret .errret: sti - mov dword [esp+36], 1 + mov dword [esp+32], 1 ret .errret2: sti - mov dword [esp+36], 2 + mov dword [esp+32], 2 ret .new: ; add new breakpoint -; cl=index; ch=flags; edx=address - test ch, 0xF0 +; dl=index; dh=flags; esi=address + test dh, 0xF0 jnz .errret - mov bl, ch - and bl, 3 - cmp bl, 2 + mov cl, dh + and cl, 3 + cmp cl, 2 jz .errret - mov bl, ch - shr bl, 2 - cmp bl, 2 + mov cl, dh + shr cl, 2 + cmp cl, 2 jz .errret - test dl, bl + + mov ebx,esi + test bl, dl + jnz .errret or byte [eax+10h+1], 3 ; set GE and LE flags - movzx ebx, ch - movzx ecx, cl + + movzx edx, dh + movzx ecx, dl add ecx, ecx bts dword [eax+10h], ecx ; set L flag add ecx, ecx - mov [eax+ecx], edx ; set DR - shl ebx, cl - mov edx, 0xF + mov [eax+ecx], ebx;esi ; set DR shl edx, cl - not edx - and [eax+10h+2], dx - or [eax+10h+2], bx ; set R/W and LEN fields + mov ebx, 0xF + shl ebx, cl + not ebx + and [eax+10h+2], bx + or [eax+10h+2], dx ; set R/W and LEN fields ; imul eax, ebp, tss_step/32 ; or byte [eax + tss_data + TSS._trap], 1 or [ebp*8 + SLOT_BASE+APPDATA.dbg_state], 1 @@ -295,51 +308,51 @@ debug_set_drx: debug_read_process_memory: ; in: -; ebx=pid -; ecx=length -; esi->buffer in debugger -; edx=address in debuggee +; ecx=pid +; edx=length +; edi->buffer in debugger +; esi=address in debuggee ; out: [esp+36]=sizeof(read) ; destroys all - push ebx - mov ebx, esi +; push ebx +; mov ebx, esi call check_region - pop ebx +; pop ebx dec eax jnz .err call get_debuggee_slot jc .err shr eax, 5 - mov ebx, esi +; mov ebx, esi call read_process_memory sti - mov dword [esp+36], eax + mov dword [esp+32], eax ret .err: - or dword [esp+36], -1 + or dword [esp+32], -1 ret debug_write_process_memory: ; in: -; ebx=pid -; ecx=length -; esi->buffer in debugger -; edx=address in debuggee +; ecx=pid +; edx=length +; edi->buffer in debugger +; esi=address in debuggee ; out: [esp+36]=sizeof(write) ; destroys all - push ebx - mov ebx, esi +; push ebx +; mov ebx, esi call check_region - pop ebx +; pop ebx dec eax jnz debug_read_process_memory.err call get_debuggee_slot jc debug_read_process_memory.err shr eax, 5 - mov ebx, esi +; mov ebx, esi call write_process_memory sti - mov [esp+36], eax + mov [esp+32], eax ret debugger_notify: diff --git a/kernel/branches/net/core/dll.inc b/kernel/branches/net/core/dll.inc index a6a1244d1d..374c051727 100644 --- a/kernel/branches/net/core/dll.inc +++ b/kernel/branches/net/core/dll.inc @@ -1,6 +1,6 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; -;; Copyright (C) KolibriOS team 2004-2008. All rights reserved. ;; +;; Copyright (C) KolibriOS team 2004-2009. All rights reserved. ;; ;; Distributed under terms of the GNU General Public License ;; ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -17,39 +17,39 @@ PID_KERNEL equ 1 ;os_idle thread align 4 proc attach_int_handler stdcall, irq:dword, handler:dword, access_rights:dword - push ebx + push ebx - mov ebx, [irq] ;irq num - test ebx, ebx - jz .err - cmp ebx, 15 ; hidnplayr says: we only have 16 IRQ's - ja .err - mov eax, [handler] - test eax, eax - jz .err - cmp [irq_owner + 4 * ebx], 0 - je @f + mov ebx, [irq] ;irq num + test ebx, ebx + jz .err + cmp ebx, 15 ; hidnplayr says: we only have 16 IRQ's + ja .err + mov eax, [handler] + test eax, eax + jz .err + cmp [irq_owner + 4 * ebx], 0 + je @f - mov ecx, [irq_rights + 4 * ebx] ; Rights : 0 - full access, 1 - read only, 2 - forbidden - test ecx, ecx - jnz .err + mov ecx, [irq_rights + 4 * ebx] ; Rights : 0 - full access, 1 - read only, 2 - forbidden + test ecx, ecx + jnz .err @@: - mov [irq_tab+ebx*4], eax + mov [irq_tab+ebx*4], eax - mov eax, [access_rights] - mov [irq_rights + 4 * ebx], eax + mov eax, [access_rights] + mov [irq_rights + 4 * ebx], eax - mov [irq_owner + 4 * ebx], PID_KERNEL ; all handlers belong to a kernel + mov [irq_owner + 4 * ebx], PID_KERNEL ; all handlers belong to a kernel - stdcall enable_irq, [irq] - pop ebx - mov eax, 1 - ret + stdcall enable_irq, [irq] + pop ebx + mov eax, 1 + ret .err: - pop ebx - xor eax, eax - ret + pop ebx + xor eax, eax + ret endp uglobal @@ -121,8 +121,8 @@ align 4 jmp .main ; align 4 ; .irq_6: -; push 6 -; jmp .main +; push 6 +; jmp .main align 4 .irq_7: push 7 @@ -149,16 +149,16 @@ align 4 jmp .main ; align 4 ; .irq_13: -; push 13 -; jmp .main +; push 13 +; jmp .main ; align 4 ; .irq_14: -; push 14 -; jmp .main +; push 14 +; jmp .main ; align 4 ; .irq_15: -; push 15 -; jmp .main +; push 15 +; jmp .main align 16 .main: @@ -315,7 +315,7 @@ proc srv_handler stdcall, ioctl:dword cmp [edi+SRV.magic], ' SRV' jne .fail - cmp [edi+SRV.size], SRV_SIZE + cmp [edi+SRV.size], SRV.sizeof jne .fail stdcall [edi+SRV.srv_proc], esi @@ -333,24 +333,24 @@ proc srv_handler stdcall, ioctl:dword endp ; param -; ebx= io_control +; ecx= io_control ; ; retval ; eax= error code align 4 srv_handlerEx: - cmp ebx, OS_BASE + cmp ecx, OS_BASE jae .fail - mov eax, [ebx+handle] + mov eax, [ecx+handle] cmp [eax+SRV.magic], ' SRV' jne .fail - cmp [eax+SRV.size], SRV_SIZE + cmp [eax+SRV.size], SRV.sizeof jne .fail - stdcall [eax+SRV.srv_proc], ebx + stdcall [eax+SRV.srv_proc], ecx ret .fail: or eax, -1 @@ -394,7 +394,7 @@ proc reg_service stdcall, name:dword, handler:dword push ebx - xor eax, eax + xor eax, eax cmp [name], eax je .fail @@ -402,8 +402,8 @@ proc reg_service stdcall, name:dword, handler:dword cmp [handler], eax je .fail - mov eax, SRV_SIZE - call malloc ;call alloc_service + mov eax, SRV.sizeof + call malloc test eax, eax jz .fail @@ -411,13 +411,15 @@ proc reg_service stdcall, name:dword, handler:dword push edi mov edi, eax mov esi, [name] - mov ecx, 16/4 - rep movsd + movsd + movsd + movsd + movsd pop edi pop esi mov [eax+SRV.magic], ' SRV' - mov [eax+SRV.size], SRV_SIZE + mov [eax+SRV.size], SRV.sizeof mov ebx, srv.fd-SRV_FD_OFFSET mov edx, [ebx+SRV.fd] @@ -432,7 +434,7 @@ proc reg_service stdcall, name:dword, handler:dword ret .fail: xor eax, eax - pop ebx + pop ebx ret endp @@ -472,8 +474,8 @@ proc get_coff_sym stdcall, pSym:dword,count:dword, sz_sym:dword xor eax, eax ret .ok: - mov ebx, [pSym] - mov eax, [ebx+8] + mov eax, [pSym] + mov eax, [eax+8] ret endp @@ -611,7 +613,10 @@ proc load_file stdcall, file_name:dword jz .cleanup mov [file2], eax + pushfd + cli stdcall unpack, [file], eax + popfd stdcall kernel_free, [file] mov eax, [file2] mov ebx, [file_size] @@ -676,7 +681,7 @@ proc get_proc_ex stdcall, proc_name:dword, imports:dword endp align 4 -proc fix_coff_symbols stdcall, sec:dword, symbols:dword,\ +proc fix_coff_symbols stdcall uses ebx esi, sec:dword, symbols:dword,\ sym_count:dword, strings:dword, imports:dword locals retval dd ? @@ -738,7 +743,8 @@ proc fix_coff_symbols stdcall, sec:dword, symbols:dword,\ endp align 4 -proc fix_coff_relocs stdcall, coff:dword, sec:dword, sym:dword +proc fix_coff_relocs stdcall uses ebx esi, coff:dword, sym:dword, \ + delta:dword locals n_sec dd ? endl @@ -746,15 +752,15 @@ proc fix_coff_relocs stdcall, coff:dword, sec:dword, sym:dword mov eax, [coff] movzx ebx, [eax+CFH.nSections] mov [n_sec], ebx + lea esi, [eax+20] .fix_sec: - mov esi, [sec] mov edi, [esi+CFS.PtrReloc] add edi, [coff] movzx ecx, [esi+CFS.NumReloc] test ecx, ecx jz .next -.next_reloc: +.reloc_loop: mov ebx, [edi+CRELOC.SymIndex] add ebx,ebx lea ebx,[ebx+ebx*8] @@ -777,12 +783,51 @@ proc fix_coff_relocs stdcall, coff:dword, sec:dword, sym:dword mov eax, [edi+CRELOC.VirtualAddress] add eax, [esi+CFS.VirtualAddress] .fix: + add eax, [delta] add [eax], edx +.next_reloc: add edi, 10 dec ecx - jnz .next_reloc + jnz .reloc_loop .next: - add [sec], COFF_SECTION_SIZE + add esi, COFF_SECTION_SIZE + dec [n_sec] + jnz .fix_sec +.exit: + ret +endp + +proc rebase_coff stdcall uses ebx esi, coff:dword, sym:dword, \ + delta:dword + locals + n_sec dd ? + endl + + mov eax, [coff] + movzx ebx, [eax+CFH.nSections] + mov [n_sec], ebx + lea esi, [eax+20] + mov edx, [delta] +.fix_sec: + mov edi, [esi+CFS.PtrReloc] + add edi, [coff] + + movzx ecx, [esi+CFS.NumReloc] + test ecx, ecx + jz .next +.reloc_loop: + cmp [edi+CRELOC.Type], 6 + jne .next_reloc +.dir_32: + mov eax, [edi+CRELOC.VirtualAddress] + add eax, [esi+CFS.VirtualAddress] + add [eax+edx], edx +.next_reloc: + add edi, 10 + dec ecx + jnz .reloc_loop +.next: + add esi, COFF_SECTION_SIZE dec [n_sec] jnz .fix_sec .exit: @@ -811,7 +856,7 @@ proc load_driver stdcall, driver_name:dword mov byte [edx+12], '/' mov esi, [driver_name] .redo: - lea edx, [file_name] + lea edx, [file_name] lea edi, [edx+13] mov ecx, 16 @@: @@ -900,10 +945,8 @@ proc load_driver stdcall, driver_name:dword jz .link_fail mov ebx, [coff] - add ebx, 20 - stdcall fix_coff_relocs, [coff], ebx, [sym] + stdcall fix_coff_relocs, ebx, [sym], 0 - mov ebx, [coff] stdcall get_coff_sym,[sym],[ebx+CFH.nSymbols],szVersion test eax, eax jz .link_fail @@ -928,14 +971,14 @@ proc load_driver stdcall, driver_name:dword jnz .ok stdcall kernel_free, [img_base] - cmp dword [file_name+13], 'SOUN' - jnz @f - cmp dword [file_name+17], 'D.ob' - jnz @f - cmp word [file_name+21], 'j' - jnz @f - mov esi, aSis - jmp .redo + cmp dword [file_name+13], 'SOUN' + jnz @f + cmp dword [file_name+17], 'D.ob' + jnz @f + cmp word [file_name+21], 'j' + jnz @f + mov esi, aSis + jmp .redo @@: xor eax, eax ret @@ -975,124 +1018,537 @@ proc load_driver stdcall, driver_name:dword ret endp +; in: edx -> COFF_SECTION struct +; out: eax = alignment as mask for bits to drop +coff_get_align: +; Rules: +; - if alignment is not given, use default = 4K; +; - if alignment is given and is no more than 4K, use it; +; - if alignment is more than 4K, revert to 4K. + push ecx + mov cl, byte [edx+CFS.Characteristics+2] + mov eax, 1 + shr cl, 4 + dec cl + js .default + cmp cl, 12 + jbe @f +.default: + mov cl, 12 +@@: + shl eax, cl + pop ecx + dec eax + ret + align 4 proc load_library stdcall, file_name:dword locals + fullname rb 260 + fileinfo rb 40 coff dd ? - sym dd ? - strings dd ? - img_size dd ? img_base dd ? - exports dd ? endl cli - stdcall load_file, [file_name] - test eax, eax +; resolve file name + mov ebx, [file_name] + lea edi, [fullname+1] + mov byte [edi-1], '/' + stdcall get_full_file_name, edi, 259 + test al, al jz .fail +; scan for required DLL in list of already loaded for this process, +; ignore timestamp + mov esi, [CURRENT_TASK] + shl esi, 8 + lea edi, [fullname] + mov ebx, [esi+SLOT_BASE+APPDATA.dlls_list_ptr] + test ebx, ebx + jz .not_in_process + mov esi, [ebx+HDLL.fd] +.scan_in_process: + cmp esi, ebx + jz .not_in_process + mov eax, [esi+HDLL.parent] + add eax, DLLDESCR.name + stdcall strncmp, eax, edi, -1 + test eax, eax + jnz .next_in_process +; simple variant: load DLL which is already loaded in this process +; just increment reference counters and return address of exports table + inc [esi+HDLL.refcount] + mov ecx, [esi+HDLL.parent] + inc [ecx+DLLDESCR.refcount] + mov eax, [ecx+DLLDESCR.exports] + sub eax, [ecx+DLLDESCR.defaultbase] + add eax, [esi+HDLL.base] + ret +.next_in_process: + mov esi, [esi+HDLL.fd] + jmp .scan_in_process +.not_in_process: + +; scan in full list, compare timestamp + lea eax, [fileinfo] + stdcall get_fileinfo, edi, eax + test eax, eax + jnz .fail + mov esi, [dll_list.fd] +.scan_for_dlls: + cmp esi, dll_list + jz .load_new + lea eax, [esi+DLLDESCR.name] + stdcall strncmp, eax, edi, -1 + test eax, eax + jnz .continue_scan +.test_prev_dll: + mov eax, dword [fileinfo+24] ; last modified time + mov edx, dword [fileinfo+28] ; last modified date + cmp dword [esi+DLLDESCR.timestamp], eax + jnz .continue_scan + cmp dword [esi+DLLDESCR.timestamp+4], edx + jz .dll_already_loaded +.continue_scan: + mov esi, [esi+DLLDESCR.fd] + jmp .scan_for_dlls + +; new DLL +.load_new: +; load file + stdcall load_file, edi + test eax, eax + jz .fail mov [coff], eax - movzx ecx, [eax+CFH.nSections] + mov dword [fileinfo+32], ebx + +; allocate DLLDESCR struct; size is DLLDESCR.sizeof plus size of DLL name + mov esi, edi + mov ecx, -1 + xor eax, eax + repnz scasb + not ecx + lea eax, [ecx+DLLDESCR.sizeof] + push ecx + call malloc + pop ecx + test eax, eax + jz .fail_and_free_coff +; save timestamp + lea edi, [eax+DLLDESCR.name] + rep movsb + mov esi, eax + mov eax, dword [fileinfo+24] + mov dword [esi+DLLDESCR.timestamp], eax + mov eax, dword [fileinfo+28] + mov dword [esi+DLLDESCR.timestamp+4], eax +; initialize DLLDESCR struct + and dword [esi+DLLDESCR.refcount], 0 ; no HDLLs yet; later it will be incremented + mov [esi+DLLDESCR.fd], dll_list + mov eax, [dll_list.bk] + mov [dll_list.bk], esi + mov [esi+DLLDESCR.bk], eax + mov [eax+DLLDESCR.fd], esi + +; calculate size of loaded DLL + mov edx, [coff] + movzx ecx, [edx+CFH.nSections] xor ebx, ebx - lea edx, [eax+20] + add edx, 20 @@: + call coff_get_align + add ebx, eax + not eax + and ebx, eax add ebx, [edx+CFS.SizeOfRawData] - add ebx, 15 - and ebx, not 15 add edx, COFF_SECTION_SIZE dec ecx jnz @B - mov [img_size], ebx - - call init_heap - stdcall user_alloc, [img_size] - +; it must be nonzero and not too big + mov [esi+DLLDESCR.size], ebx + test ebx, ebx + jz .fail_and_free_dll + cmp ebx, MAX_DEFAULT_DLL_ADDR-MIN_DEFAULT_DLL_ADDR + ja .fail_and_free_dll +; allocate memory for kernel-side image + stdcall kernel_alloc, ebx test eax, eax - jz .fail - mov [img_base], eax + jz .fail_and_free_dll + mov [esi+DLLDESCR.data], eax +; calculate preferred base address + add ebx, 0x1FFF + and ebx, not 0xFFF + mov ecx, [dll_cur_addr] + lea edx, [ecx+ebx] + cmp edx, MAX_DEFAULT_DLL_ADDR + jb @f + mov ecx, MIN_DEFAULT_DLL_ADDR + lea edx, [ecx+ebx] +@@: + mov [esi+DLLDESCR.defaultbase], ecx + mov [dll_cur_addr], edx +; copy sections and set correct values for VirtualAddress'es in headers + push esi mov edx, [coff] movzx ebx, [edx+CFH.nSections] - mov edi, [img_base] - lea eax, [edx+20] + mov edi, eax + add edx, 20 + cld @@: - mov [eax+CFS.VirtualAddress], edi - mov esi, [eax+CFS.PtrRawData] + call coff_get_align + add ecx, eax + add edi, eax + not eax + and ecx, eax + and edi, eax + mov [edx+CFS.VirtualAddress], ecx + add ecx, [edx+CFS.SizeOfRawData] + mov esi, [edx+CFS.PtrRawData] + push ecx + mov ecx, [edx+CFS.SizeOfRawData] test esi, esi jnz .copy - add edi, [eax+CFS.SizeOfRawData] + xor eax, eax + rep stosb jmp .next .copy: - add esi, edx - mov ecx, [eax+CFS.SizeOfRawData] - cld + add esi, [coff] rep movsb .next: - add edi, 15 ;-new_app_base - and edi, -16 - add eax, COFF_SECTION_SIZE + pop ecx + add edx, COFF_SECTION_SIZE dec ebx jnz @B + pop esi +; save some additional data from COFF file +; later we will use COFF header, headers for sections and symbol table +; and also relocations table for all sections + mov edx, [coff] mov ebx, [edx+CFH.pSymTable] + mov edi, dword [fileinfo+32] + sub edi, ebx + jc .fail_and_free_data + mov [esi+DLLDESCR.symbols_lim], edi add ebx, edx - mov [sym], ebx + movzx ecx, [edx+CFH.nSections] + lea ecx, [ecx*5] + lea edi, [edi+ecx*8+20] + add edx, 20 +@@: + movzx eax, [edx+CFS.NumReloc] + lea eax, [eax*5] + lea edi, [edi+eax*2] + add edx, COFF_SECTION_SIZE + sub ecx, 5 + jnz @b + stdcall kernel_alloc, edi + test eax, eax + jz .fail_and_free_data + mov edx, [coff] + movzx ecx, [edx+CFH.nSections] + lea ecx, [ecx*5] + lea ecx, [ecx*2+5] + mov [esi+DLLDESCR.coff_hdr], eax + push esi + mov esi, edx + mov edi, eax + rep movsd + pop esi + mov [esi+DLLDESCR.symbols_ptr], edi + push esi mov ecx, [edx+CFH.nSymbols] - add ecx,ecx - lea ecx,[ecx+ecx*8] ;ecx*=18 = nSymbols*CSYM_SIZE - add ecx, [sym] - mov [strings], ecx + mov [esi+DLLDESCR.symbols_num], ecx + mov ecx, [esi+DLLDESCR.symbols_lim] + mov esi, ebx + rep movsb + pop esi + mov ebx, [esi+DLLDESCR.coff_hdr] + push esi + movzx eax, [edx+CFH.nSections] + lea edx, [ebx+20] +@@: + movzx ecx, [edx+CFS.NumReloc] + lea ecx, [ecx*5] + mov esi, [edx+CFS.PtrReloc] + mov [edx+CFS.PtrReloc], edi + sub [edx+CFS.PtrReloc], ebx + add esi, [coff] + shr ecx, 1 + rep movsd + adc ecx, ecx + rep movsw + add edx, COFF_SECTION_SIZE + dec eax + jnz @b + pop esi - lea eax, [edx+20] +; fixup symbols + mov edx, ebx + mov eax, [ebx+CFH.nSymbols] + add edx, 20 + mov ecx, [esi+DLLDESCR.symbols_num] + lea ecx, [ecx*9] + add ecx, ecx + add ecx, [esi+DLLDESCR.symbols_ptr] - stdcall fix_coff_symbols, eax, [sym], [edx+CFH.nSymbols],\ - [strings], dword 0 + stdcall fix_coff_symbols, edx, [esi+DLLDESCR.symbols_ptr], eax,\ + ecx, 0 +; test eax, eax +; jnz @F +; +;@@: + + stdcall get_coff_sym,[esi+DLLDESCR.symbols_ptr],[ebx+CFH.nSymbols],szEXPORTS test eax, eax jnz @F + stdcall get_coff_sym,[esi+DLLDESCR.symbols_ptr],[ebx+CFH.nSymbols],sz_EXPORTS @@: - mov edx, [coff] - movzx ebx, [edx+CFH.nSections] - mov edi, new_app_base - lea eax, [edx+20] -@@: - add [eax+CFS.VirtualAddress], edi ;patch user space offset - add eax, COFF_SECTION_SIZE - dec ebx - jnz @B + mov [esi+DLLDESCR.exports], eax - add edx, 20 - stdcall fix_coff_relocs, [coff], edx, [sym] +; fix relocs in the hidden copy in kernel memory to default address +; it is first fix; usually this will be enough, but second fix +; can be necessary if real load address will not equal assumption + mov eax, [esi+DLLDESCR.data] + sub eax, [esi+DLLDESCR.defaultbase] + stdcall fix_coff_relocs, ebx, [esi+DLLDESCR.symbols_ptr], eax - mov ebx, [coff] - stdcall get_coff_sym,[sym],[ebx+CFH.nSymbols],szEXPORTS - test eax, eax - jnz @F - - mov ebx, [coff] - stdcall get_coff_sym,[sym],[ebx+CFH.nSymbols],sz_EXPORTS -@@: - mov [exports], eax stdcall kernel_free, [coff] - mov eax, [exports] + +.dll_already_loaded: + inc [esi+DLLDESCR.refcount] + push esi + call init_heap + pop esi + + mov edi, [esi+DLLDESCR.size] + stdcall user_alloc_at, [esi+DLLDESCR.defaultbase], edi + test eax, eax + jnz @f + stdcall user_alloc, edi + test eax, eax + jz .fail_and_dereference +@@: + mov [img_base], eax + mov eax, HDLL.sizeof + call malloc + test eax, eax + jz .fail_and_free_user + mov ebx, [CURRENT_TASK] + shl ebx, 5 + mov edx, [CURRENT_TASK+ebx+TASKDATA.pid] + mov [eax+HDLL.pid], edx + push eax + call init_dlls_in_thread + pop ebx + test eax, eax + jz .fail_and_free_user + mov edx, [eax+HDLL.fd] + mov [ebx+HDLL.fd], edx + mov [ebx+HDLL.bk], eax + mov [eax+HDLL.fd], ebx + mov [edx+HDLL.bk], ebx + mov eax, ebx + mov ebx, [img_base] + mov [eax+HDLL.base], ebx + mov [eax+HDLL.size], edi + mov [eax+HDLL.refcount], 1 + mov [eax+HDLL.parent], esi + mov edx, ebx + shr edx, 12 + or dword [page_tabs+(edx-1)*4], DONT_FREE_BLOCK +; copy entries of page table from kernel-side image to usermode +; use copy-on-write for user-mode image, so map as readonly + xor edi, edi + mov ecx, [esi+DLLDESCR.data] + shr ecx, 12 +.map_pages_loop: + mov eax, [page_tabs+ecx*4] + and eax, not 0xFFF + or al, PG_USER + xchg eax, [page_tabs+edx*4] + test al, 1 + jz @f + call free_page +@@: + invlpg [ebx+edi] + inc ecx + inc edx + add edi, 0x1000 + cmp edi, [esi+DLLDESCR.size] + jb .map_pages_loop + +; if real user-mode base is not equal to preferred base, relocate image + sub ebx, [esi+DLLDESCR.defaultbase] + jz @f + stdcall rebase_coff, [esi+DLLDESCR.coff_hdr], [esi+DLLDESCR.symbols_ptr], ebx +@@: + + mov eax, [esi+DLLDESCR.exports] + sub eax, [esi+DLLDESCR.defaultbase] + add eax, [img_base] ret +.fail_and_free_data: + stdcall kernel_free, [esi+DLLDESCR.data] +.fail_and_free_dll: + mov eax, esi + call free +.fail_and_free_coff: + stdcall kernel_free, [coff] .fail: xor eax, eax ret +.fail_and_free_user: + stdcall user_free, [img_base] +.fail_and_dereference: + mov eax, 1 ; delete 1 reference + call dereference_dll + xor eax, eax + ret endp -align 4 -proc stop_all_services +; initialize [APPDATA.dlls_list_ptr] for given thread +; DLL is per-process object, so APPDATA.dlls_list_ptr must be +; kept in sync for all threads of one process. +; out: eax = APPDATA.dlls_list_ptr if all is OK, +; NULL if memory allocation failed +init_dlls_in_thread: + mov ebx, [current_slot] + mov eax, [ebx+APPDATA.dlls_list_ptr] + test eax, eax + jnz .ret + push [ebx+APPDATA.dir_table] + mov eax, 8 + call malloc + pop edx + test eax, eax + jz .ret + mov [eax], eax + mov [eax+4], eax + mov ecx, [TASK_COUNT] + mov ebx, SLOT_BASE+256 +.set: + cmp [ebx+APPDATA.dir_table], edx + jnz @f + mov [ebx+APPDATA.dlls_list_ptr], eax +@@: + add ebx, 256 + dec ecx + jnz .set +.ret: + ret +; in: eax = number of references to delete, esi -> DLLDESCR struc +dereference_dll: + sub [esi+DLLDESCR.refcount], eax + jnz .ret + mov eax, [esi+DLLDESCR.fd] + mov edx, [esi+DLLDESCR.bk] + mov [eax+DLLDESCR.bk], edx + mov [edx+DLLDESCR.fd], eax + stdcall kernel_free, [esi+DLLDESCR.coff_hdr] + stdcall kernel_free, [esi+DLLDESCR.data] + mov eax, esi + call free +.ret: + ret + +destroy_hdll: + push ebx ecx esi edi + push eax + mov ebx, [eax+HDLL.base] + mov esi, [eax+HDLL.parent] + mov edx, [esi+DLLDESCR.size] +; The following actions require the context of application where HDLL is mapped. +; However, destroy_hdll can be called in the context of OS thread when +; cleaning up objects created by the application which is destroyed. +; So remember current cr3 and set it to page table of target. + mov eax, [ecx+APPDATA.dir_table] +; Because we cheat with cr3, disable interrupts: task switch would restore +; page table from APPDATA of current thread. +; Also set [current_slot] because it is used by user_free. + pushf + cli + push [current_slot] + mov [current_slot], ecx + mov ecx, cr3 + push ecx + mov cr3, eax + push ebx ; argument for user_free + mov eax, ebx + shr ebx, 12 + push ebx + mov esi, [esi+DLLDESCR.data] + shr esi, 12 +.unmap_loop: + push eax + mov eax, 2 + xchg eax, [page_tabs+ebx*4] + mov ecx, [page_tabs+esi*4] + and eax, not 0xFFF + and ecx, not 0xFFF + cmp eax, ecx + jz @f + call free_page +@@: + pop eax + invlpg [eax] + add eax, 0x1000 + inc ebx + inc esi + sub edx, 0x1000 + ja .unmap_loop + pop ebx + and dword [page_tabs+(ebx-1)*4], not DONT_FREE_BLOCK + call user_free +; Restore context. + pop eax + mov cr3, eax + pop [current_slot] + popf +; Ok, cheating is done. + pop eax + push eax + mov esi, [eax+HDLL.parent] + mov eax, [eax+HDLL.refcount] + call dereference_dll + pop eax + mov edx, [eax+HDLL.bk] + mov ebx, [eax+HDLL.fd] + mov [ebx+HDLL.bk], edx + mov [edx+HDLL.fd], ebx + call free + pop edi esi ecx ebx + ret + +; ecx -> APPDATA for slot, esi = dlls_list_ptr +destroy_all_hdlls: + test esi, esi + jz .ret +.loop: + mov eax, [esi+HDLL.fd] + cmp eax, esi + jz free + call destroy_hdll + jmp .loop +.ret: + ret + +align 4 +stop_all_services: + push ebp mov edx, [srv.fd] .next: cmp edx, srv.fd-SRV_FD_OFFSET je .done cmp [edx+SRV.magic], ' SRV' jne .next - cmp [edx+SRV.size], SRV_SIZE + cmp [edx+SRV.size], SRV.sizeof jne .next mov ebx, [edx+SRV.entry] @@ -1101,12 +1557,16 @@ proc stop_all_services jz .next push edx - stdcall ebx, dword -1 + mov ebp, esp + push 0 + push -1 + call ebx + mov esp, ebp pop edx jmp .next .done: + pop ebp ret -endp ; param ; eax= size diff --git a/kernel/branches/net/core/exports.inc b/kernel/branches/net/core/exports.inc index 1a5237f5c4..decb89d739 100644 --- a/kernel/branches/net/core/exports.inc +++ b/kernel/branches/net/core/exports.inc @@ -9,78 +9,74 @@ $Revision$ iglobal - szKernel db 'KERNEL', 0 - szVersion db 'version',0 + szKernel db 'KERNEL', 0 + szVersion db 'version',0 - szRegService db 'RegService',0 - szGetService db 'GetService',0 + szRegService db 'RegService',0 + szGetService db 'GetService',0 szServiceHandler db 'ServiceHandler',0 szAttachIntHandler db 'AttachIntHandler',0 szGetIntHandler db 'GetIntHandler', 0 - szFpuSave db 'FpuSave',0 - szFpuRestore db 'FpuRestore',0 + szFpuSave db 'FpuSave',0 + szFpuRestore db 'FpuRestore',0 szReservePortArea db 'ReservePortArea',0 - szBoot_Log db 'Boot_Log',0 + szBoot_Log db 'Boot_Log',0 - szPciApi db 'PciApi', 0 - szPciRead32 db 'PciRead32', 0 - szPciRead16 db 'PciRead16', 0 - szPciRead8 db 'PciRead8', 0 - szPciWrite8 db 'PciWrite8',0 - szPciWrite16 db 'PciWrite16',0 - szPciWrite32 db 'PciWrite32',0 + szPciApi db 'PciApi', 0 + szPciRead32 db 'PciRead32', 0 + szPciRead16 db 'PciRead16', 0 + szPciRead8 db 'PciRead8', 0 + szPciWrite8 db 'PciWrite8',0 + szPciWrite16 db 'PciWrite16',0 + szPciWrite32 db 'PciWrite32',0 - szAllocPage db 'AllocPage',0 - szAllocPages db 'AllocPages',0 - szFreePage db 'FreePage',0 - szGetPgAddr db 'GetPgAddr',0 - szMapPage db 'MapPage',0 - szMapSpace db 'MapSpace',0 - szMapIoMem db 'MapIoMem',0 + szAllocPage db 'AllocPage',0 + szAllocPages db 'AllocPages',0 + szFreePage db 'FreePage',0 + szGetPgAddr db 'GetPgAddr',0 + szMapPage db 'MapPage',0 + szMapSpace db 'MapSpace',0 + szMapIoMem db 'MapIoMem',0 szCommitPages db 'CommitPages',0 szReleasePages db 'ReleasePages',0 szAllocKernelSpace db 'AllocKernelSpace',0 szFreeKernelSpace db 'FreeKernelSpace',0 szKernelAlloc db 'KernelAlloc',0 - szKernelFree db 'KernelFree',0 - szUserAlloc db 'UserAlloc',0 - szUserFree db 'UserFree',0 - szKmalloc db 'Kmalloc',0 - szKfree db 'Kfree',0 + szKernelFree db 'KernelFree',0 + szUserAlloc db 'UserAlloc',0 + szUserFree db 'UserFree',0 + szKmalloc db 'Kmalloc',0 + szKfree db 'Kfree',0 szCreateRingBuffer db 'CreateRingBuffer',0 - szGetPid db 'GetPid',0 + szGetPid db 'GetPid',0 szCreateObject db 'CreateObject',0 szDestroyObject db 'DestroyObject',0 szCreateEvent db 'CreateEvent',0 - szRaiseEvent db 'RaiseEvent',0 - szWaitEvent db 'WaitEvent',0 + szRaiseEvent db 'RaiseEvent',0 + szWaitEvent db 'WaitEvent',0 szDestroyEvent db 'DestroyEvent',0 - szClearEvent db 'ClearEvent',0 + szClearEvent db 'ClearEvent',0 - szLoadCursor db 'LoadCursor',0 - szSelectHwCursor db 'SelectHwCursor',0 - szSetHwCursor db 'SetHwCursor',0 - szHwCursorRestore db 'HwCursorRestore', 0 - szHwCursorCreate db 'HwCursorCreate', 0 + szLoadCursor db 'LoadCursor',0 szSysMsgBoardStr db 'SysMsgBoardStr', 0 szSysMsgBoardChar db 'SysMsgBoardChar', 0 szGetCurrentTask db 'GetCurrentTask',0 - szLFBAddress db 'LFBAddress',0 - szLoadFile db 'LoadFile',0 - szSendEvent db 'SendEvent',0 + szLFBAddress db 'LFBAddress',0 + szLoadFile db 'LoadFile',0 + szSendEvent db 'SendEvent',0 szSetMouseData db 'SetMouseData',0 - szSleep db 'Sleep',0 + szSleep db 'Sleep',0 szGetTimerTicks db 'GetTimerTicks',0 - szStrncat db 'strncat',0 - szStrncpy db 'strncpy',0 - szstrncmp db 'strncmp',0 - szStrnlen db 'strnlen',0 - szStrchr db 'strchr',0 - szStrrchr db 'strrchr',0 + szStrncat db 'strncat',0 + szStrncpy db 'strncpy',0 + szstrncmp db 'strncmp',0 + szStrnlen db 'strnlen',0 + szStrchr db 'strchr',0 + szStrrchr db 'strrchr',0 szEthReceiver db 'EthReceiver',0 szEthRegDev db 'EthRegDev',0 @@ -95,12 +91,12 @@ kernel_export: dd szServiceHandler , srv_handler dd szAttachIntHandler, attach_int_handler dd szGetIntHandler , get_int_handler - dd szFpuSave , fpu_save + dd szFpuSave , fpu_save dd szFpuRestore , fpu_restore dd szReservePortArea , r_f_port_area dd szBoot_Log , boot_log - dd szPciApi , pci_api + dd szPciApi , pci_api dd szPciRead32 , pci_read32 dd szPciRead16 , pci_read16 dd szPciRead8 , pci_read8 @@ -108,57 +104,52 @@ kernel_export: dd szPciWrite16 , pci_write16 dd szPciWrite32 , pci_write32 - dd szAllocPage , alloc_page ;stdcall - dd szAllocPages , alloc_pages ;stdcall + dd szAllocPage , alloc_page ;stdcall + dd szAllocPages , alloc_pages ;stdcall dd szFreePage , free_page - dd szMapPage , map_page ;stdcall + dd szMapPage , map_page ;stdcall dd szMapSpace , map_space - dd szMapIoMem , map_io_mem ;stdcall + dd szMapIoMem , map_io_mem ;stdcall dd szGetPgAddr , get_pg_addr - dd szCommitPages , commit_pages ;not implemented + dd szCommitPages , commit_pages ;not implemented dd szReleasePages , release_pages dd szAllocKernelSpace, alloc_kernel_space ;stdcall dd szFreeKernelSpace , free_kernel_space ;stdcall - dd szKernelAlloc , kernel_alloc ;stdcall - dd szKernelFree , kernel_free ;stdcall - dd szUserAlloc , user_alloc ;stdcall - dd szUserFree , user_free ;stdcall - dd szKmalloc , malloc - dd szKfree , free + dd szKernelAlloc , kernel_alloc ;stdcall + dd szKernelFree , kernel_free ;stdcall + dd szUserAlloc , user_alloc ;stdcall + dd szUserFree , user_free ;stdcall + dd szKmalloc , malloc + dd szKfree , free dd szCreateRingBuffer, create_ring_buffer ;stdcall - dd szGetPid , get_pid + dd szGetPid , get_pid dd szCreateObject , create_kernel_object dd szDestroyObject , destroy_kernel_object - dd szCreateEvent , create_event ;see EVENT.inc for specification - dd szRaiseEvent , raise_event ;see EVENT.inc for specification - dd szWaitEvent , wait_event ;see EVENT.inc for specification - dd szDestroyEvent , destroy_event ;see EVENT.inc for specification - dd szClearEvent , clear_event ;see EVENT.inc for specification + dd szCreateEvent , create_event ;see EVENT.inc for specification + dd szRaiseEvent , raise_event ;see EVENT.inc for specification + dd szWaitEvent , wait_event ;see EVENT.inc for specification + dd szDestroyEvent , destroy_event ;see EVENT.inc for specification + dd szClearEvent , clear_event ;see EVENT.inc for specification - dd szLoadCursor , load_cursor ;stdcall - - dd szSelectHwCursor , select_hw_cursor ;import stdcall - dd szSetHwCursor , set_hw_cursor ;import stdcall - dd szHwCursorRestore , hw_restore ;import - dd szHwCursorCreate , create_cursor ;import + dd szLoadCursor , load_cursor ;stdcall dd szSysMsgBoardStr , sys_msg_board_str dd szSysMsgBoardChar , sys_msg_board dd szGetCurrentTask , get_curr_task - dd szLoadFile , load_file ;retval eax, ebx - dd szSendEvent , send_event ;see EVENT.inc for specification + dd szLoadFile , load_file ;retval eax, ebx + dd szSendEvent , send_event ;see EVENT.inc for specification dd szSetMouseData , set_mouse_data ;stdcall - dd szSleep , delay_ms + dd szSleep , delay_ms dd szGetTimerTicks , get_timer_ticks - dd szStrncat , strncat - dd szStrncpy , strncpy - dd szstrncmp , strncmp - dd szStrnlen , strnlen - dd szStrchr , strchr - dd szStrrchr , strrchr + dd szStrncat , strncat + dd szStrncpy , strncpy + dd szstrncmp , strncmp + dd szStrnlen , strnlen + dd szStrchr , strchr + dd szStrrchr , strrchr dd szEthReceiver , ETH_receiver dd szEthRegDev , ETH_add_device @@ -167,6 +158,6 @@ kernel_export: exp_lfb: dd szLFBAddress , 0 - dd 0 ;terminator, must be zero + dd 0 ;terminator, must be zero endg diff --git a/kernel/branches/net/core/ext_lib.inc b/kernel/branches/net/core/ext_lib.inc index 673bd5c6a1..db53e63264 100644 --- a/kernel/branches/net/core/ext_lib.inc +++ b/kernel/branches/net/core/ext_lib.inc @@ -13,7 +13,9 @@ $Revision$ - +if 0 +; The code currently does not work. Kill "if 0/end if" only after correcting +; to current kernel (dll.inc). macro library [name,fname] { forward @@ -315,3 +317,4 @@ endp uglobal s_libname db 64 dup (0) endg +end if diff --git a/kernel/branches/net/core/heap.inc b/kernel/branches/net/core/heap.inc index 7b3f0b69b0..03d914459c 100644 --- a/kernel/branches/net/core/heap.inc +++ b/kernel/branches/net/core/heap.inc @@ -1,6 +1,6 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; -;; Copyright (C) KolibriOS team 2004-2008. All rights reserved. ;; +;; Copyright (C) KolibriOS team 2004-2009. All rights reserved. ;; ;; Distributed under terms of the GNU General Public License ;; ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -9,19 +9,19 @@ $Revision$ struc MEM_BLOCK -{ .next_block dd ? - .prev_block dd ? ;+4 - .list_fd dd ? ;+8 - .list_bk dd ? ;+12 - .base dd ? ;+16 - .size dd ? ;+20 - .flags dd ? ;+24 - .handle dd ? ;+28 +{ .next_block dd ? + .prev_block dd ? ;+4 + .list_fd dd ? ;+8 + .list_bk dd ? ;+12 + .base dd ? ;+16 + .size dd ? ;+20 + .flags dd ? ;+24 + .handle dd ? ;+28 } MEM_LIST_OFFSET equ 8 -FREE_BLOCK equ 4 -USED_BLOCK equ 8 +FREE_BLOCK equ 4 +USED_BLOCK equ 8 DONT_FREE_BLOCK equ 10h virtual at 0 @@ -39,53 +39,53 @@ block_size equ MEM_BLOCK.size block_flags equ MEM_BLOCK.flags macro calc_index op -{ shr op, 12 - dec op - cmp op, 63 - jna @f - mov op, 63 +{ shr op, 12 + dec op + cmp op, 63 + jna @f + mov op, 63 @@: } macro remove_from_list op -{ mov edx, [op+list_fd] - mov ecx, [op+list_bk] - test edx, edx - jz @f - mov [edx+list_bk], ecx +{ mov edx, [op+list_fd] + mov ecx, [op+list_bk] + test edx, edx + jz @f + mov [edx+list_bk], ecx @@: - test ecx, ecx - jz @f - mov [ecx+list_fd], edx + test ecx, ecx + jz @f + mov [ecx+list_fd], edx @@: - mov [op+list_fd],0 - mov [op+list_bk],0 + mov [op+list_fd],0 + mov [op+list_bk],0 } macro remove_from_free op { - remove_from_list op + remove_from_list op - mov eax, [op+block_size] - calc_index eax - cmp [mem_block_list+eax*4], op - jne @f - mov [mem_block_list+eax*4], edx + mov eax, [op+block_size] + calc_index eax + cmp [mem_block_list+eax*4], op + jne @f + mov [mem_block_list+eax*4], edx @@: - cmp [mem_block_list+eax*4], 0 - jne @f - btr [mem_block_mask], eax + cmp [mem_block_list+eax*4], 0 + jne @f + btr [mem_block_mask], eax @@: } macro remove_from_used op { - mov edx, [op+list_fd] - mov ecx, [op+list_bk] - mov [edx+list_bk], ecx - mov [ecx+list_fd], edx - mov [op+list_fd], 0 - mov [op+list_bk], 0 + mov edx, [op+list_fd] + mov ecx, [op+list_bk] + mov [edx+list_bk], ecx + mov [ecx+list_fd], edx + mov [op+list_fd], 0 + mov [op+list_bk], 0 } align 4 @@ -97,57 +97,57 @@ proc init_kernel_heap cld rep stosd - mov ecx, 512/4 - mov edi, mem_block_map - not eax - rep stosd + mov ecx, 512/4 + mov edi, mem_block_map + not eax + rep stosd - mov [mem_block_start], mem_block_map - mov [mem_block_end], mem_block_map+512 - mov [mem_block_arr], HEAP_BASE + mov [mem_block_start], mem_block_map + mov [mem_block_end], mem_block_map+512 + mov [mem_block_arr], HEAP_BASE - mov eax, mem_used.fd-MEM_LIST_OFFSET - mov [mem_used.fd], eax - mov [mem_used.bk], eax + mov eax, mem_used.fd-MEM_LIST_OFFSET + mov [mem_used.fd], eax + mov [mem_used.bk], eax - stdcall alloc_pages, dword 32 - mov ecx, 32 - mov edx, eax - mov edi, HEAP_BASE + stdcall alloc_pages, dword 32 + mov ecx, 32 + mov edx, eax + mov edi, HEAP_BASE .l1: - stdcall map_page,edi,edx,PG_SW - add edi, 0x1000 - add edx, 0x1000 - dec ecx - jnz .l1 + stdcall map_page,edi,edx,PG_SW + add edi, 0x1000 + add edx, 0x1000 + dec ecx + jnz .l1 - mov edi, HEAP_BASE - mov ebx, HEAP_BASE+MEM_BLOCK_SIZE - xor eax, eax - mov [edi+block_next], ebx - mov [edi+block_prev], eax - mov [edi+list_fd], eax - mov [edi+list_bk], eax - mov [edi+block_base], HEAP_BASE - mov [edi+block_size], 4096*MEM_BLOCK_SIZE - mov [edi+block_flags], USED_BLOCK + mov edi, HEAP_BASE + mov ebx, HEAP_BASE+MEM_BLOCK_SIZE + xor eax, eax + mov [edi+block_next], ebx + mov [edi+block_prev], eax + mov [edi+list_fd], eax + mov [edi+list_bk], eax + mov [edi+block_base], HEAP_BASE + mov [edi+block_size], 4096*MEM_BLOCK_SIZE + mov [edi+block_flags], USED_BLOCK - mov [ebx+block_next], eax - mov [ebx+block_prev], eax - mov [ebx+list_fd], eax - mov [ebx+list_bk], eax - mov [ebx+block_base], HEAP_BASE+4096*MEM_BLOCK_SIZE + mov [ebx+block_next], eax + mov [ebx+block_prev], eax + mov [ebx+list_fd], eax + mov [ebx+list_bk], eax + mov [ebx+block_base], HEAP_BASE+4096*MEM_BLOCK_SIZE mov ecx, [pg_data.kernel_pages] shl ecx, 12 - sub ecx, HEAP_BASE+4096*MEM_BLOCK_SIZE + sub ecx, HEAP_BASE-OS_BASE+4096*MEM_BLOCK_SIZE mov [heap_size], ecx mov [heap_free], ecx mov [ebx+block_size], ecx mov [ebx+block_flags], FREE_BLOCK - mov [mem_block_mask], eax - mov [mem_block_mask+4],0x80000000 + mov [mem_block_mask], eax + mov [mem_block_mask+4],0x80000000 mov [mem_block_list+63*4], ebx mov byte [mem_block_map], 0xFC @@ -166,481 +166,481 @@ endp align 4 get_small_block: - mov ecx, eax - shr ecx, 12 - dec ecx - cmp ecx, 63 - jle .get_index - mov ecx, 63 + mov ecx, eax + shr ecx, 12 + dec ecx + cmp ecx, 63 + jle .get_index + mov ecx, 63 .get_index: - lea esi, [mem_block_mask] - xor ebx, ebx - or edx, -1 + lea esi, [mem_block_mask] + xor ebx, ebx + or edx, -1 - cmp ecx, 32 - jb .bit_test + cmp ecx, 32 + jb .bit_test - sub ecx, 32 - add ebx, 32 - add esi, 4 + sub ecx, 32 + add ebx, 32 + add esi, 4 .bit_test: - shl edx, cl - and edx, [esi] + shl edx, cl + and edx, [esi] .find: - bsf edi, edx - jz .high_mask - add ebx, edi - mov edi, [mem_block_list+ebx*4] + bsf edi, edx + jz .high_mask + add ebx, edi + mov edi, [mem_block_list+ebx*4] .check_size: - cmp eax, [edi+block_size] - ja .next - ret + cmp eax, [edi+block_size] + ja .next + ret .high_mask: - add esi, 4 - cmp esi, mem_block_mask+8 - jae .err - add ebx, 32 - mov edx, [esi] - jmp .find + add esi, 4 + cmp esi, mem_block_mask+8 + jae .err + add ebx, 32 + mov edx, [esi] + jmp .find .next: - mov edi, [edi+list_fd] - test edi, edi - jnz .check_size + mov edi, [edi+list_fd] + test edi, edi + jnz .check_size .err: - xor edi, edi - ret + xor edi, edi + ret align 4 alloc_mem_block: - mov ebx, [mem_block_start] - mov ecx, [mem_block_end] + mov ebx, [mem_block_start] + mov ecx, [mem_block_end] .l1: - bsf eax,[ebx]; - jnz found - add ebx,4 - cmp ebx, ecx - jb .l1 - xor eax,eax - ret + bsf eax,[ebx]; + jnz found + add ebx,4 + cmp ebx, ecx + jb .l1 + xor eax,eax + ret found: - btr [ebx], eax - mov [mem_block_start],ebx - sub ebx, mem_block_map - lea eax,[eax+ebx*8] - shl eax, 5 - add eax, [mem_block_arr] - dec [free_blocks] - ret + btr [ebx], eax + mov [mem_block_start],ebx + sub ebx, mem_block_map + lea eax,[eax+ebx*8] + shl eax, 5 + add eax, [mem_block_arr] + dec [free_blocks] + ret align 4 free_mem_block: - mov dword [eax], 0 - mov dword [eax+4], 0 - mov dword [eax+8], 0 - mov dword [eax+12], 0 - mov dword [eax+16], 0 + mov dword [eax], 0 + mov dword [eax+4], 0 + mov dword [eax+8], 0 + mov dword [eax+12], 0 + mov dword [eax+16], 0 ; mov dword [eax+20], 0 - mov dword [eax+24], 0 - mov dword [eax+28], 0 + mov dword [eax+24], 0 + mov dword [eax+28], 0 - sub eax, [mem_block_arr] - shr eax, 5 + sub eax, [mem_block_arr] + shr eax, 5 - mov ebx, mem_block_map - bts [ebx], eax - inc [free_blocks] - shr eax, 3 - and eax, not 3 - add eax, ebx - cmp [mem_block_start], eax - ja @f - ret + mov ebx, mem_block_map + bts [ebx], eax + inc [free_blocks] + shr eax, 3 + and eax, not 3 + add eax, ebx + cmp [mem_block_start], eax + ja @f + ret @@: - mov [mem_block_start], eax + mov [mem_block_start], eax ret .err: - xor eax, eax + xor eax, eax ret align 4 proc alloc_kernel_space stdcall, size:dword - local block_ind:DWORD + local block_ind:DWORD - push ebx - push esi - push edi + push ebx + push esi + push edi - mov eax, [size] - add eax, 4095 - and eax, not 4095 - mov [size], eax + mov eax, [size] + add eax, 4095 + and eax, not 4095 + mov [size], eax - mov ebx, heap_mutex - call wait_mutex ;ebx + mov ebx, heap_mutex + call wait_mutex ;ebx - cmp eax, [heap_free] - ja .error + cmp eax, [heap_free] + ja .error - call get_small_block ; eax - test edi, edi - jz .error + call get_small_block ; eax + test edi, edi + jz .error - cmp [edi+block_flags], FREE_BLOCK - jne .error + cmp [edi+block_flags], FREE_BLOCK + jne .error - mov [block_ind], ebx ;index of allocated block + mov [block_ind], ebx ;index of allocated block - mov eax, [edi+block_size] - cmp eax, [size] - je .m_eq_size + mov eax, [edi+block_size] + cmp eax, [size] + je .m_eq_size - call alloc_mem_block - and eax, eax - jz .error + call alloc_mem_block + and eax, eax + jz .error - mov esi, eax ;esi - splitted block + mov esi, eax ;esi - splitted block - mov [esi+block_next], edi - mov eax, [edi+block_prev] - mov [esi+block_prev], eax - mov [edi+block_prev], esi - mov [esi+list_fd], 0 - mov [esi+list_bk], 0 - and eax, eax - jz @f - mov [eax+block_next], esi + mov [esi+block_next], edi + mov eax, [edi+block_prev] + mov [esi+block_prev], eax + mov [edi+block_prev], esi + mov [esi+list_fd], 0 + mov [esi+list_bk], 0 + and eax, eax + jz @f + mov [eax+block_next], esi @@: - mov ebx, [edi+block_base] - mov [esi+block_base], ebx - mov edx, [size] - mov [esi+block_size], edx - add [edi+block_base], edx - sub [edi+block_size], edx + mov ebx, [edi+block_base] + mov [esi+block_base], ebx + mov edx, [size] + mov [esi+block_size], edx + add [edi+block_base], edx + sub [edi+block_size], edx - mov eax, [edi+block_size] - shr eax, 12 - sub eax, 1 - cmp eax, 63 - jna @f - mov eax, 63 + mov eax, [edi+block_size] + shr eax, 12 + sub eax, 1 + cmp eax, 63 + jna @f + mov eax, 63 @@: - cmp eax, [block_ind] - je .m_eq_ind + cmp eax, [block_ind] + je .m_eq_ind - remove_from_list edi + remove_from_list edi - mov ecx, [block_ind] - mov [mem_block_list+ecx*4], edx + mov ecx, [block_ind] + mov [mem_block_list+ecx*4], edx - test edx, edx - jnz @f - btr [mem_block_mask], ecx + test edx, edx + jnz @f + btr [mem_block_mask], ecx @@: - mov edx, [mem_block_list+eax*4] - mov [edi+list_fd], edx - test edx, edx - jz @f - mov [edx+list_bk], edi + mov edx, [mem_block_list+eax*4] + mov [edi+list_fd], edx + test edx, edx + jz @f + mov [edx+list_bk], edi @@: - mov [mem_block_list+eax*4], edi - bts [mem_block_mask], eax + mov [mem_block_list+eax*4], edi + bts [mem_block_mask], eax .m_eq_ind: - mov ecx, mem_used.fd-MEM_LIST_OFFSET - mov edx, [ecx+list_fd] - mov [esi+list_fd], edx - mov [esi+list_bk], ecx - mov [ecx+list_fd], esi - mov [edx+list_bk], esi + mov ecx, mem_used.fd-MEM_LIST_OFFSET + mov edx, [ecx+list_fd] + mov [esi+list_fd], edx + mov [esi+list_bk], ecx + mov [ecx+list_fd], esi + mov [edx+list_bk], esi - mov [esi+block_flags], USED_BLOCK - mov eax, [esi+block_base] - mov ebx, [size] - sub [heap_free], ebx - and [heap_mutex], 0 - pop edi - pop esi - pop ebx - ret + mov [esi+block_flags], USED_BLOCK + mov eax, [esi+block_base] + mov ebx, [size] + sub [heap_free], ebx + and [heap_mutex], 0 + pop edi + pop esi + pop ebx + ret .m_eq_size: - remove_from_list edi - mov [mem_block_list+ebx*4], edx - and edx, edx - jnz @f - btr [mem_block_mask], ebx + remove_from_list edi + mov [mem_block_list+ebx*4], edx + and edx, edx + jnz @f + btr [mem_block_mask], ebx @@: - mov ecx, mem_used.fd-MEM_LIST_OFFSET - mov edx, [ecx+list_fd] - mov [edi+list_fd], edx - mov [edi+list_bk], ecx - mov [ecx+list_fd], edi - mov [edx+list_bk], edi + mov ecx, mem_used.fd-MEM_LIST_OFFSET + mov edx, [ecx+list_fd] + mov [edi+list_fd], edx + mov [edi+list_bk], ecx + mov [ecx+list_fd], edi + mov [edx+list_bk], edi - mov [edi+block_flags], USED_BLOCK - mov eax, [edi+block_base] - mov ebx, [size] - sub [heap_free], ebx - and [heap_mutex], 0 - pop edi - pop esi - pop ebx - ret + mov [edi+block_flags], USED_BLOCK + mov eax, [edi+block_base] + mov ebx, [size] + sub [heap_free], ebx + and [heap_mutex], 0 + pop edi + pop esi + pop ebx + ret .error: - xor eax, eax - mov [heap_mutex], eax - pop edi - pop esi - pop ebx - ret + xor eax, eax + mov [heap_mutex], eax + pop edi + pop esi + pop ebx + ret endp align 4 proc free_kernel_space stdcall uses ebx ecx edx esi edi, base:dword - push ebx - push esi - push edi - mov ebx, heap_mutex - call wait_mutex ;ebx + push ebx + push esi + push edi + mov ebx, heap_mutex + call wait_mutex ;ebx - mov eax, [base] - mov esi, [mem_used.fd] + mov eax, [base] + mov esi, [mem_used.fd] @@: - cmp esi, mem_used.fd-MEM_LIST_OFFSET - je .fail + cmp esi, mem_used.fd-MEM_LIST_OFFSET + je .fail - cmp [esi+block_base], eax - je .found - mov esi, [esi+list_fd] - jmp @b + cmp [esi+block_base], eax + je .found + mov esi, [esi+list_fd] + jmp @b .found: - cmp [esi+block_flags], USED_BLOCK - jne .fail + cmp [esi+block_flags], USED_BLOCK + jne .fail - mov eax, [esi+block_size] - add [heap_free], eax + mov eax, [esi+block_size] + add [heap_free], eax - mov edi, [esi+block_next] - test edi, edi - jz .prev + mov edi, [esi+block_next] + test edi, edi + jz .prev - cmp [edi+block_flags], FREE_BLOCK - jne .prev + cmp [edi+block_flags], FREE_BLOCK + jne .prev - remove_from_free edi + remove_from_free edi - mov edx, [edi+block_next] - mov [esi+block_next], edx - test edx, edx - jz @f + mov edx, [edi+block_next] + mov [esi+block_next], edx + test edx, edx + jz @f - mov [edx+block_prev], esi + mov [edx+block_prev], esi @@: - mov ecx, [edi+block_size] - add [esi+block_size], ecx + mov ecx, [edi+block_size] + add [esi+block_size], ecx - mov eax, edi - call free_mem_block + mov eax, edi + call free_mem_block .prev: - mov edi, [esi+block_prev] - test edi, edi - jz .insert + mov edi, [esi+block_prev] + test edi, edi + jz .insert - cmp [edi+block_flags], FREE_BLOCK - jne .insert + cmp [edi+block_flags], FREE_BLOCK + jne .insert - remove_from_used esi + remove_from_used esi - mov edx, [esi+block_next] - mov [edi+block_next], edx - test edx, edx - jz @f - mov [edx+block_prev], edi + mov edx, [esi+block_next] + mov [edi+block_next], edx + test edx, edx + jz @f + mov [edx+block_prev], edi @@: - mov eax, esi - call free_mem_block + mov eax, esi + call free_mem_block - mov ecx, [edi+block_size] - mov eax, [esi+block_size] - add eax, ecx - mov [edi+block_size], eax + mov ecx, [edi+block_size] + mov eax, [esi+block_size] + add eax, ecx + mov [edi+block_size], eax - calc_index eax - calc_index ecx - cmp eax, ecx - je .m_eq + calc_index eax + calc_index ecx + cmp eax, ecx + je .m_eq - push ecx - remove_from_list edi - pop ecx + push ecx + remove_from_list edi + pop ecx - cmp [mem_block_list+ecx*4], edi - jne @f - mov [mem_block_list+ecx*4], edx + cmp [mem_block_list+ecx*4], edi + jne @f + mov [mem_block_list+ecx*4], edx @@: - cmp [mem_block_list+ecx*4], 0 - jne @f - btr [mem_block_mask], ecx + cmp [mem_block_list+ecx*4], 0 + jne @f + btr [mem_block_mask], ecx @@: - mov esi, [mem_block_list+eax*4] - mov [mem_block_list+eax*4], edi - mov [edi+list_fd], esi - test esi, esi - jz @f - mov [esi+list_bk], edi + mov esi, [mem_block_list+eax*4] + mov [mem_block_list+eax*4], edi + mov [edi+list_fd], esi + test esi, esi + jz @f + mov [esi+list_bk], edi @@: - bts [mem_block_mask], eax + bts [mem_block_mask], eax .m_eq: - xor eax, eax - mov [heap_mutex], eax - dec eax - pop edi - pop esi - pop ebx - ret + xor eax, eax + mov [heap_mutex], eax + dec eax + pop edi + pop esi + pop ebx + ret .insert: - remove_from_used esi + remove_from_used esi - mov eax, [esi+block_size] - calc_index eax + mov eax, [esi+block_size] + calc_index eax - mov edi, [mem_block_list+eax*4] - mov [mem_block_list+eax*4], esi - mov [esi+list_fd], edi - test edi, edi - jz @f - mov [edi+list_bk], esi + mov edi, [mem_block_list+eax*4] + mov [mem_block_list+eax*4], esi + mov [esi+list_fd], edi + test edi, edi + jz @f + mov [edi+list_bk], esi @@: - bts [mem_block_mask], eax - mov [esi+block_flags],FREE_BLOCK - xor eax, eax - mov [heap_mutex], eax - dec eax - pop edi - pop esi - pop ebx - ret + bts [mem_block_mask], eax + mov [esi+block_flags],FREE_BLOCK + xor eax, eax + mov [heap_mutex], eax + dec eax + pop edi + pop esi + pop ebx + ret .fail: - xor eax, eax - mov [heap_mutex], eax - pop edi - pop esi - pop ebx - ret + xor eax, eax + mov [heap_mutex], eax + pop edi + pop esi + pop ebx + ret endp align 4 proc kernel_alloc stdcall, size:dword - locals - lin_addr dd ? - pages_count dd ? - endl + locals + lin_addr dd ? + pages_count dd ? + endl - push ebx - push edi - push edx + push ebx + push edi + push edx - mov eax, [size] - add eax, 4095 - and eax, not 4095; - mov [size], eax - and eax, eax - jz .err - mov ebx, eax - shr ebx, 12 - mov [pages_count], ebx + mov eax, [size] + add eax, 4095 + and eax, not 4095; + mov [size], eax + and eax, eax + jz .err + mov ebx, eax + shr ebx, 12 + mov [pages_count], ebx - stdcall alloc_kernel_space, eax - test eax, eax - jz .err - mov [lin_addr], eax + stdcall alloc_kernel_space, eax + test eax, eax + jz .err + mov [lin_addr], eax - mov ecx, [pages_count] - mov edx, eax - mov ebx, ecx + mov ecx, [pages_count] + mov edx, eax + mov ebx, ecx - shr ecx, 3 - jz .next + shr ecx, 3 + jz .next - and ebx, not 7 - push ebx - stdcall alloc_pages, ebx - pop ecx ; yes ecx!!! - and eax, eax - jz .err + and ebx, not 7 + push ebx + stdcall alloc_pages, ebx + pop ecx ; yes ecx!!! + and eax, eax + jz .err - mov edi, eax - mov edx, [lin_addr] + mov edi, eax + mov edx, [lin_addr] @@: - stdcall map_page,edx,edi,dword PG_SW - add edx, 0x1000 - add edi, 0x1000 - dec ecx - jnz @B + stdcall map_page,edx,edi,dword PG_SW + add edx, 0x1000 + add edi, 0x1000 + dec ecx + jnz @B .next: - mov ecx, [pages_count] - and ecx, 7 - jz .end + mov ecx, [pages_count] + and ecx, 7 + jz .end @@: - push ecx - call alloc_page - pop ecx - test eax, eax - jz .err + push ecx + call alloc_page + pop ecx + test eax, eax + jz .err - stdcall map_page,edx,eax,dword PG_SW - add edx, 0x1000 - dec ecx - jnz @B + stdcall map_page,edx,eax,dword PG_SW + add edx, 0x1000 + dec ecx + jnz @B .end: - mov eax, [lin_addr] - pop edx - pop edi - pop ebx - ret + mov eax, [lin_addr] + pop edx + pop edi + pop ebx + ret .err: - xor eax, eax - pop edx - pop edi - pop ebx - ret + xor eax, eax + pop edx + pop edi + pop ebx + ret endp align 4 proc kernel_free stdcall, base:dword - push ebx esi + push ebx esi - mov ebx, heap_mutex - call wait_mutex ;ebx + mov ebx, heap_mutex + call wait_mutex ;ebx - mov eax, [base] - mov esi, [mem_used.fd] + mov eax, [base] + mov esi, [mem_used.fd] @@: - cmp esi, mem_used.fd-MEM_LIST_OFFSET - je .fail + cmp esi, mem_used.fd-MEM_LIST_OFFSET + je .fail - cmp [esi+block_base], eax - je .found - mov esi, [esi+list_fd] - jmp @b + cmp [esi+block_base], eax + je .found + mov esi, [esi+list_fd] + jmp @b .found: - cmp [esi+block_flags], USED_BLOCK - jne .fail + cmp [esi+block_flags], USED_BLOCK + jne .fail - and [heap_mutex], 0 + and [heap_mutex], 0 - push ecx - mov ecx, [esi+block_size]; - shr ecx, 12 - call release_pages ;eax, ecx - pop ecx - stdcall free_kernel_space, [base] - pop esi ebx - ret + push ecx + mov ecx, [esi+block_size]; + shr ecx, 12 + call release_pages ;eax, ecx + pop ecx + stdcall free_kernel_space, [base] + pop esi ebx + ret .fail: - and [heap_mutex], 0 - pop esi ebx - ret + and [heap_mutex], 0 + pop esi ebx + ret endp restore block_next @@ -657,485 +657,581 @@ HEAP_TOP equ 0x5FC00000 align 4 proc init_heap - mov ebx,[current_slot] - mov eax, [ebx+APPDATA.heap_top] - test eax, eax - jz @F - sub eax,[ebx+APPDATA.heap_base] - sub eax, 4096 - ret + mov ebx,[current_slot] + mov eax, [ebx+APPDATA.heap_top] + test eax, eax + jz @F + sub eax,[ebx+APPDATA.heap_base] + sub eax, 4096 + ret @@: - mov esi, [ebx+APPDATA.mem_size] - add esi, 4095 - and esi, not 4095 - mov [ebx+APPDATA.mem_size], esi - mov eax, HEAP_TOP - mov [ebx+APPDATA.heap_base], esi - mov [ebx+APPDATA.heap_top], eax + mov esi, [ebx+APPDATA.mem_size] + add esi, 4095 + and esi, not 4095 + mov [ebx+APPDATA.mem_size], esi + mov eax, HEAP_TOP + mov [ebx+APPDATA.heap_base], esi + mov [ebx+APPDATA.heap_top], eax - sub eax, esi - shr esi, 10 - mov ecx, eax - sub eax, 4096 - or ecx, FREE_BLOCK - mov [page_tabs+esi], ecx - ret + sub eax, esi + shr esi, 10 + mov ecx, eax + sub eax, 4096 + or ecx, FREE_BLOCK + mov [page_tabs+esi], ecx + ret endp align 4 proc user_alloc stdcall, alloc_size:dword - push ebx - push esi - push edi + push ebx + push esi + push edi - mov ecx, [alloc_size] - add ecx, (4095+4096) - and ecx, not 4095 + mov ecx, [alloc_size] + add ecx, (4095+4096) + and ecx, not 4095 - mov ebx, [current_slot] - mov esi, dword [ebx+APPDATA.heap_base] ; heap_base - mov edi, dword [ebx+APPDATA.heap_top] ; heap_top + mov ebx, [current_slot] + mov esi, dword [ebx+APPDATA.heap_base] ; heap_base + mov edi, dword [ebx+APPDATA.heap_top] ; heap_top l_0: - cmp esi, edi - jae m_exit + cmp esi, edi + jae m_exit - mov ebx, esi - shr ebx, 12 - mov eax, [page_tabs+ebx*4] - test al, FREE_BLOCK - jz test_used - and eax, 0xFFFFF000 - cmp eax, ecx ;alloc_size - jb m_next - jz @f + mov ebx, esi + shr ebx, 12 + mov eax, [page_tabs+ebx*4] + test al, FREE_BLOCK + jz test_used + and eax, 0xFFFFF000 + cmp eax, ecx ;alloc_size + jb m_next + jz @f - lea edx, [esi+ecx] - sub eax, ecx - or al, FREE_BLOCK - shr edx, 12 - mov [page_tabs+edx*4], eax + lea edx, [esi+ecx] + sub eax, ecx + or al, FREE_BLOCK + shr edx, 12 + mov [page_tabs+edx*4], eax @@: - or ecx, USED_BLOCK - mov [page_tabs+ebx*4], ecx - shr ecx, 12 - inc ebx - dec ecx - jz .no + or ecx, USED_BLOCK + mov [page_tabs+ebx*4], ecx + shr ecx, 12 + inc ebx + dec ecx + jz .no @@: - mov dword [page_tabs+ebx*4], 2 - inc ebx - dec ecx - jnz @B + mov dword [page_tabs+ebx*4], 2 + inc ebx + dec ecx + jnz @B .no: - mov edx, [current_slot] - mov ebx, [alloc_size] - add ebx, 0xFFF - and ebx, not 0xFFF - add ebx, [edx+APPDATA.mem_size] - call update_mem_size + mov edx, [current_slot] + mov ebx, [alloc_size] + add ebx, 0xFFF + and ebx, not 0xFFF + add ebx, [edx+APPDATA.mem_size] + call update_mem_size - lea eax, [esi+4096] + lea eax, [esi+4096] - pop edi - pop esi - pop ebx - ret + pop edi + pop esi + pop ebx + ret test_used: - test al, USED_BLOCK - jz m_exit + test al, USED_BLOCK + jz m_exit - and eax, 0xFFFFF000 + and eax, 0xFFFFF000 m_next: - add esi, eax - jmp l_0 + add esi, eax + jmp l_0 m_exit: - xor eax, eax - pop edi - pop esi - pop ebx - ret + xor eax, eax + pop edi + pop esi + pop ebx + ret +endp + +align 4 +proc user_alloc_at stdcall, address:dword, alloc_size:dword + + push ebx + push esi + push edi + + mov ebx, [current_slot] + mov edx, [address] + and edx, not 0xFFF + mov [address], edx + sub edx, 0x1000 + jb .error + mov esi, [ebx+APPDATA.heap_base] + mov edi, [ebx+APPDATA.heap_top] + cmp edx, esi + jb .error +.scan: + cmp esi, edi + jae .error + mov ebx, esi + shr ebx, 12 + mov eax, [page_tabs+ebx*4] + mov ecx, eax + and ecx, 0xFFFFF000 + add ecx, esi + cmp edx, ecx + jb .found + mov esi, ecx + jmp .scan +.error: + xor eax, eax + pop edi + pop esi + pop ebx + ret +.found: + test al, FREE_BLOCK + jz .error + mov eax, ecx + sub eax, edx + sub eax, 0x1000 + cmp eax, [alloc_size] + jb .error + +; Here we have 1 big free block which includes requested area. +; In general, 3 other blocks must be created instead: +; free at [esi, edx); +; busy at [edx, edx+0x1000+ALIGN_UP(alloc_size,0x1000)); +; free at [edx+0x1000+ALIGN_UP(alloc_size,0x1000), ecx) +; First or third block (or both) may be absent. + mov eax, edx + sub eax, esi + jz .nofirst + or al, FREE_BLOCK + mov [page_tabs+ebx*4], eax +.nofirst: + mov eax, [alloc_size] + add eax, 0x1FFF + and eax, not 0xFFF + mov ebx, edx + add edx, eax + shr ebx, 12 + or al, USED_BLOCK + mov [page_tabs+ebx*4], eax + shr eax, 12 + dec eax + jz .second_nofill + inc ebx +.fill: + mov dword [page_tabs+ebx*4], 2 + inc ebx + dec eax + jnz .fill +.second_nofill: + sub ecx, edx + jz .nothird + or cl, FREE_BLOCK + mov [page_tabs+ebx*4], ecx +.nothird: + + mov edx, [current_slot] + mov ebx, [alloc_size] + add ebx, 0xFFF + and ebx, not 0xFFF + add ebx, [edx+APPDATA.mem_size] + call update_mem_size + + mov eax, [address] + + pop edi + pop esi + pop ebx + ret endp align 4 proc user_free stdcall, base:dword - push esi + push esi - mov esi, [base] - test esi, esi - jz .exit + mov esi, [base] + test esi, esi + jz .exit - push ebx + push ebx - xor ebx, ebx - shr esi, 12 - mov eax, [page_tabs+(esi-1)*4] - test al, USED_BLOCK - jz .cantfree - test al, DONT_FREE_BLOCK - jnz .cantfree + xor ebx, ebx + shr esi, 12 + mov eax, [page_tabs+(esi-1)*4] + test al, USED_BLOCK + jz .cantfree + test al, DONT_FREE_BLOCK + jnz .cantfree - and eax, not 4095 - mov ecx, eax - or al, FREE_BLOCK - mov [page_tabs+(esi-1)*4], eax - sub ecx, 4096 - mov ebx, ecx - shr ecx, 12 - jz .released + and eax, not 4095 + mov ecx, eax + or al, FREE_BLOCK + mov [page_tabs+(esi-1)*4], eax + sub ecx, 4096 + mov ebx, ecx + shr ecx, 12 + jz .released .release: - xor eax, eax - xchg eax, [page_tabs+esi*4] - test al, 1 - jz @F - test eax, PG_SHARED - jnz @F - call free_page - mov eax, esi - shl eax, 12 - invlpg [eax] + xor eax, eax + xchg eax, [page_tabs+esi*4] + test al, 1 + jz @F + test eax, PG_SHARED + jnz @F + call free_page + mov eax, esi + shl eax, 12 + invlpg [eax] @@: - inc esi - dec ecx - jnz .release + inc esi + dec ecx + jnz .release .released: - push edi + push edi - mov edx, [current_slot] - mov esi, dword [edx+APPDATA.heap_base] - mov edi, dword [edx+APPDATA.heap_top] - sub ebx, [edx+APPDATA.mem_size] - neg ebx - call update_mem_size - call user_normalize - pop edi - pop ebx - pop esi - ret + mov edx, [current_slot] + mov esi, dword [edx+APPDATA.heap_base] + mov edi, dword [edx+APPDATA.heap_top] + sub ebx, [edx+APPDATA.mem_size] + neg ebx + call update_mem_size + call user_normalize + pop edi + pop ebx + pop esi + ret .exit: - xor eax, eax - inc eax - pop esi - ret + xor eax, eax + inc eax + pop esi + ret .cantfree: - xor eax, eax - pop ebx - pop esi - ret + xor eax, eax + pop ebx + pop esi + ret endp user_normalize: ; in: esi=heap_base, edi=heap_top ; out: eax=0 <=> OK ; destroys: ebx,edx,esi,edi - shr esi, 12 - shr edi, 12 + shr esi, 12 + shr edi, 12 @@: - mov eax, [page_tabs+esi*4] - test al, USED_BLOCK - jz .test_free - shr eax, 12 - add esi, eax - jmp @B + mov eax, [page_tabs+esi*4] + test al, USED_BLOCK + jz .test_free + shr eax, 12 + add esi, eax + jmp @B .test_free: - test al, FREE_BLOCK - jz .err - mov edx, eax - shr edx, 12 - add edx, esi - cmp edx, edi - jae .exit + test al, FREE_BLOCK + jz .err + mov edx, eax + shr edx, 12 + add edx, esi + cmp edx, edi + jae .exit - mov ebx, [page_tabs+edx*4] - test bl, USED_BLOCK - jz .next_free + mov ebx, [page_tabs+edx*4] + test bl, USED_BLOCK + jz .next_free - shr ebx, 12 - add edx, ebx - mov esi, edx - jmp @B + shr ebx, 12 + add edx, ebx + mov esi, edx + jmp @B .next_free: - test bl, FREE_BLOCK - jz .err - and dword [page_tabs+edx*4], 0 - add eax, ebx - and eax, not 4095 - or eax, FREE_BLOCK - mov [page_tabs+esi*4], eax - jmp @B + test bl, FREE_BLOCK + jz .err + and dword [page_tabs+edx*4], 0 + add eax, ebx + and eax, not 4095 + or eax, FREE_BLOCK + mov [page_tabs+esi*4], eax + jmp @B .exit: - xor eax, eax - inc eax - ret + xor eax, eax + inc eax + ret .err: - xor eax, eax - ret + xor eax, eax + ret user_realloc: ; in: eax = pointer, ebx = new size ; out: eax = new pointer or NULL - test eax, eax - jnz @f + test eax, eax + jnz @f ; realloc(NULL,sz) - same as malloc(sz) - push ebx - call user_alloc - ret + push ebx + call user_alloc + ret @@: - push ecx edx - lea ecx, [eax - 0x1000] - shr ecx, 12 - mov edx, [page_tabs+ecx*4] - test dl, USED_BLOCK - jnz @f + push ecx edx + lea ecx, [eax - 0x1000] + shr ecx, 12 + mov edx, [page_tabs+ecx*4] + test dl, USED_BLOCK + jnz @f ; attempt to realloc invalid pointer .ret0: - pop edx ecx - xor eax, eax - ret + pop edx ecx + xor eax, eax + ret @@: - test dl, DONT_FREE_BLOCK - jnz .ret0 - add ebx, 0x1FFF - shr edx, 12 - shr ebx, 12 + test dl, DONT_FREE_BLOCK + jnz .ret0 + add ebx, 0x1FFF + shr edx, 12 + shr ebx, 12 ; edx = allocated size, ebx = new size - add edx, ecx - add ebx, ecx - cmp edx, ebx - jb .realloc_add + add edx, ecx + add ebx, ecx + cmp edx, ebx + jb .realloc_add ; release part of allocated memory .loop: - cmp edx, ebx - jz .release_done - dec edx - xor eax, eax - xchg eax, [page_tabs+edx*4] - test al, 1 - jz .loop - call free_page - mov eax, edx - shl eax, 12 - invlpg [eax] - jmp .loop + cmp edx, ebx + jz .release_done + dec edx + xor eax, eax + xchg eax, [page_tabs+edx*4] + test al, 1 + jz .loop + call free_page + mov eax, edx + shl eax, 12 + invlpg [eax] + jmp .loop .release_done: - sub ebx, ecx - cmp ebx, 1 - jnz .nofreeall - mov eax, [page_tabs+ecx*4] - and eax, not 0xFFF - mov edx, [current_slot] - mov ebx, [APPDATA.mem_size+edx] - sub ebx, eax - add ebx, 0x1000 - or al, FREE_BLOCK - mov [page_tabs+ecx*4], eax - push esi edi - mov esi, [APPDATA.heap_base+edx] - mov edi, [APPDATA.heap_top+edx] - call update_mem_size - call user_normalize - pop edi esi - jmp .ret0 ; all freed + sub ebx, ecx + cmp ebx, 1 + jnz .nofreeall + mov eax, [page_tabs+ecx*4] + and eax, not 0xFFF + mov edx, [current_slot] + mov ebx, [APPDATA.mem_size+edx] + sub ebx, eax + add ebx, 0x1000 + or al, FREE_BLOCK + mov [page_tabs+ecx*4], eax + push esi edi + mov esi, [APPDATA.heap_base+edx] + mov edi, [APPDATA.heap_top+edx] + call update_mem_size + call user_normalize + pop edi esi + jmp .ret0 ; all freed .nofreeall: - sub edx, ecx - shl ebx, 12 - or ebx, USED_BLOCK - xchg [page_tabs+ecx*4], ebx - shr ebx, 12 - sub ebx, edx - push ebx ecx edx - mov edx, [current_slot] - shl ebx, 12 - sub ebx, [APPDATA.mem_size+edx] - neg ebx - call update_mem_size - pop edx ecx ebx - lea eax, [ecx+1] - shl eax, 12 - push eax - add ecx, edx - lea edx, [ecx+ebx] - shl ebx, 12 - jz .ret - push esi - mov esi, [current_slot] - mov esi, [APPDATA.heap_top+esi] - shr esi, 12 + sub edx, ecx + shl ebx, 12 + or ebx, USED_BLOCK + xchg [page_tabs+ecx*4], ebx + shr ebx, 12 + sub ebx, edx + push ebx ecx edx + mov edx, [current_slot] + shl ebx, 12 + sub ebx, [APPDATA.mem_size+edx] + neg ebx + call update_mem_size + pop edx ecx ebx + lea eax, [ecx+1] + shl eax, 12 + push eax + add ecx, edx + lea edx, [ecx+ebx] + shl ebx, 12 + jz .ret + push esi + mov esi, [current_slot] + mov esi, [APPDATA.heap_top+esi] + shr esi, 12 @@: - cmp edx, esi - jae .merge_done - mov eax, [page_tabs+edx*4] - test al, USED_BLOCK - jnz .merge_done - and dword [page_tabs+edx*4], 0 - shr eax, 12 - add edx, eax - shl eax, 12 - add ebx, eax - jmp @b + cmp edx, esi + jae .merge_done + mov eax, [page_tabs+edx*4] + test al, USED_BLOCK + jnz .merge_done + and dword [page_tabs+edx*4], 0 + shr eax, 12 + add edx, eax + shl eax, 12 + add ebx, eax + jmp @b .merge_done: - pop esi - or ebx, FREE_BLOCK - mov [page_tabs+ecx*4], ebx + pop esi + or ebx, FREE_BLOCK + mov [page_tabs+ecx*4], ebx .ret: - pop eax edx ecx - ret + pop eax edx ecx + ret .realloc_add: ; get some additional memory - mov eax, [current_slot] - mov eax, [APPDATA.heap_top+eax] - shr eax, 12 - cmp edx, eax - jae .cant_inplace - mov eax, [page_tabs+edx*4] - test al, FREE_BLOCK - jz .cant_inplace - shr eax, 12 - add eax, edx - sub eax, ebx - jb .cant_inplace - jz @f - shl eax, 12 - or al, FREE_BLOCK - mov [page_tabs+ebx*4], eax + mov eax, [current_slot] + mov eax, [APPDATA.heap_top+eax] + shr eax, 12 + cmp edx, eax + jae .cant_inplace + mov eax, [page_tabs+edx*4] + test al, FREE_BLOCK + jz .cant_inplace + shr eax, 12 + add eax, edx + sub eax, ebx + jb .cant_inplace + jz @f + shl eax, 12 + or al, FREE_BLOCK + mov [page_tabs+ebx*4], eax @@: - mov eax, ebx - sub eax, ecx - shl eax, 12 - or al, USED_BLOCK - mov [page_tabs+ecx*4], eax - lea eax, [ecx+1] - shl eax, 12 - push eax - push edi - lea edi, [page_tabs+edx*4] - mov eax, 2 - sub ebx, edx - mov ecx, ebx - cld - rep stosd - pop edi - mov edx, [current_slot] - shl ebx, 12 - add ebx, [APPDATA.mem_size+edx] - call update_mem_size - pop eax edx ecx - ret + mov eax, ebx + sub eax, ecx + shl eax, 12 + or al, USED_BLOCK + mov [page_tabs+ecx*4], eax + lea eax, [ecx+1] + shl eax, 12 + push eax + push edi + lea edi, [page_tabs+edx*4] + mov eax, 2 + sub ebx, edx + mov ecx, ebx + cld + rep stosd + pop edi + mov edx, [current_slot] + shl ebx, 12 + add ebx, [APPDATA.mem_size+edx] + call update_mem_size + pop eax edx ecx + ret .cant_inplace: - push esi edi - mov eax, [current_slot] - mov esi, [APPDATA.heap_base+eax] - mov edi, [APPDATA.heap_top+eax] - shr esi, 12 - shr edi, 12 - sub ebx, ecx + push esi edi + mov eax, [current_slot] + mov esi, [APPDATA.heap_base+eax] + mov edi, [APPDATA.heap_top+eax] + shr esi, 12 + shr edi, 12 + sub ebx, ecx .find_place: - cmp esi, edi - jae .place_not_found - mov eax, [page_tabs+esi*4] - test al, FREE_BLOCK - jz .next_place - shr eax, 12 - cmp eax, ebx - jae .place_found - add esi, eax - jmp .find_place + cmp esi, edi + jae .place_not_found + mov eax, [page_tabs+esi*4] + test al, FREE_BLOCK + jz .next_place + shr eax, 12 + cmp eax, ebx + jae .place_found + add esi, eax + jmp .find_place .next_place: - shr eax, 12 - add esi, eax - jmp .find_place + shr eax, 12 + add esi, eax + jmp .find_place .place_not_found: - pop edi esi - jmp .ret0 + pop edi esi + jmp .ret0 .place_found: - sub eax, ebx - jz @f - push esi - add esi, ebx - shl eax, 12 - or al, FREE_BLOCK - mov [page_tabs+esi*4], eax - pop esi + sub eax, ebx + jz @f + push esi + add esi, ebx + shl eax, 12 + or al, FREE_BLOCK + mov [page_tabs+esi*4], eax + pop esi @@: - mov eax, ebx - shl eax, 12 - or al, USED_BLOCK - mov [page_tabs+esi*4], eax - inc esi - mov eax, esi - shl eax, 12 - push eax - mov eax, [page_tabs+ecx*4] - and eax, not 0xFFF - or al, FREE_BLOCK - sub edx, ecx - mov [page_tabs+ecx*4], eax - inc ecx - dec ebx - dec edx - jz .no + mov eax, ebx + shl eax, 12 + or al, USED_BLOCK + mov [page_tabs+esi*4], eax + inc esi + mov eax, esi + shl eax, 12 + push eax + mov eax, [page_tabs+ecx*4] + and eax, not 0xFFF + or al, FREE_BLOCK + sub edx, ecx + mov [page_tabs+ecx*4], eax + inc ecx + dec ebx + dec edx + jz .no @@: - xor eax, eax - xchg eax, [page_tabs+ecx*4] - mov [page_tabs+esi*4], eax - mov eax, ecx - shl eax, 12 - invlpg [eax] - inc esi - inc ecx - dec ebx - dec edx - jnz @b + xor eax, eax + xchg eax, [page_tabs+ecx*4] + mov [page_tabs+esi*4], eax + mov eax, ecx + shl eax, 12 + invlpg [eax] + inc esi + inc ecx + dec ebx + dec edx + jnz @b .no: - push ebx - mov edx, [current_slot] - shl ebx, 12 - add ebx, [APPDATA.mem_size+edx] - call update_mem_size - pop ebx + push ebx + mov edx, [current_slot] + shl ebx, 12 + add ebx, [APPDATA.mem_size+edx] + call update_mem_size + pop ebx @@: - mov dword [page_tabs+esi*4], 2 - inc esi - dec ebx - jnz @b - pop eax edi esi edx ecx - ret + mov dword [page_tabs+esi*4], 2 + inc esi + dec ebx + jnz @b + pop eax edi esi edx ecx + ret if 0 align 4 proc alloc_dll - pushf - cli - bsf eax, [dll_map] - jnz .find - popf - xor eax, eax - ret + pushf + cli + bsf eax, [dll_map] + jnz .find + popf + xor eax, eax + ret .find: - btr [dll_map], eax - popf - shl eax, 5 - add eax, dll_tab - ret + btr [dll_map], eax + popf + shl eax, 5 + add eax, dll_tab + ret endp align 4 proc alloc_service - pushf - cli - bsf eax, [srv_map] - jnz .find - popf - xor eax, eax - ret + pushf + cli + bsf eax, [srv_map] + jnz .find + popf + xor eax, eax + ret .find: - btr [srv_map], eax - popf - shl eax,0x02 - lea eax,[srv_tab+eax+eax*8] ;srv_tab+eax*36 - ret + btr [srv_map], eax + popf + shl eax,0x02 + lea eax,[srv_tab+eax+eax*8] ;srv_tab+eax*36 + ret endp end if @@ -1150,295 +1246,296 @@ end if align 4 destroy_smap: - pushfd - cli + pushfd + cli - push esi - push edi + push esi + push edi - mov edi, eax - mov esi, [eax+SMAP.parent] - test esi, esi - jz .done + mov edi, eax + mov esi, [eax+SMAP.parent] + test esi, esi + jz .done - lock dec [esi+SMEM.refcount] - jnz .done + lock dec [esi+SMEM.refcount] + jnz .done - mov ecx, [esi+SMEM.bk] - mov edx, [esi+SMEM.fd] + mov ecx, [esi+SMEM.bk] + mov edx, [esi+SMEM.fd] - mov [ecx+SMEM.fd], edx - mov [edx+SMEM.bk], ecx + mov [ecx+SMEM.fd], edx + mov [edx+SMEM.bk], ecx - stdcall kernel_free, [esi+SMEM.base] - mov eax, esi - call free + stdcall kernel_free, [esi+SMEM.base] + mov eax, esi + call free .done: - mov eax, edi - call destroy_kernel_object + mov eax, edi + call destroy_kernel_object - pop edi - pop esi - popfd + pop edi + pop esi + popfd - ret + ret -E_NOTFOUND equ 5 -E_ACCESS equ 10 -E_NOMEM equ 30 -E_PARAM equ 33 +E_NOTFOUND equ 5 +E_ACCESS equ 10 +E_NOMEM equ 30 +E_PARAM equ 33 -SHM_READ equ 0 -SHM_WRITE equ 1 +SHM_READ equ 0 +SHM_WRITE equ 1 SHM_ACCESS_MASK equ 3 -SHM_OPEN equ (0 shl 2) +SHM_OPEN equ (0 shl 2) SHM_OPEN_ALWAYS equ (1 shl 2) -SHM_CREATE equ (2 shl 2) +SHM_CREATE equ (2 shl 2) -SHM_OPEN_MASK equ (3 shl 2) +SHM_OPEN_MASK equ (3 shl 2) align 4 proc shmem_open stdcall name:dword, size:dword, access:dword - locals - action dd ? - owner_access dd ? - mapped dd ? - endl + locals + action dd ? + owner_access dd ? + mapped dd ? + endl - push ebx - push esi - push edi + push ebx + push esi + push edi - mov [mapped], 0 - mov [owner_access], 0 + mov [mapped], 0 + mov [owner_access], 0 - pushfd ;mutex required - cli + pushfd ;mutex required + cli - mov eax, [access] - and eax, SHM_OPEN_MASK - mov [action], eax + mov eax, [access] + and eax, SHM_OPEN_MASK + mov [action], eax - mov eax, [name] - test eax, eax - mov edx, E_PARAM - jz .exit + mov ebx, [name] + test ebx, ebx + mov edx, E_PARAM + jz .fail - mov esi, [shmem_list.fd] + mov esi, [shmem_list.fd] align 4 @@: - cmp esi, shmem_list - je .not_found + cmp esi, shmem_list + je .not_found - lea edx, [esi+SMEM.name] ; link , base, size - stdcall strncmp, edx, eax, 32 - test eax, eax - je .found + lea edx, [esi+SMEM.name] ; link , base, size + stdcall strncmp, edx, ebx, 32 + test eax, eax + je .found - mov esi, [esi+SMEM.fd] - jmp @B + mov esi, [esi+SMEM.fd] + jmp @B .not_found: - mov eax, [action] + mov eax, [action] - cmp eax, SHM_OPEN - mov edx, E_NOTFOUND - je .exit + cmp eax, SHM_OPEN + mov edx, E_NOTFOUND + je .fail - cmp eax, SHM_CREATE - mov edx, E_PARAM - je .create_shm + cmp eax, SHM_CREATE + mov edx, E_PARAM + je .create_shm - cmp eax, SHM_OPEN_ALWAYS - jne .exit + cmp eax, SHM_OPEN_ALWAYS + jne .fail .create_shm: - mov ecx, [size] - test ecx, ecx - jz .exit + mov ecx, [size] + test ecx, ecx + jz .fail - add ecx, 4095 - and ecx, -4096 - mov [size], ecx + add ecx, 4095 + and ecx, -4096 + mov [size], ecx - mov eax, SMEM.sizeof - call malloc - test eax, eax - mov esi, eax - mov edx, E_NOMEM - jz .exit + mov eax, SMEM.sizeof + call malloc + test eax, eax + mov esi, eax + mov edx, E_NOMEM + jz .fail - stdcall kernel_alloc, [size] - test eax, eax - mov [mapped], eax - mov edx, E_NOMEM - jz .cleanup + stdcall kernel_alloc, [size] + test eax, eax + mov [mapped], eax + mov edx, E_NOMEM + jz .cleanup - mov ecx, [size] - mov edx, [access] - and edx, SHM_ACCESS_MASK + mov ecx, [size] + mov edx, [access] + and edx, SHM_ACCESS_MASK - mov [esi+SMEM.base], eax - mov [esi+SMEM.size], ecx - mov [esi+SMEM.access], edx - mov [esi+SMEM.refcount], 0 - mov [esi+SMEM.name+28], 0 + mov [esi+SMEM.base], eax + mov [esi+SMEM.size], ecx + mov [esi+SMEM.access], edx + mov [esi+SMEM.refcount], 0 + mov [esi+SMEM.name+28], 0 - lea eax, [esi+SMEM.name] - stdcall strncpy, eax, [name], 31 + lea eax, [esi+SMEM.name] + stdcall strncpy, eax, [name], 31 - mov eax, [shmem_list.fd] - mov [esi+SMEM.bk], shmem_list - mov [esi+SMEM.fd], eax + mov eax, [shmem_list.fd] + mov [esi+SMEM.bk], shmem_list + mov [esi+SMEM.fd], eax - mov [eax+SMEM.bk], esi - mov [shmem_list.fd], esi + mov [eax+SMEM.bk], esi + mov [shmem_list.fd], esi - mov [action], SHM_OPEN - mov [owner_access], SHM_WRITE + mov [action], SHM_OPEN + mov [owner_access], SHM_WRITE .found: - mov eax, [action] + mov eax, [action] - cmp eax, SHM_CREATE - mov edx, E_ACCESS - je .exit + cmp eax, SHM_CREATE + mov edx, E_ACCESS + je .exit - cmp eax, SHM_OPEN - mov edx, E_PARAM - je .create_map + cmp eax, SHM_OPEN + mov edx, E_PARAM + je .create_map - cmp eax, SHM_OPEN_ALWAYS - jne .exit + cmp eax, SHM_OPEN_ALWAYS + jne .fail .create_map: - mov eax, [access] - and eax, SHM_ACCESS_MASK - cmp eax, [esi+SMEM.access] - mov [access], eax - mov edx, E_ACCESS - ja .exit + mov eax, [access] + and eax, SHM_ACCESS_MASK + cmp eax, [esi+SMEM.access] + mov [access], eax + mov edx, E_ACCESS + ja .fail - mov ebx, [CURRENT_TASK] - shl ebx, 5 - mov ebx, [CURRENT_TASK+ebx+4] - mov eax, SMAP.sizeof + mov ebx, [CURRENT_TASK] + shl ebx, 5 + mov ebx, [CURRENT_TASK+ebx+4] + mov eax, SMAP.sizeof - call create_kernel_object - test eax, eax - mov edi, eax - mov edx, E_NOMEM - jz .exit + call create_kernel_object + test eax, eax + mov edi, eax + mov edx, E_NOMEM + jz .fail - mov [edi+SMAP.magic], 'SMAP' - mov [edi+SMAP.destroy], destroy_smap - mov [edi+SMAP.base], 0 - mov [edi+SMAP.parent], 0 + inc [esi+SMEM.refcount] - stdcall user_alloc, [esi+SMEM.size] - test eax, eax - mov [mapped], eax - mov edx, E_NOMEM - jz .cleanup2 + mov [edi+SMAP.magic], 'SMAP' + mov [edi+SMAP.destroy], destroy_smap + mov [edi+SMAP.parent], esi + mov [edi+SMAP.base], 0 - lock inc [esi+SMEM.refcount] - mov [edi+SMAP.base], eax - mov [edi+SMAP.parent], esi + stdcall user_alloc, [esi+SMEM.size] + test eax, eax + mov [mapped], eax + mov edx, E_NOMEM + jz .cleanup2 - mov ecx, [esi+SMEM.size] - mov [size], ecx + mov [edi+SMAP.base], eax - shr ecx, 12 - shr eax, 10 + mov ecx, [esi+SMEM.size] + mov [size], ecx - mov esi, [esi+SMEM.base] - shr esi, 10 - lea edi, [page_tabs+eax] - add esi, page_tabs + shr ecx, 12 + shr eax, 10 - mov edx, [access] - or edx, [owner_access] - shl edx, 1 - or edx, PG_USER+PG_SHARED + mov esi, [esi+SMEM.base] + shr esi, 10 + lea edi, [page_tabs+eax] + add esi, page_tabs + + mov edx, [access] + or edx, [owner_access] + shl edx, 1 + or edx, PG_USER+PG_SHARED @@: - lodsd - and eax, 0xFFFFF000 - or eax, edx - stosd - loop @B + lodsd + and eax, 0xFFFFF000 + or eax, edx + stosd + loop @B - xor edx, edx + xor edx, edx - cmp [owner_access], 0 - jne .exit - - mov edx, [size] + cmp [owner_access], 0 + jne .fail .exit: - mov eax, [mapped] - - popfd - pop edi - pop esi - pop ebx - ret + mov edx, [size] +.fail: + mov eax, [mapped] + popfd + pop edi + pop esi + pop ebx + ret .cleanup: - mov eax, esi - call free - jmp .exit + mov [size], edx + mov eax, esi + call free + jmp .exit .cleanup2: - mov eax, edi - call destroy_smap - jmp .exit + mov [size], edx + mov eax, edi + call destroy_smap + jmp .exit endp align 4 proc shmem_close stdcall, name:dword - mov eax, [name] - test eax, eax - jz .fail + mov eax, [name] + test eax, eax + jz .fail - push esi - push edi - pushfd - cli + push esi + push edi + pushfd + cli - mov esi, [current_slot] - add esi, APP_OBJ_OFFSET + mov esi, [current_slot] + add esi, APP_OBJ_OFFSET .next: - mov eax, [esi+APPOBJ.fd] - test eax, eax - jz @F + mov eax, [esi+APPOBJ.fd] + test eax, eax + jz @F - cmp eax, esi - mov esi, eax - je @F + cmp eax, esi + mov esi, eax + je @F - cmp [eax+SMAP.magic], 'SMAP' - jne .next + cmp [eax+SMAP.magic], 'SMAP' + jne .next - mov edi, [eax+SMAP.parent] - test edi, edi - jz .next + mov edi, [eax+SMAP.parent] + test edi, edi + jz .next - lea eax, [edi+SMEM.name] - stdcall strncmp, [name], edi, 32 - test eax, eax - jne .next + lea eax, [edi+SMEM.name] + stdcall strncmp, [name], edi, 32 + test eax, eax + jne .next - stdcall user_free, [esi+SMAP.base] + stdcall user_free, [esi+SMAP.base] - call [esi+APPOBJ.destroy] + call [esi+APPOBJ.destroy] @@: - popfd - pop edi - pop esi + popfd + pop edi + pop esi .fail: - ret + ret endp diff --git a/kernel/branches/net/core/malloc.inc b/kernel/branches/net/core/malloc.inc index 0b9bfd3b8b..edf3ee53eb 100644 --- a/kernel/branches/net/core/malloc.inc +++ b/kernel/branches/net/core/malloc.inc @@ -1,6 +1,6 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; -;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;; +;; Copyright (C) KolibriOS team 2004-2009. All rights reserved. ;; ;; Distributed under terms of the GNU General Public License ;; ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -20,6 +20,7 @@ $Revision$ ; esi= nb ; ebx= idx ; +align 16 malloc: push esi @@ -134,13 +135,17 @@ malloc: mov [eax+12], ecx ; r->bk = B; mov eax, ebx pop esi + mov [mst.mutex], 0 ret .small: ; if (ms.treemap != 0 && (mem = malloc_small(nb)) != 0) - - cmp [mst.treemap], 0 - je .from_top +;;;;;;;;;;; start a change + mov eax,[mst.treemap] + test eax,eax +;;;;;;;;;;; end the change +; cmp [mst.treemap], 0 + jz .from_top mov eax, esi call malloc_small test eax, eax @@ -196,7 +201,6 @@ malloc: ; param ; eax= mem -align 4 free: push edi mov edi, eax @@ -246,7 +250,7 @@ free: shr ecx, 3 cmp eax, edx jne @F - and [mst.smallmap], ecx + btr [mst.smallmap], ecx @@: mov [eax+12], edx ;F->bk = B; mov [edx+8], eax ;B->fd = F @@ -383,7 +387,6 @@ free: ; ecx = chunk ; eax = size -align 4 insert_chunk: cmp eax, 256 @@ -416,13 +419,11 @@ insert_chunk: and [mst.mutex], 0 ret -align 4 ; param ; esi= chunk ; ebx= size -align 4 insert_large_chunk: ; I = compute_tree_index(S); @@ -475,7 +476,6 @@ insert_large_chunk: shl eax, cl ;eax= K jmp .loop - .not_eq_size: ; C = &(T->child[(K >> 31) & 1]); @@ -517,7 +517,6 @@ insert_large_chunk: mov [esi+8], eax mov [esi+12], edx ret - .insert_child: ; *C = X; @@ -536,7 +535,6 @@ insert_large_chunk: ; param ; edx= chunk -align 4 unlink_large_chunk: mov eax, [edx+12] @@ -593,17 +591,21 @@ unlink_large_chunk: btr [mst.treemap], ecx pop edi ret + .l3: cmp [edi+16], edx jne @F mov [edi+16], eax jmp .l4 + @@: mov [edi+20], eax + .l4: test eax, eax je .done + .l5: mov [eax+24], edi mov ecx, [edx+16] @@ -612,6 +614,7 @@ unlink_large_chunk: mov [eax+16], ecx mov [ecx+24], eax + .l6: mov edx, [edx+20] test edx, edx @@ -619,6 +622,7 @@ unlink_large_chunk: mov [eax+20], edx mov [edx+24], eax + .done: pop edi ret @@ -626,7 +630,6 @@ unlink_large_chunk: ; param ; esi= nb -align 4 malloc_small: push ebp mov ebp, esi @@ -641,8 +644,10 @@ malloc_small: mov edi, [ecx+4] and edi, -4 sub edi, esi + .loop: mov ebx, ecx + .loop_1: ; while ((t = leftmost_child(t)) != 0) @@ -652,8 +657,10 @@ malloc_small: jz @F mov ecx, eax jmp .l1 + @@: mov ecx, [ecx+20] + .l1: test ecx, ecx jz .unlink @@ -704,6 +711,7 @@ malloc_small: lea eax, [ebx+8] ret + .split: ; v->head = nb|PINUSE_BIT|CINUSE_BIT; @@ -736,6 +744,7 @@ malloc_small: pop ebp lea eax, [ebx+8] ret + .large: lea eax, [ebx+8] push eax @@ -750,12 +759,12 @@ malloc_small: ; param ; esi= nb -align 4 malloc_large: .idx equ esp+4 .rst equ esp push ebp + push esi push edi sub esp, 8 ; v = 0; @@ -789,17 +798,20 @@ malloc_large: jne @F xor ecx, ecx jmp .l1 + @@: mov edx, ecx shr edx, 1 mov ecx, 37 sub ecx, edx + .l1: mov edx, ebx shl edx, cl ; rst = 0; mov [.rst], ebp + .loop: ; trem = (t->head & ~INUSE_BITS) - nb; @@ -819,6 +831,7 @@ malloc_large: mov ebp, eax mov edi, ecx je .l2 + @@: ; rt = t->child[1]; @@ -840,6 +853,7 @@ malloc_large: ; rst = rt; mov [.rst], ecx + @@: ; if (t == 0) @@ -850,9 +864,11 @@ malloc_large: add edx, edx jmp .loop + @@: ; t = rst; mov eax, [.rst] + .l2: ; if (t == 0 && v == 0) @@ -861,6 +877,7 @@ malloc_large: test ebp, ebp jne .l7 mov ecx, [.idx] + .l3: ; leftbits = (-1<head & ~INUSE_BITS) - nb; @@ -896,6 +915,7 @@ malloc_large: mov edi, ecx ; v = t; mov ebp, eax + @@: ; t = leftmost_child(t); @@ -905,20 +925,24 @@ malloc_large: je @F mov eax, ecx jmp .l6 + @@: mov eax, [eax+20] + .l6: ; while (t != 0) test eax, eax jne .l4 + .l5: ; if (v != 0) test ebp, ebp jz .done + .l7: ; r = chunk_plus_offset((mchunkptr)v, nb); @@ -947,8 +971,10 @@ malloc_large: lea eax, [ebp+8] add esp, 8 pop edi + pop esi pop ebp ret + .large: ; v->head = nb|PINUSE_BIT|CINUSE_BIT; @@ -971,16 +997,18 @@ malloc_large: lea eax, [ebp+8] add esp, 8 pop edi + pop esi pop ebp ret + .done: add esp, 8 pop edi + pop esi pop ebp xor eax, eax ret -align 4 init_malloc: stdcall kernel_alloc, 0x40000 @@ -989,6 +1017,7 @@ init_malloc: mov [mst.topsize], 128*1024 mov dword [eax+4], (128*1024) or 1 mov eax, mst.smallbins + @@: mov [eax+8], eax mov [eax+12], eax @@ -998,6 +1027,3 @@ init_malloc: ret - - - diff --git a/kernel/branches/net/core/memory.inc b/kernel/branches/net/core/memory.inc index 0500134586..611fd87ecc 100644 --- a/kernel/branches/net/core/memory.inc +++ b/kernel/branches/net/core/memory.inc @@ -1,6 +1,6 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; -;; Copyright (C) KolibriOS team 2004-2008. All rights reserved. ;; +;; Copyright (C) KolibriOS team 2004-2009. All rights reserved. ;; ;; Distributed under terms of the GNU General Public License ;; ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -11,177 +11,177 @@ $Revision$ align 4 proc alloc_page - pushfd - cli - push ebx - mov ebx, [page_start] - mov ecx, [page_end] + pushfd + cli + push ebx + mov ebx, [page_start] + mov ecx, [page_end] .l1: - bsf eax,[ebx]; - jnz .found - add ebx,4 - cmp ebx, ecx - jb .l1 - pop ebx - popfd - xor eax,eax - ret + bsf eax,[ebx]; + jnz .found + add ebx,4 + cmp ebx, ecx + jb .l1 + pop ebx + popfd + xor eax,eax + ret .found: - btr [ebx], eax - mov [page_start],ebx - sub ebx, sys_pgmap - lea eax, [eax+ebx*8] - shl eax, 12 - dec [pg_data.pages_free] - pop ebx - popfd - ret + btr [ebx], eax + mov [page_start],ebx + sub ebx, sys_pgmap + lea eax, [eax+ebx*8] + shl eax, 12 + dec [pg_data.pages_free] + pop ebx + popfd + ret endp align 4 proc alloc_pages stdcall, count:dword - pushfd - push ebx - push edi - cli - mov eax, [count] - add eax, 7 - shr eax, 3 - mov [count], eax - cmp eax, [pg_data.pages_free] - ja .fail + pushfd + push ebx + push edi + cli + mov eax, [count] + add eax, 7 + shr eax, 3 + mov [count], eax + cmp eax, [pg_data.pages_free] + ja .fail - mov ecx, [page_start] - mov ebx, [page_end] + mov ecx, [page_start] + mov ebx, [page_end] .find: - mov edx, [count] - mov edi, ecx + mov edx, [count] + mov edi, ecx .match: - cmp byte [ecx], 0xFF - jne .next - dec edx - jz .ok - inc ecx - cmp ecx,ebx - jb .match + cmp byte [ecx], 0xFF + jne .next + dec edx + jz .ok + inc ecx + cmp ecx,ebx + jb .match .fail: - xor eax, eax - pop edi - pop ebx - popfd - ret + xor eax, eax + pop edi + pop ebx + popfd + ret .next: - inc ecx - cmp ecx, ebx - jb .find - pop edi - pop ebx - popfd - xor eax, eax - ret + inc ecx + cmp ecx, ebx + jb .find + pop edi + pop ebx + popfd + xor eax, eax + ret .ok: - sub ecx, edi - inc ecx - push esi - mov esi, edi - xor eax, eax - rep stosb - sub esi, sys_pgmap - shl esi, 3+12 - mov eax, esi - mov ebx, [count] - shl ebx, 3 - sub [pg_data.pages_free], ebx - pop esi - pop edi - pop ebx - popfd - ret + sub ecx, edi + inc ecx + push esi + mov esi, edi + xor eax, eax + rep stosb + sub esi, sys_pgmap + shl esi, 3+12 + mov eax, esi + mov ebx, [count] + shl ebx, 3 + sub [pg_data.pages_free], ebx + pop esi + pop edi + pop ebx + popfd + ret endp align 4 proc map_page stdcall,lin_addr:dword,phis_addr:dword,flags:dword - push ebx - mov eax, [phis_addr] - and eax, not 0xFFF - or eax, [flags] - mov ebx, [lin_addr] - shr ebx, 12 - mov [page_tabs+ebx*4], eax - mov eax, [lin_addr] - invlpg [eax] - pop ebx - ret + push ebx + mov eax, [phis_addr] + and eax, not 0xFFF + or eax, [flags] + mov ebx, [lin_addr] + shr ebx, 12 + mov [page_tabs+ebx*4], eax + mov eax, [lin_addr] + invlpg [eax] + pop ebx + ret endp align 4 map_space: ;not implemented - ret + ret align 4 proc free_page ;arg: eax page address - pushfd - cli - shr eax, 12 ;page index - bts dword [sys_pgmap], eax ;that's all! - cmc - adc [pg_data.pages_free], 0 - shr eax, 3 - and eax, not 3 ;dword offset from page_map - add eax, sys_pgmap - cmp [page_start], eax - ja @f - popfd - ret + pushfd + cli + shr eax, 12 ;page index + bts dword [sys_pgmap], eax ;that's all! + cmc + adc [pg_data.pages_free], 0 + shr eax, 3 + and eax, not 3 ;dword offset from page_map + add eax, sys_pgmap + cmp [page_start], eax + ja @f + popfd + ret @@: - mov [page_start], eax - popfd - ret + mov [page_start], eax + popfd + ret endp proc map_io_mem stdcall, base:dword, size:dword, flags:dword - push ebx - push edi - mov eax, [size] - add eax, 4095 - and eax, -4096 - mov [size], eax - stdcall alloc_kernel_space, eax - test eax, eax - jz .fail - push eax + push ebx + push edi + mov eax, [size] + add eax, 4095 + and eax, -4096 + mov [size], eax + stdcall alloc_kernel_space, eax + test eax, eax + jz .fail + push eax - mov edi, 0x1000 - mov ebx, eax - mov ecx,[size] - mov edx, [base] - shr eax, 12 - shr ecx, 12 - and edx, -4096 - or edx, [flags] + mov edi, 0x1000 + mov ebx, eax + mov ecx,[size] + mov edx, [base] + shr eax, 12 + shr ecx, 12 + and edx, -4096 + or edx, [flags] @@: - mov [page_tabs+eax*4], edx - ; push eax - ; invlpg [ebx] - ; pop eax - inc eax - add ebx, edi - add edx, edi - loop @B + mov [page_tabs+eax*4], edx + ; push eax + invlpg [ebx] + ; pop eax + inc eax + add ebx, edi + add edx, edi + loop @B - pop eax - mov edx, [base] - and edx, 4095 - add eax, edx + pop eax + mov edx, [base] + and edx, 4095 + add eax, edx .fail: - pop edi - pop ebx - ret + pop edi + pop ebx + ret endp ; param @@ -191,31 +191,31 @@ endp align 4 commit_pages: - push edi - test ecx, ecx - jz .fail + push edi + test ecx, ecx + jz .fail - mov edi, ebx - mov ebx, pg_data.pg_mutex - call wait_mutex ;ebx + mov edi, ebx + mov ebx, pg_data.pg_mutex + call wait_mutex ;ebx - mov edx, 0x1000 - mov ebx, edi - shr ebx, 12 + mov edx, 0x1000 + mov ebx, edi + shr ebx, 12 @@: - mov [page_tabs+ebx*4], eax - ; push eax - ; invlpg [edi] - ; pop eax - add edi, edx - add eax, edx - inc ebx - dec ecx - jnz @B - mov [pg_data.pg_mutex],ecx + mov [page_tabs+ebx*4], eax + ; push eax + invlpg [edi] + ; pop eax + add edi, edx + add eax, edx + inc ebx + dec ecx + jnz @B + mov [pg_data.pg_mutex],ecx .fail: - pop edi - ret + pop edi + ret ; param @@ -225,49 +225,49 @@ commit_pages: align 4 release_pages: - pushad - mov ebx, pg_data.pg_mutex - call wait_mutex ;ebx + pushad + mov ebx, pg_data.pg_mutex + call wait_mutex ;ebx - mov esi, eax - mov edi, eax + mov esi, eax + mov edi, eax - shr esi, 10 - add esi, page_tabs + shr esi, 10 + add esi, page_tabs - mov ebp, [pg_data.pages_free] - mov ebx, [page_start] - mov edx, sys_pgmap + mov ebp, [pg_data.pages_free] + mov ebx, [page_start] + mov edx, sys_pgmap @@: - xor eax, eax - xchg eax, [esi] - push eax - invlpg [edi] - pop eax + xor eax, eax + xchg eax, [esi] + push eax + invlpg [edi] + pop eax - test eax, 1 - jz .next + test eax, 1 + jz .next - shr eax, 12 - bts [edx], eax - cmc - adc ebp, 0 - shr eax, 3 - and eax, -4 - add eax, edx - cmp eax, ebx - jae .next + shr eax, 12 + bts [edx], eax + cmc + adc ebp, 0 + shr eax, 3 + and eax, -4 + add eax, edx + cmp eax, ebx + jae .next - mov ebx, eax + mov ebx, eax .next: - add edi, 0x1000 - add esi, 4 - dec ecx - jnz @B - mov [pg_data.pages_free], ebp - and [pg_data.pg_mutex],0 - popad - ret + add edi, 0x1000 + add esi, 4 + dec ecx + jnz @B + mov [pg_data.pages_free], ebp + and [pg_data.pg_mutex],0 + popad + ret ; param ; eax= base @@ -276,229 +276,238 @@ release_pages: align 4 unmap_pages: - push edi + push edi - mov edi, eax - mov edx, eax + mov edi, eax + mov edx, eax - shr edi, 10 - add edi, page_tabs + shr edi, 10 + add edi, page_tabs - xor eax, eax + xor eax, eax @@: - stosd - invlpg [edx] - add edx, 0x1000 - loop @b + stosd + invlpg [edx] + add edx, 0x1000 + loop @b - pop edi - ret + pop edi + ret align 4 proc map_page_table stdcall, lin_addr:dword, phis_addr:dword - push ebx - mov ebx, [lin_addr] - shr ebx, 22 - mov eax, [phis_addr] - and eax, not 0xFFF - or eax, PG_UW ;+PG_NOCACHE - mov dword [master_tab+ebx*4], eax - mov eax, [lin_addr] - shr eax, 10 - add eax, page_tabs - invlpg [eax] - pop ebx - ret + push ebx + mov ebx, [lin_addr] + shr ebx, 22 + mov eax, [phis_addr] + and eax, not 0xFFF + or eax, PG_UW ;+PG_NOCACHE + mov dword [master_tab+ebx*4], eax + mov eax, [lin_addr] + shr eax, 10 + add eax, page_tabs + invlpg [eax] + pop ebx + ret endp align 4 proc init_LFB - locals - pg_count dd ? - endl + locals + pg_count dd ? + endl - cmp dword [LFBAddress], -1 - jne @f - mov [BOOT_VAR+0x901c],byte 2 - stdcall kernel_alloc, 0x280000 - mov [LFBAddress], eax - ret + cmp dword [LFBAddress], -1 + jne @f + mov [BOOT_VAR+0x901c],byte 2 + stdcall alloc_pages, (0x280000 / 4096) + + push eax + call alloc_page + stdcall map_page_table, LFB_BASE, eax + pop eax + or eax, PG_UW + mov ebx, LFB_BASE + mov ecx, 0x280000 / 4096 + call commit_pages + mov [LFBAddress], dword LFB_BASE + ret @@: - test [SCR_MODE],word 0100000000000000b - jnz @f - mov [BOOT_VAR+0x901c],byte 2 - ret + test [SCR_MODE],word 0100000000000000b + jnz @f + mov [BOOT_VAR+0x901c],byte 2 + ret @@: - call init_mtrr + call init_mtrr - mov edx, LFB_BASE - mov esi, [LFBAddress] - mov edi, 0x00800000 - mov dword [exp_lfb+4], edx + mov edx, LFB_BASE + mov esi, [LFBAddress] + mov edi, 0x00C00000 + mov dword [exp_lfb+4], edx - shr edi, 12 - mov [pg_count], edi - shr edi, 10 + shr edi, 12 + mov [pg_count], edi + shr edi, 10 - bt [cpu_caps], CAPS_PSE - jnc .map_page_tables - or esi, PG_LARGE+PG_UW - mov edx, sys_pgdir+(LFB_BASE shr 20) + bt [cpu_caps], CAPS_PSE + jnc .map_page_tables + or esi, PG_LARGE+PG_UW + mov edx, sys_pgdir+(LFB_BASE shr 20) @@: - mov [edx], esi - add edx, 4 - add esi, 0x00400000 - dec edi - jnz @B + mov [edx], esi + add edx, 4 + add esi, 0x00400000 + dec edi + jnz @B - bt [cpu_caps], CAPS_PGE - jnc @F - or dword [sys_pgdir+(LFB_BASE shr 20)], PG_GLOBAL + bt [cpu_caps], CAPS_PGE + jnc @F + or dword [sys_pgdir+(LFB_BASE shr 20)], PG_GLOBAL @@: - mov dword [LFBAddress], LFB_BASE - mov eax, cr3 ;flush TLB - mov cr3, eax - ret + mov dword [LFBAddress], LFB_BASE + mov eax, cr3 ;flush TLB + mov cr3, eax + ret .map_page_tables: @@: - call alloc_page - stdcall map_page_table, edx, eax - add edx, 0x00400000 - dec edi - jnz @B + call alloc_page + stdcall map_page_table, edx, eax + add edx, 0x00400000 + dec edi + jnz @B - mov eax, [LFBAddress] - mov edi, page_tabs + (LFB_BASE shr 10) - or eax, PG_UW - mov ecx, [pg_count] - cld + mov eax, [LFBAddress] + mov edi, page_tabs + (LFB_BASE shr 10) + or eax, PG_UW + mov ecx, [pg_count] + cld @@: - stosd - add eax, 0x1000 - dec ecx - jnz @B + stosd + add eax, 0x1000 + dec ecx + jnz @B - mov dword [LFBAddress], LFB_BASE - mov eax, cr3 ;flush TLB - mov cr3, eax + mov dword [LFBAddress], LFB_BASE + mov eax, cr3 ;flush TLB + mov cr3, eax - ret + ret endp align 4 proc new_mem_resize stdcall, new_size:dword - mov ebx, pg_data.pg_mutex - call wait_mutex ;ebx + mov ebx, pg_data.pg_mutex + call wait_mutex ;ebx - mov edi, [new_size] - add edi,4095 - and edi,not 4095 - mov [new_size], edi + mov edi, [new_size] + add edi,4095 + and edi,not 4095 + mov [new_size], edi - mov edx,[current_slot] - cmp [edx+APPDATA.heap_base],0 - jne .exit + mov edx,[current_slot] + cmp [edx+APPDATA.heap_base],0 + jne .exit - mov esi, [edx+APPDATA.mem_size] - add esi, 4095 - and esi, not 4095 + mov esi, [edx+APPDATA.mem_size] + add esi, 4095 + and esi, not 4095 - cmp edi, esi - jae .expand + cmp edi, esi + jae .expand - shr edi, 12 - shr esi, 12 + shr edi, 12 + shr esi, 12 @@: - mov eax, [app_page_tabs+edi*4] - test eax, 1 - jz .next - mov dword [app_page_tabs+edi*4], 2 - mov ebx, edi - shl ebx, 12 - push eax - invlpg [ebx] - pop eax - call free_page + mov eax, [app_page_tabs+edi*4] + test eax, 1 + jz .next + mov dword [app_page_tabs+edi*4], 2 + mov ebx, edi + shl ebx, 12 + push eax + invlpg [ebx] + pop eax + call free_page -.next: add edi, 1 - cmp edi, esi - jb @B +.next: add edi, 1 + cmp edi, esi + jb @B .update_size: - mov ebx, [new_size] - call update_mem_size + mov ebx, [new_size] + call update_mem_size - xor eax, eax - dec [pg_data.pg_mutex] - ret + xor eax, eax + dec [pg_data.pg_mutex] + ret .expand: - push esi - push edi + push esi + push edi - add edi, 0x3FFFFF - and edi, not(0x3FFFFF) - add esi, 0x3FFFFF - and esi, not(0x3FFFFF) + add edi, 0x3FFFFF + and edi, not(0x3FFFFF) + add esi, 0x3FFFFF + and esi, not(0x3FFFFF) - cmp esi, edi - jae .grow + cmp esi, edi + jae .grow - xchg esi, edi + xchg esi, edi @@: - call alloc_page - test eax, eax - jz .exit_pop + call alloc_page + test eax, eax + jz .exit_pop - stdcall map_page_table, edi, eax + stdcall map_page_table, edi, eax - push edi - shr edi, 10 - add edi, page_tabs - mov ecx, 1024 - xor eax, eax - cld - rep stosd - pop edi + push edi + shr edi, 10 + add edi, page_tabs + mov ecx, 1024 + xor eax, eax + cld + rep stosd + pop edi - add edi, 0x00400000 - cmp edi, esi - jb @B + add edi, 0x00400000 + cmp edi, esi + jb @B .grow: - pop edi - pop esi + pop edi + pop esi @@: - call alloc_page - test eax, eax - jz .exit - stdcall map_page,esi,eax,dword PG_UW + call alloc_page + test eax, eax + jz .exit + stdcall map_page,esi,eax,dword PG_UW - push edi - mov edi, esi - xor eax, eax - mov ecx, 1024 - cld - rep stosd - pop edi + push edi + mov edi, esi + xor eax, eax + mov ecx, 1024 + cld + rep stosd + pop edi - add esi, 0x1000 - cmp esi, edi - jb @B + add esi, 0x1000 + cmp esi, edi + jb @B - jmp .update_size + jmp .update_size .exit_pop: - pop edi - pop esi + pop edi + pop esi .exit: - xor eax, eax - inc eax - dec [pg_data.pg_mutex] - ret + xor eax, eax + inc eax + dec [pg_data.pg_mutex] + ret endp update_mem_size: @@ -506,31 +515,31 @@ update_mem_size: ; ebx = new memory size ; destroys eax,ecx,edx - mov [APPDATA.mem_size+edx],ebx + mov [APPDATA.mem_size+edx],ebx ;search threads and update ;application memory size infomation - mov ecx,[APPDATA.dir_table+edx] - mov eax,2 + mov ecx,[APPDATA.dir_table+edx] + mov eax,2 .search_threads: ;eax = current slot ;ebx = new memory size ;ecx = page directory - cmp eax,[TASK_COUNT] - jg .search_threads_end - mov edx,eax - shl edx,5 - cmp word [CURRENT_TASK+edx+TASKDATA.state],9 ;if slot empty? - jz .search_threads_next - shl edx,3 - cmp [SLOT_BASE+edx+APPDATA.dir_table],ecx ;if it is our thread? - jnz .search_threads_next - mov [SLOT_BASE+edx+APPDATA.mem_size],ebx ;update memory size + cmp eax,[TASK_COUNT] + jg .search_threads_end + mov edx,eax + shl edx,5 + cmp word [CURRENT_TASK+edx+TASKDATA.state],9 ;if slot empty? + jz .search_threads_next + shl edx,3 + cmp [SLOT_BASE+edx+APPDATA.dir_table],ecx ;if it is our thread? + jnz .search_threads_next + mov [SLOT_BASE+edx+APPDATA.mem_size],ebx ;update memory size .search_threads_next: - inc eax - jmp .search_threads + inc eax + jmp .search_threads .search_threads_end: - ret + ret ; param ; eax= linear address @@ -540,162 +549,193 @@ update_mem_size: align 4 get_pg_addr: - shr eax, 12 - mov eax, [page_tabs+eax*4] - and eax, 0xFFFFF000 - ret + shr eax, 12 + mov eax, [page_tabs+eax*4] + and eax, 0xFFFFF000 + ret align 4 ; Now it is called from core/sys32::exc_c (see stack frame there) proc page_fault_handler - .err_addr equ ebp-4 + .err_addr equ ebp-4 - push ebx ;save exception number (#PF) - mov ebp, esp - mov ebx, cr2 - push ebx ;that is locals: .err_addr = cr2 - inc [pg_data.pages_faults] + push ebx ;save exception number (#PF) + mov ebp, esp + mov ebx, cr2 + push ebx ;that is locals: .err_addr = cr2 + inc [pg_data.pages_faults] -; push eax -; push edx -; mov edx, 0x400 ;bochs -; mov al,0xff ;bochs -; out dx, al ;bochs -; pop edx -; pop eax + mov eax, [pf_err_code] - mov eax, [pf_err_code] + cmp ebx, OS_BASE ;ebx == .err_addr + jb .user_space ;страница в памяти приложения ; - cmp ebx, OS_BASE ;ebx == .err_addr - jb .user_space ;страница в памяти приложения ; + cmp ebx, page_tabs + jb .kernel_space ;страница в памяти ядра - cmp ebx, page_tabs - jb .kernel_space ;страница в памяти ядра - - cmp ebx, kernel_tabs - jb .alloc;.app_tabs ;таблицы страниц приложения ; - ;просто создадим одну + cmp ebx, kernel_tabs + jb .alloc;.app_tabs ;таблицы страниц приложения ; + ;просто создадим одну if 0 ;пока это просто лишнее - cmp ebx, LFB_BASE - jb .core_tabs ;таблицы страниц ядра - ;Ошибка + cmp ebx, LFB_BASE + jb .core_tabs ;таблицы страниц ядра + ;Ошибка .lfb: - ;область LFB - ;Ошибка - jmp .fail + ;область LFB + ;Ошибка + jmp .fail end if .core_tabs: -.fail: ;simply return to caller - mov esp, ebp - pop ebx ;restore exception number (#PF) - ret +.fail: ;simply return to caller + mov esp, ebp + pop ebx ;restore exception number (#PF) + ret + +; xchg bx, bx +; add esp,12 ;clear in stack: locals(.err_addr) + #PF + ret_to_caller +; restore_ring3_context +; iretd .user_space: - test eax, PG_MAP - jnz .err_access ;Страница присутствует - ;Ошибка доступа ? + test eax, PG_MAP + jnz .err_access ;Страница присутствует + ;Ошибка доступа ? - shr ebx, 12 - mov ecx, ebx - shr ecx, 10 - mov edx, [master_tab+ecx*4] - test edx, PG_MAP - jz .fail ;таблица страниц не создана - ;неверный адрес в программе + shr ebx, 12 + mov ecx, ebx + shr ecx, 10 + mov edx, [master_tab+ecx*4] + test edx, PG_MAP + jz .fail ;таблица страниц не создана + ;неверный адрес в программе - mov eax, [page_tabs+ebx*4] - test eax, 2 - jz .fail ;адрес не зарезервирован для ; - ;использования. Ошибка + mov eax, [page_tabs+ebx*4] + test eax, 2 + jz .fail ;адрес не зарезервирован для ; + ;использования. Ошибка .alloc: - call alloc_page - test eax, eax - jz .fail + call alloc_page + test eax, eax + jz .fail - stdcall map_page,[.err_addr],eax,dword PG_UW + stdcall map_page,[.err_addr],eax,PG_UW - mov edi, [.err_addr] - and edi, 0xFFFFF000 - mov ecx, 1024 - xor eax, eax + mov edi, [.err_addr] + and edi, 0xFFFFF000 + mov ecx, 1024 + xor eax, eax ;cld ;caller is duty for this - rep stosd -.exit: ;iret with repeat fault instruction - add esp,12 ;clear in stack: locals(.err_addr) + #PF + ret_to_caller - restore_ring3_context - iretd + rep stosd +.exit: ;iret with repeat fault instruction + add esp,12 ;clear in stack: locals(.err_addr) + #PF + ret_to_caller + restore_ring3_context + iretd -.err_access = .fail -;никогда не происходит - ;jmp .fail +.err_access: +; access denied? this may be a result of copy-on-write protection for DLL +; check list of HDLLs + and ebx, not 0xFFF + mov eax, [CURRENT_TASK] + shl eax, 8 + mov eax, [SLOT_BASE+eax+APPDATA.dlls_list_ptr] + test eax, eax + jz .fail + mov esi, [eax+HDLL.fd] +.scan_hdll: + cmp esi, eax + jz .fail + mov edx, ebx + sub edx, [esi+HDLL.base] + cmp edx, [esi+HDLL.size] + jb .fault_in_hdll +.scan_hdll.next: + mov esi, [esi+HDLL.fd] + jmp .scan_hdll +.fault_in_hdll: +; allocate new page, map it as rw and copy data + call alloc_page + test eax, eax + jz .fail + stdcall map_page,ebx,eax,PG_UW + mov edi, ebx + mov ecx, 1024 + sub ebx, [esi+HDLL.base] + mov esi, [esi+HDLL.parent] + mov esi, [esi+DLLDESCR.data] + add esi, ebx + rep movsd + jmp .exit .kernel_space: - test eax, PG_MAP - jz .fail ;страница не присутствует + test eax, PG_MAP + jz .fail ;страница не присутствует - test eax,12 ;U/S (+below) - jnz .fail ;приложение обратилось к памяти - ;ядра + test eax,12 ;U/S (+below) + jnz .fail ;приложение обратилось к памяти + ;ядра ;test eax, 8 ;jnz .fail ;установлен зарезервированный бит - ;в таблицах страниц. добавлено в P4/Xeon + ;в таблицах страниц. добавлено в P4/Xeon ;попытка записи в защищённую страницу ядра - cmp ebx, tss._io_map_0 - jb .fail + cmp ebx, tss._io_map_0 + jb .fail - cmp ebx, tss._io_map_0+8192 - jae .fail + cmp ebx, tss._io_map_0+8192 + jae .fail ; io permission map ; copy-on-write protection - call alloc_page - test eax, eax - jz .fail + call alloc_page + test eax, eax + jz .fail - push eax - stdcall map_page,[.err_addr],eax,dword PG_SW - pop eax - mov edi, [.err_addr] - and edi, -4096 - lea esi, [edi+(not tss._io_map_0)+1]; -tss._io_map_0 + push eax + stdcall map_page,[.err_addr],eax,dword PG_SW + pop eax + mov edi, [.err_addr] + and edi, -4096 + lea esi, [edi+(not tss._io_map_0)+1]; -tss._io_map_0 - mov ebx, esi - shr ebx, 12 - mov edx, [current_slot] - or eax, PG_SW - mov [edx+APPDATA.io_map+ebx*4], eax + mov ebx, esi + shr ebx, 12 + mov edx, [current_slot] + or eax, PG_SW + mov [edx+APPDATA.io_map+ebx*4], eax - add esi, [default_io_map] - mov ecx, 4096/4 + add esi, [default_io_map] + mov ecx, 4096/4 ;cld ;caller is duty for this - rep movsd - jmp .exit + rep movsd + jmp .exit endp -align 4 -proc map_mem stdcall, lin_addr:dword,pdir:dword,\ - ofs:dword,buf_size:dword - mov eax, [buf_size] - test eax, eax - jz .exit +; returns number of mapped bytes +proc map_mem stdcall, lin_addr:dword,slot:dword,\ + ofs:dword,buf_size:dword,req_access:dword + push 0 ; initialize number of mapped bytes - mov eax, [pdir] - and eax, 0xFFFFF000 + cmp [buf_size], 0 + jz .exit - stdcall map_page,[ipc_pdir],eax,PG_UW - mov ebx, [ofs] - shr ebx, 22 - mov esi, [ipc_pdir] - mov edi, [ipc_ptab] - mov eax, [esi+ebx*4] - and eax, 0xFFFFF000 - jz .exit - stdcall map_page,edi,eax,PG_UW + mov eax, [slot] + shl eax, 8 + mov eax, [SLOT_BASE+eax+APPDATA.dir_table] + and eax, 0xFFFFF000 + + stdcall map_page,[ipc_pdir],eax,PG_UW + mov ebx, [ofs] + shr ebx, 22 + mov esi, [ipc_pdir] + mov edi, [ipc_ptab] + mov eax, [esi+ebx*4] + and eax, 0xFFFFF000 + jz .exit + stdcall map_page,edi,eax,PG_UW ; inc ebx ; add edi, 0x1000 ; mov eax, [esi+ebx*4] @@ -704,89 +744,173 @@ proc map_mem stdcall, lin_addr:dword,pdir:dword,\ ; and eax, 0xFFFFF000 ; stdcall map_page, edi, eax -@@: mov edi, [lin_addr] - and edi, 0xFFFFF000 - mov ecx, [buf_size] - add ecx, 4095 - shr ecx, 12 - inc ecx +@@: mov edi, [lin_addr] + and edi, 0xFFFFF000 + mov ecx, [buf_size] + add ecx, 4095 + shr ecx, 12 + inc ecx - mov edx, [ofs] - shr edx, 12 - and edx, 0x3FF - mov esi, [ipc_ptab] + mov edx, [ofs] + shr edx, 12 + and edx, 0x3FF + mov esi, [ipc_ptab] -.map: mov eax, [esi+edx*4] - and eax, 0xFFFFF000 - jz .exit - stdcall map_page,edi,eax,PG_UW - dec ecx - jz .exit - add edi, 0x1000 - inc edx - cmp edx, 0x400 - jnz .map - inc ebx - mov eax, [ipc_pdir] - mov eax, [eax+ebx*4] - and eax, 0xFFFFF000 - jz .exit - stdcall map_page,esi,eax,PG_UW - xor edx, edx - jmp .map +.map: + stdcall safe_map_page,[slot],[req_access],[ofs] + jnc .exit + add dword [ebp-4], 4096 + add [ofs], 4096 + dec ecx + jz .exit + add edi, 0x1000 + inc edx + cmp edx, 0x400 + jnz .map + inc ebx + mov eax, [ipc_pdir] + mov eax, [eax+ebx*4] + and eax, 0xFFFFF000 + jz .exit + stdcall map_page,esi,eax,PG_UW + xor edx, edx + jmp .map .exit: - ret + pop eax + ret endp -align 4 -proc map_memEx stdcall, lin_addr:dword,pdir:dword,\ - ofs:dword,buf_size:dword - mov eax, [buf_size] - test eax, eax - jz .exit +proc map_memEx stdcall, lin_addr:dword,slot:dword,\ + ofs:dword,buf_size:dword,req_access:dword + push 0 ; initialize number of mapped bytes - mov eax, [pdir] - and eax, 0xFFFFF000 + cmp [buf_size], 0 + jz .exit - stdcall map_page,[proc_mem_pdir],eax,dword PG_UW - mov ebx, [ofs] - shr ebx, 22 - mov esi, [proc_mem_pdir] - mov edi, [proc_mem_tab] - mov eax, [esi+ebx*4] - and eax, 0xFFFFF000 - test eax, eax - jz .exit - stdcall map_page,edi,eax,dword PG_UW + mov eax, [slot] + shl eax, 8 + mov eax, [SLOT_BASE+eax+APPDATA.dir_table] + and eax, 0xFFFFF000 -@@: mov edi, [lin_addr] - and edi, 0xFFFFF000 - mov ecx, [buf_size] - add ecx, 4095 - shr ecx, 12 - inc ecx + stdcall map_page,[proc_mem_pdir],eax,PG_UW + mov ebx, [ofs] + shr ebx, 22 + mov esi, [proc_mem_pdir] + mov edi, [proc_mem_tab] + mov eax, [esi+ebx*4] + and eax, 0xFFFFF000 + test eax, eax + jz .exit + stdcall map_page,edi,eax,PG_UW - mov edx, [ofs] - shr edx, 12 - and edx, 0x3FF - mov esi, [proc_mem_tab] +@@: mov edi, [lin_addr] + and edi, 0xFFFFF000 + mov ecx, [buf_size] + add ecx, 4095 + shr ecx, 12 + inc ecx -.map: mov eax, [esi+edx*4] -; and eax, 0xFFFFF000 -; test eax, eax -; jz .exit - stdcall map_page,edi,eax,dword PG_UW - add edi, 0x1000 - inc edx - dec ecx - jnz .map + mov edx, [ofs] + shr edx, 12 + and edx, 0x3FF + mov esi, [proc_mem_tab] + +.map: + stdcall safe_map_page,[slot],[req_access],[ofs] + jnc .exit + add dword [ebp-4], 0x1000 + add edi, 0x1000 + add [ofs], 0x1000 + inc edx + dec ecx + jnz .map .exit: - ret + pop eax + ret endp - - +; in: esi+edx*4 = pointer to page table entry +; in: [slot], [req_access], [ofs] on the stack +; in: edi = linear address to map +; out: CF cleared <=> failed +; destroys: only eax +proc safe_map_page stdcall, slot:dword, req_access:dword, ofs:dword + mov eax, [esi+edx*4] + test al, PG_MAP + jz .not_present + test al, PG_WRITE + jz .resolve_readonly +; normal case: writable page, just map with requested access +.map: + stdcall map_page, edi, eax, [req_access] + stc +.fail: + ret +.not_present: +; check for alloc-on-demand page + test al, 2 + jz .fail +; allocate new page, save it to source page table + push ecx + call alloc_page + pop ecx + test eax, eax + jz .fail + or al, PG_UW + mov [esi+edx*4], eax + jmp .map +.resolve_readonly: +; readonly page, probably copy-on-write +; check: readonly request of readonly page is ok + test [req_access], PG_WRITE + jz .map +; find control structure for this page + pushf + cli + cld + push ebx ecx + mov eax, [slot] + shl eax, 8 + mov eax, [SLOT_BASE+eax+APPDATA.dlls_list_ptr] + test eax, eax + jz .no_hdll + mov ecx, [eax+HDLL.fd] +.scan_hdll: + cmp ecx, eax + jz .no_hdll + mov ebx, [ofs] + and ebx, not 0xFFF + sub ebx, [ecx+HDLL.base] + cmp ebx, [ecx+HDLL.size] + jb .hdll_found + mov ecx, [ecx+HDLL.fd] + jmp .scan_hdll +.no_hdll: + pop ecx ebx + popf + clc + ret +.hdll_found: +; allocate page, save it in page table, map it, copy contents from base + mov eax, [ecx+HDLL.parent] + add ebx, [eax+DLLDESCR.data] + call alloc_page + test eax, eax + jz .no_hdll + or al, PG_UW + mov [esi+edx*4], eax + stdcall map_page, edi, eax, [req_access] + push esi edi + mov esi, ebx + mov ecx, 4096/4 + rep movsd + pop edi esi + pop ecx ebx + popf + stc + ret +endp sys_IPC: ;input: @@ -798,511 +922,545 @@ sys_IPC: ; ecx=address of message ; edx=size of message - cmp eax,1 - jne @f - call set_ipc_buff - mov [esp+36], eax - ret + cmp eax,1 + jne @f + call set_ipc_buff + mov [esp+36], eax + ret @@: - cmp eax, 2 - jne @f - stdcall sys_ipc_send, ebx, ecx, edx - mov [esp+36], eax - ret + cmp eax, 2 + jne @f + stdcall sys_ipc_send, ebx, ecx, edx + mov [esp+36], eax + ret @@: - xor eax, eax - not eax - mov [esp+36], eax - ret + xor eax, eax + not eax + mov [esp+36], eax + ret align 4 proc set_ipc_buff - mov eax,[current_slot] - pushf - cli - mov [eax+APPDATA.ipc_start],ebx ;set fields in extended information area - mov [eax+APPDATA.ipc_size],ecx + mov eax,[current_slot] + pushf + cli + mov [eax+APPDATA.ipc_start],ebx ;set fields in extended information area + mov [eax+APPDATA.ipc_size],ecx - add ecx, ebx - add ecx, 4095 - and ecx, not 4095 + add ecx, ebx + add ecx, 4095 + and ecx, not 4095 .touch: mov eax, [ebx] - add ebx, 0x1000 - cmp ebx, ecx - jb .touch + add ebx, 0x1000 + cmp ebx, ecx + jb .touch - popf - xor eax, eax - ret + popf + xor eax, eax + ret endp proc sys_ipc_send stdcall, PID:dword, msg_addr:dword, msg_size:dword - locals - dst_slot dd ? - dst_offset dd ? - buf_size dd ? - used_buf dd ? - endl + locals + dst_slot dd ? + dst_offset dd ? + buf_size dd ? + used_buf dd ? + endl - pushf - cli + pushf + cli - mov eax, [PID] - call pid_to_slot - test eax,eax - jz .no_pid + mov eax, [PID] + call pid_to_slot + test eax,eax + jz .no_pid - mov [dst_slot], eax - shl eax,8 - mov edi,[eax+SLOT_BASE+0xa0] ;is ipc area defined? - test edi,edi - jz .no_ipc_area + mov [dst_slot], eax + shl eax,8 + mov edi,[eax+SLOT_BASE+0xa0] ;is ipc area defined? + test edi,edi + jz .no_ipc_area - mov ebx, edi - and ebx, 0xFFF - mov [dst_offset], ebx + mov ebx, edi + and ebx, 0xFFF + mov [dst_offset], ebx - mov esi, [eax+SLOT_BASE+0xa4] - mov [buf_size], esi + mov esi, [eax+SLOT_BASE+0xa4] + mov [buf_size], esi - mov ecx, [ipc_tmp] - cmp esi, 0x40000-0x1000 ; size of [ipc_tmp] minus one page - jbe @f - push eax esi edi - add esi,0x1000 - stdcall alloc_kernel_space,esi - mov ecx, eax - pop edi esi eax + mov ecx, [ipc_tmp] + cmp esi, 0x40000-0x1000 ; size of [ipc_tmp] minus one page + jbe @f + push esi edi + add esi,0x1000 + stdcall alloc_kernel_space,esi + mov ecx, eax + pop edi esi @@: - mov [used_buf], ecx - stdcall map_mem, ecx, [SLOT_BASE+eax+0xB8],\ - edi, esi + mov [used_buf], ecx + stdcall map_mem, ecx, [dst_slot],\ + edi, esi, PG_SW - mov edi, [dst_offset] - add edi, [used_buf] - cmp dword [edi], 0 - jnz .ipc_blocked ;if dword [buffer]<>0 - ipc blocked now + mov edi, [dst_offset] + add edi, [used_buf] + cmp dword [edi], 0 + jnz .ipc_blocked ;if dword [buffer]<>0 - ipc blocked now - mov edx, dword [edi+4] - lea ebx, [edx+8] - add ebx, [msg_size] - cmp ebx, [buf_size] - ja .buffer_overflow ;esi<0 - not enough memory in buffer + mov edx, dword [edi+4] + lea ebx, [edx+8] + add ebx, [msg_size] + cmp ebx, [buf_size] + ja .buffer_overflow ;esi<0 - not enough memory in buffer - mov dword [edi+4], ebx - mov eax,[TASK_BASE] - mov eax, [eax+0x04] ;eax - our PID - add edi, edx - mov [edi], eax - mov ecx, [msg_size] + mov dword [edi+4], ebx + mov eax,[TASK_BASE] + mov eax, [eax+0x04] ;eax - our PID + add edi, edx + mov [edi], eax + mov ecx, [msg_size] - mov [edi+4], ecx - add edi, 8 - mov esi, [msg_addr] + mov [edi+4], ecx + add edi, 8 + mov esi, [msg_addr] ; add esi, new_app_base - cld - rep movsb + cld + rep movsb - mov ebx, [ipc_tmp] - mov edx, ebx - shr ebx, 12 - xor eax, eax - mov [page_tabs+ebx*4], eax - invlpg [edx] + mov ebx, [ipc_tmp] + mov edx, ebx + shr ebx, 12 + xor eax, eax + mov [page_tabs+ebx*4], eax + invlpg [edx] - mov ebx, [ipc_pdir] - mov edx, ebx - shr ebx, 12 - xor eax, eax - mov [page_tabs+ebx*4], eax - invlpg [edx] + mov ebx, [ipc_pdir] + mov edx, ebx + shr ebx, 12 + xor eax, eax + mov [page_tabs+ebx*4], eax + invlpg [edx] - mov ebx, [ipc_ptab] - mov edx, ebx - shr ebx, 12 - xor eax, eax - mov [page_tabs+ebx*4], eax - invlpg [edx] + mov ebx, [ipc_ptab] + mov edx, ebx + shr ebx, 12 + xor eax, eax + mov [page_tabs+ebx*4], eax + invlpg [edx] - mov eax, [dst_slot] - shl eax, 8 - or [eax+SLOT_BASE+0xA8],dword 0x40 - cmp dword [check_idle_semaphore],20 - jge .ipc_no_cis + mov eax, [dst_slot] + shl eax, 8 + or [eax+SLOT_BASE+0xA8],dword 0x40 + cmp dword [check_idle_semaphore],20 + jge .ipc_no_cis - mov dword [check_idle_semaphore],5 + mov dword [check_idle_semaphore],5 .ipc_no_cis: - push 0 - jmp .ret + push 0 + jmp .ret .no_pid: - popf - mov eax, 4 - ret + popf + mov eax, 4 + ret .no_ipc_area: - popf - xor eax, eax - inc eax - ret + popf + xor eax, eax + inc eax + ret .ipc_blocked: - push 2 - jmp .ret + push 2 + jmp .ret .buffer_overflow: - push 3 + push 3 .ret: - mov eax, [used_buf] - cmp eax, [ipc_tmp] - jz @f - stdcall free_kernel_space,eax + mov eax, [used_buf] + cmp eax, [ipc_tmp] + jz @f + stdcall free_kernel_space,eax @@: - pop eax - popf - ret + pop eax + popf + ret endp align 4 sysfn_meminfo: - ; add ecx, new_app_base - cmp ecx, OS_BASE - jae .fail + ; add ecx, new_app_base + cmp ecx, OS_BASE + jae .fail - mov eax, [pg_data.pages_count] - mov [ecx], eax - shl eax, 12 - mov [esp+32], eax - mov eax, [pg_data.pages_free] - mov [ecx+4], eax - mov eax, [pg_data.pages_faults] - mov [ecx+8], eax - mov eax, [heap_size] - mov [ecx+12], eax - mov eax, [heap_free] - mov [ecx+16], eax - mov eax, [heap_blocks] - mov [ecx+20], eax - mov eax, [free_blocks] - mov [ecx+24], eax - ret + mov eax, [pg_data.pages_count] + mov [ecx], eax + shl eax, 12 + mov [esp+32], eax + mov eax, [pg_data.pages_free] + mov [ecx+4], eax + mov eax, [pg_data.pages_faults] + mov [ecx+8], eax + mov eax, [heap_size] + mov [ecx+12], eax + mov eax, [heap_free] + mov [ecx+16], eax + mov eax, [heap_blocks] + mov [ecx+20], eax + mov eax, [free_blocks] + mov [ecx+24], eax + ret .fail: - mov dword [esp+32], -1 - ret - + or dword [esp+32], -1 + ret +iglobal align 4 f68call: - dd f68.11 - dd f68.12 - dd f68.13 - dd f68.14 - dd f68.fail ;moved to f68.24 - dd f68.16 - dd f68.17 - dd f68.fail ;moved to f68.25 - dd f68.19 - dd f68.20 - dd f68.21 - dd f68.22 - dd f68.23 - dd f68.24 - dd f68.25 - + dd f68.11 ; init_heap + dd f68.12 ; user_alloc + dd f68.13 ; user_free + dd f68.14 ; get_event_ex + dd f68.fail ;moved to f68.24 + dd f68.16 ; get_service + dd f68.17 ; call_service + dd f68.fail ;moved to f68.25 + dd f68.19 ; load_dll + dd f68.20 ; user_realloc + dd f68.21 ; load_driver + dd f68.22 ; shmem_open + dd f68.23 ; shmem_close + dd f68.24 + dd f68.25 +endg align 4 f68: - cmp eax,4 - jle sys_sheduler + cmp ebx,4 + jbe sys_sheduler - cmp eax, 11 - jb .fail + cmp ebx, 11 + jb .fail - cmp eax, 25 - ja .fail + cmp ebx, 25 + ja .fail - jmp dword [f68call+eax*4-11*4] + jmp dword [f68call+ebx*4-11*4] .11: - call init_heap - mov [esp+36], eax - ret + call init_heap + mov [esp+32], eax + ret .12: - stdcall user_alloc, ebx - mov [esp+36], eax - ret + stdcall user_alloc, ecx + mov [esp+32], eax + ret .13: - stdcall user_free, ebx - mov [esp+36], eax - ret + stdcall user_free, ecx + mov [esp+32], eax + ret .14: - cmp ebx, OS_BASE - jae .fail - mov edi,ebx - call get_event_ex - mov [esp+36], eax - ret -.24: - mov eax, [current_slot] - xchg ebx, [eax+APPDATA.exc_handler] - xchg ecx, [eax+APPDATA.except_mask] - mov [esp+36], ebx ; reg_eax+8 - mov [esp+24], ecx ; reg_ebx+8 - ret + cmp ecx, OS_BASE + jae .fail + mov edi,ecx + call get_event_ex + mov [esp+32], eax + ret .16: - test ebx, ebx - jz .fail - cmp ebx, OS_BASE - jae .fail - stdcall get_service, ebx - mov [esp+36], eax - ret + test ecx, ecx + jz .fail + cmp ecx, OS_BASE + jae .fail + stdcall get_service, ecx + mov [esp+32], eax + ret .17: - call srv_handlerEx ;ebx - mov [esp+36], eax - ret -.25: - cmp ebx,32 - jae .fail - mov eax, [current_slot] - btr [eax+APPDATA.except_mask],ebx - setc byte[esp+36] - jecxz @f - bts [eax+APPDATA.except_mask],ebx - @@: ret + call srv_handlerEx ;ecx + mov [esp+32], eax + ret .19: - cmp ebx, OS_BASE - jae .fail - stdcall load_library, ebx - mov [esp+36], eax - ret + cmp ecx, OS_BASE + jae .fail + stdcall load_library, ecx + mov [esp+32], eax + ret .20: - mov eax, ecx - call user_realloc - mov [esp+36], eax - ret + mov eax, edx + mov ebx, ecx + call user_realloc ;in: eax = pointer, ebx = new size + mov [esp+32], eax + ret .21: - cmp ebx, OS_BASE - jae .fail + cmp ecx, OS_BASE + jae .fail - stdcall load_PE, ebx + cmp ebx, OS_BASE + jae .fail - test eax, eax - jz @F + mov edi, edx + stdcall load_PE, ecx + mov esi, eax + test eax, eax + jz @F - mov esi, eax - stdcall eax, DRV_ENTRY + push edi + push DRV_ENTRY + call eax + add esp, 8 + test eax, eax + jz @F - test eax, eax - jz @F - - mov [eax+SRV.entry], esi + mov [eax+SRV.entry], esi @@: - mov [esp+36], eax - ret + mov [esp+32], eax + ret .22: - cmp ebx, OS_BASE - jae .fail + cmp ecx, OS_BASE + jae .fail - stdcall shmem_open, ebx, ecx, edx - mov [esp+28], edx - mov [esp+36], eax - ret + stdcall shmem_open, ecx, edx, esi + mov [esp+24], edx + mov [esp+32], eax + ret .23: - cmp ebx, OS_BASE - jae .fail + cmp ecx, OS_BASE + jae .fail - stdcall shmem_close, ebx - mov [esp+36], eax - ret + stdcall shmem_close, ecx + mov [esp+32], eax + ret +.24: + mov eax, [current_slot] + xchg ecx, [eax+APPDATA.exc_handler] + xchg edx, [eax+APPDATA.except_mask] + mov [esp+32], ecx ; reg_eax+8 + mov [esp+20], edx ; reg_ebx+8 + ret +.25: + cmp ecx,32 + jae .fail + mov eax, [current_slot] + btr [eax+APPDATA.except_mask],ecx + setc byte[esp+32] + jecxz @f + bts [eax+APPDATA.except_mask],ecx +@@: + ret .fail: - xor eax, eax - mov [esp+36], eax - ret + xor eax, eax + mov [esp+32], eax + ret align 4 proc load_pe_driver stdcall, file:dword - stdcall load_PE, [file] - test eax, eax - jz .fail + stdcall load_PE, [file] + test eax, eax + jz .fail - mov esi, eax - stdcall eax, DRV_ENTRY - test eax, eax - jz .fail + mov esi, eax + stdcall eax, DRV_ENTRY + test eax, eax + jz .fail - mov [eax+SRV.entry], esi - ret + mov [eax+SRV.entry], esi + ret .fail: - xor eax, eax - ret + xor eax, eax + ret endp align 4 proc init_mtrr - cmp [BOOT_VAR+0x901c],byte 2 - je .exit + cmp [BOOT_VAR+0x901c],byte 2 + je .exit - bt [cpu_caps], CAPS_MTRR - jnc .exit + bt [cpu_caps], CAPS_MTRR + jnc .exit - mov eax, cr0 - or eax, 0x60000000 ;disable caching - mov cr0, eax - wbinvd ;invalidate cache + mov eax, cr0 + or eax, 0x60000000 ;disable caching + mov cr0, eax + wbinvd ;invalidate cache - mov ecx, 0x2FF - rdmsr ; - push eax + mov ecx, 0x2FF + rdmsr ; +; has BIOS already initialized MTRRs? + test ah, 8 + jnz .skip_init +; rarely needed, so mainly placeholder +; main memory - cached + push eax - xor edx, edx - xor eax, eax - mov ecx, 0x2FF - wrmsr ;disable all MTRR - - mov eax, [MEM_AMOUNT] + mov eax, [MEM_AMOUNT] ; round eax up to next power of 2 - dec eax - bsr ecx, eax - mov eax, 2 - shl eax, cl - stdcall set_mtrr, edx,edx,eax,MEM_WB - stdcall set_mtrr, 1,[LFBAddress],[LFBSize],MEM_WC - xor edx, edx - xor eax, eax - mov ecx, 0x204 - mov ebx, 6 + dec eax + bsr ecx, eax + mov ebx, 2 + shl ebx, cl + dec ebx +; base of memory range = 0, type of memory range = MEM_WB + xor edx, edx + mov eax, MEM_WB + mov ecx, 0x200 + wrmsr +; mask of memory range = 0xFFFFFFFFF - (size - 1), ebx = size - 1 + mov eax, 0xFFFFFFFF + mov edx, 0x0000000F + sub eax, ebx + sbb edx, 0 + or eax, 0x800 + inc ecx + wrmsr +; clear unused MTRRs + xor eax, eax + xor edx, edx @@: - wrmsr ;disable unused MTRR - inc ecx - wrmsr - inc ecx - dec ebx - jnz @b + wrmsr + inc ecx + cmp ecx, 0x210 + jb @b +; enable MTRRs + pop eax + or ah, 8 + and al, 0xF0 ; default memtype = UC + mov ecx, 0x2FF + wrmsr +.skip_init: + stdcall set_mtrr, [LFBAddress],[LFBSize],MEM_WC - wbinvd ;again invalidate + wbinvd ;again invalidate - pop eax - or eax, 0x800 ;set default memtype to UC - and al, 0xF0 - mov ecx, 0x2FF - wrmsr ;and enable MTRR - - mov eax, cr0 - and eax, not 0x60000000 - mov cr0, eax ; enable caching + mov eax, cr0 + and eax, not 0x60000000 + mov cr0, eax ; enable caching .exit: - ret + ret endp align 4 -proc set_mtrr stdcall, reg:dword,base:dword,size:dword,mem_type:dword +proc set_mtrr stdcall, base:dword,size:dword,mem_type:dword +; find unused register + mov ecx, 0x201 +@@: + rdmsr + dec ecx + test ah, 8 + jz .found + rdmsr + mov al, 0 ; clear memory type field + cmp eax, [base] + jz .ret + add ecx, 3 + cmp ecx, 0x210 + jb @b +; no free registers, ignore the call +.ret: + ret +.found: +; found, write values + xor edx, edx + mov eax, [base] + or eax, [mem_type] + wrmsr - xor edx, edx - mov eax, [base] - or eax, [mem_type] - mov ecx, [reg] - lea ecx, [0x200+ecx*2] - wrmsr - - mov ebx, [size] - dec ebx - mov eax, 0xFFFFFFFF - mov edx, 0x0000000F - sub eax, ebx - sbb edx, 0 - or eax, 0x800 - inc ecx - wrmsr - ret + mov ebx, [size] + dec ebx + mov eax, 0xFFFFFFFF + mov edx, 0x0000000F + sub eax, ebx + sbb edx, 0 + or eax, 0x800 + inc ecx + wrmsr + ret endp align 4 proc stall stdcall, delay:dword - push ecx - push edx - push ebx - push eax + push ecx + push edx + push ebx + push eax - mov eax, [delay] - mul [stall_mcs] - mov ebx, eax ;low - mov ecx, edx ;high - rdtsc - add ebx, eax - adc ecx,edx + mov eax, [delay] + mul [stall_mcs] + mov ebx, eax ;low + mov ecx, edx ;high + rdtsc + add ebx, eax + adc ecx,edx @@: - rdtsc - sub eax, ebx - sbb edx, ecx - jb @B + rdtsc + sub eax, ebx + sbb edx, ecx + jb @B - pop eax - pop ebx - pop edx - pop ecx - ret + pop eax + pop ebx + pop edx + pop ecx + ret endp align 4 proc create_ring_buffer stdcall, size:dword, flags:dword - locals - buf_ptr dd ? - endl + locals + buf_ptr dd ? + endl - mov eax, [size] - test eax, eax - jz .fail + mov eax, [size] + test eax, eax + jz .fail - add eax, eax - stdcall alloc_kernel_space, eax - test eax, eax - jz .fail + add eax, eax + stdcall alloc_kernel_space, eax + test eax, eax + jz .fail - push ebx + push ebx - mov [buf_ptr], eax + mov [buf_ptr], eax - mov ebx, [size] - shr ebx, 12 - push ebx + mov ebx, [size] + shr ebx, 12 + push ebx - stdcall alloc_pages, ebx - pop ecx + stdcall alloc_pages, ebx + pop ecx - test eax, eax - jz .mm_fail + test eax, eax + jz .mm_fail - push edi + push edi - or eax, [flags] - mov edi, [buf_ptr] - mov ebx, [buf_ptr] - mov edx, ecx - shl edx, 2 - shr edi, 10 + or eax, [flags] + mov edi, [buf_ptr] + mov ebx, [buf_ptr] + mov edx, ecx + shl edx, 2 + shr edi, 10 @@: - mov [page_tabs+edi], eax - mov [page_tabs+edi+edx], eax - invlpg [ebx] - invlpg [ebx+0x10000] - add eax, 0x1000 - add ebx, 0x1000 - add edi, 4 - dec ecx - jnz @B + mov [page_tabs+edi], eax + mov [page_tabs+edi+edx], eax + invlpg [ebx] + invlpg [ebx+0x10000] + add eax, 0x1000 + add ebx, 0x1000 + add edi, 4 + dec ecx + jnz @B - mov eax, [buf_ptr] - pop edi - pop ebx - ret + mov eax, [buf_ptr] + pop edi + pop ebx + ret .mm_fail: - stdcall free_kernel_space, [buf_ptr] - xor eax, eax - pop ebx + stdcall free_kernel_space, [buf_ptr] + xor eax, eax + pop ebx .fail: - ret + ret endp diff --git a/kernel/branches/net/core/peload.inc b/kernel/branches/net/core/peload.inc index abc4479f52..d85ec4d887 100644 --- a/kernel/branches/net/core/peload.inc +++ b/kernel/branches/net/core/peload.inc @@ -280,6 +280,8 @@ L40: __exports: export 'KERNEL', \ alloc_kernel_space, 'AllocKernelSpace', \ ; stdcall + alloc_page, 'AllocPage', \ ; gcc ABI + alloc_pages, 'AllocPages', \ ; stdcall commit_pages, 'CommitPages', \ ; eax, ebx, ecx create_kernel_object, 'CreateObject', \ create_ring_buffer, 'CreateRingBuffer', \ ; stdcall @@ -287,17 +289,12 @@ __exports: free_kernel_space, 'FreeKernelSpace', \ ; stdcall kernel_alloc, 'KernelAlloc', \ ; stdcall kernel_free, 'KernelFree', \ ; stdcall - alloc_pages, 'AllocPages', \ ; stdcall malloc, 'Kmalloc', \ free, 'Kfree', \ map_io_mem, 'MapIoMem', \ ; stdcall get_pg_addr, 'GetPgAddr', \ ; eax \ - select_hw_cursor, 'SelectHwCursor', \ ; stdcall - set_hw_cursor, 'SetHwCursor', \ ; stdcall - hw_restore, 'HwCursorRestore', \ ; - create_cursor, 'HwCursorCreate', \ ; -\ + get_display, 'GetDisplay', \ set_screen, 'SetScreen', \ pci_api, 'PciApi', \ pci_read8, 'PciRead8', \ ; stdcall @@ -307,6 +304,7 @@ __exports: pci_write16, 'PciWrite16', \ ; stdcall pci_write32, 'PciWrite32', \ ; stdcall \ + get_service, 'GetService', \ ; reg_service, 'RegService', \ ; stdcall attach_int_handler, 'AttachIntHandler', \ ; stdcall user_alloc, 'UserAlloc', \ ; stdcall diff --git a/kernel/branches/net/core/sched.inc b/kernel/branches/net/core/sched.inc index e29ee756fe..c77f7e1b16 100644 --- a/kernel/branches/net/core/sched.inc +++ b/kernel/branches/net/core/sched.inc @@ -162,21 +162,36 @@ do_change_task: ;scratched: eax,ecx,esi mov esi,ebx xchg esi,[current_slot] - ; set new stack after saving old +; set new stack after saving old mov [esi+APPDATA.saved_esp], esp mov esp, [ebx+APPDATA.saved_esp] - ; set new thread io-map +; set new thread io-map Mov dword [page_tabs+((tss._io_map_0 and -4096) shr 10)],eax,[ebx+APPDATA.io_map] Mov dword [page_tabs+((tss._io_map_1 and -4096) shr 10)],eax,[ebx+APPDATA.io_map+4] - ; set new thread memory-map +; set new thread memory-map mov ecx, APPDATA.dir_table mov eax, [ebx+ecx] ;offset>0x7F cmp eax, [esi+ecx] ;offset>0x7F je @f mov cr3, eax - @@: ; set tss.esp0 +@@: +; set tss.esp0 + Mov [tss._esp0],eax,[ebx+APPDATA.saved_esp0] - ; set gs selector unconditionally + + mov edx, [ebx+APPDATA.tls_base] + cmp edx, [esi+APPDATA.tls_base] + je @f + + mov [tls_data_l+2],dx + shr edx,16 + mov [tls_data_l+4],dl + mov [tls_data_l+7],dh + + mov dx, app_tls + mov fs, dx +@@: +; set gs selector unconditionally Mov gs,ax,graph_data ; set CR0.TS cmp bh, byte[fpu_owner] ;bh == incoming task (new) @@ -211,6 +226,7 @@ struc TIMER .arg dd ? } + MAX_PROIRITY 0 ; highest, used for kernel tasks MAX_USER_PRIORITY 0 ; highest priority for user processes USER_PRIORITY 7 ; default (should correspond to nice 0) @@ -218,7 +234,9 @@ MIN_USER_PRIORITY 14 ; minimum priority for user processes IDLE_PRIORITY 15 ; lowest, only IDLE process goes here NR_SCHED_QUEUES 16 ; MUST equal IDLE_PRIORYTY + 1 +uglobal rdy_head rd 16 +endg align 4 pick_task: diff --git a/kernel/branches/net/core/sys32.inc b/kernel/branches/net/core/sys32.inc index 10722d93cb..32c4e80a49 100644 --- a/kernel/branches/net/core/sys32.inc +++ b/kernel/branches/net/core/sys32.inc @@ -279,21 +279,26 @@ p_irq15: iret ready_for_next_irq: - mov [check_idle_semaphore],5 - mov al, 0x20 + mov eax,5 + mov [check_idle_semaphore],eax +; mov al, 0x20 + add eax,(0x20-0x5) + out 0x20, al ret - +;destroy eax ready_for_next_irq_1: - mov [check_idle_semaphore],5 - mov al, 0x20 + mov eax,5 + mov [check_idle_semaphore],eax +; mov al, 0x20 + add eax,(0x20-0x5) out 0xa0,al out 0x20, al ret irqD: push eax - mov al,0 + xor eax,eax out 0xf0,al mov al,0x20 out 0xa0,al @@ -396,37 +401,33 @@ clear_application_table_status: cmp eax,[application_table_status] jne apptsl1 - mov [application_table_status],0 + xor eax,eax + mov [application_table_status],eax apptsl1: pop eax ret +; * eax = 64 - номер функции +; * ebx = 1 - единственная подфункция +; * ecx = новый размер памяти +;Возвращаемое значение: +; * eax = 0 - успешно +; * eax = 1 - недостаточно памяти + sys_resize_app_memory: - ; eax = 1 - resize - ; ebx = new amount of memory - - cmp eax,1 - jne .no_application_mem_resize - - stdcall new_mem_resize, ebx - mov [esp+36], eax - ret + ; ebx = 1 - resize + ; ecx = new amount of memory +; cmp eax,1 + dec ebx + jnz .no_application_mem_resize + stdcall new_mem_resize, ecx + mov [esp+32], eax .no_application_mem_resize: ret -sys_threads: - -; eax=1 create thread -; -; ebx=thread start -; ecx=thread stack value -; -; on return : eax = pid -jmp new_sys_threads - iglobal ; process_terminating db 'K : Process - terminating',13,10,0 ; process_terminated db 'K : Process - done',13,10,0 @@ -497,10 +498,10 @@ term9: pop esi jmp @B @@: + mov eax, [.slot] shl eax, 8 - mov eax,[SLOT_BASE+eax+APPDATA.dir_table] - stdcall destroy_app_space, eax + stdcall destroy_app_space, [SLOT_BASE+eax+APPDATA.dir_table], [SLOT_BASE+eax+APPDATA.dlls_list_ptr] mov esi, [.slot] cmp [fpu_owner],esi ; if user fpu last -> fpu user = 1 @@ -586,13 +587,13 @@ term9: shl esi,5 add esi,window_data mov eax,[esi+WDATA.box.left] - mov [dlx],eax + mov [draw_limits.left],eax add eax,[esi+WDATA.box.width] - mov [dlxe],eax + mov [draw_limits.right],eax mov eax,[esi+WDATA.box.top] - mov [dly],eax + mov [draw_limits.top],eax add eax,[esi+WDATA.box.height] - mov [dlye],eax + mov [draw_limits.bottom],eax xor eax, eax mov [esi+WDATA.box.left],eax @@ -641,12 +642,12 @@ term9: add edi,SLOT_BASE mov eax, [edi+APPDATA.io_map] - cmp eax, (tss._io_map_0-OS_BASE+PG_MAP) + cmp eax, [SLOT_BASE+256+APPDATA.io_map] je @F call free_page @@: mov eax, [edi+APPDATA.io_map+4] - cmp eax, (tss._io_map_1-OS_BASE+PG_MAP) + cmp eax, [SLOT_BASE+256+APPDATA.io_map+4] je @F call free_page @@: @@ -689,22 +690,22 @@ term9: cmp [hd1_status], esi jnz @f call free_hd_channel - mov [hd1_status], 0 + and [hd1_status], 0 @@: cmp [cd_status], esi jnz @f call free_cd_channel - mov [cd_status], 0 + and [cd_status], 0 @@: cmp [flp_status], esi jnz @f - mov [flp_status], 0 + and [flp_status], 0 @@: pop esi cmp [bgrlockpid], esi jnz @f and [bgrlockpid], 0 - mov [bgrlock], 0 + and [bgrlock], 0 @@: pusha ; remove all irq reservations @@ -736,8 +737,8 @@ term9: mov esi,[RESERVED_PORTS] - cmp esi,0 - je rmpr9 + test esi,esi + jz rmpr9 rmpr3: @@ -796,10 +797,10 @@ term9: ; call systest sti ; .. and life goes on - mov eax, [dlx] - mov ebx, [dly] - mov ecx, [dlxe] - mov edx, [dlye] + mov eax, [draw_limits.left] + mov ebx, [draw_limits.top] + mov ecx, [draw_limits.right] + mov edx, [draw_limits.bottom] call calculatescreen xor eax, eax xor esi, esi @@ -808,7 +809,7 @@ term9: mov [MOUSE_BACKGROUND],byte 0 ; no mouse background mov [DONT_DRAW_MOUSE],byte 0 ; draw mouse - mov [application_table_status],0 + and [application_table_status],0 ;mov esi,process_terminated ;call sys_msg_board_str add esp, 4 diff --git a/kernel/branches/net/core/syscall.inc b/kernel/branches/net/core/syscall.inc index f978bfd379..54d2ca3df0 100644 --- a/kernel/branches/net/core/syscall.inc +++ b/kernel/branches/net/core/syscall.inc @@ -20,7 +20,6 @@ cross_order: call dword [servetable+edi*4] ret - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; ;; SYSENTER ENTRY ;; @@ -123,59 +122,57 @@ iglobal dd 0 dd 0 dd 0 - dd sys_midi ; 20-ResetMidi and OutputMidi - dd sys_setup ; 21-SetMidiBase,SetKeymap,SetShiftKeymap,. - dd sys_settime ; 22-setting date,time,clock and alarm-clock - dd 0 - dd syscall_cdaudio ; 24-PlayCdTrack,StopCd and GetCdPlaylist - dd 0 ; - dd sys_getsetup ; 26-GetMidiBase,GetKeymap,GetShiftKeymap,. - dd 0 - dd 0 ; - dd 0 - dd sys_current_directory ; 30-Get/SetCurrentDirectory dd 0 dd 0 dd 0 dd 0 dd 0 dd 0 - dd readmousepos ; 37-GetMousePosition_ScreenRelative,. - dd 0 ; 38-DrawLine - dd sys_getbackground ; 39-GetBackgroundSize,ReadBgrData,. dd 0 dd 0 dd 0 - dd sys_outport ; 43-SendDeviceData - dd 0 - dd 0 - dd syscall_reserveportarea ; 46-ReservePortArea and FreePortArea - dd display_number ; 47-WriteNum - dd display_settings ; 48-SetRedrawType and SetButtonType - dd sys_apm ; 49-Advanced Power Management (APM) - dd random_shaped_window ; 50-Window shape & scale - dd syscall_threads ; 51-Threads dd 0 dd 0 dd 0 - dd sound_interface ; 55-Sound interface dd 0 - dd sys_pcibios ; 57-PCI BIOS32 - dd file_system ; 58-Common file system interface dd 0 - dd sys_IPC ; 60-Inter Process Communication - dd sys_gs ; 61-Direct graphics access - dd sys_pci ; 62-PCI functions - dd sys_msg_board ; 63-System message board - dd sys_resize_app_memory ; 64-Resize application memory usage + dd 0 + dd 0 + dd 0 + dd 0 + dd 0 + dd 0 + dd 0 + dd 0 + dd 0 + dd 0 + dd 0 + dd 0 + dd 0 + dd 0 + dd 0 + dd 0 + dd 0 + dd 0 + dd 0 + dd 0 + dd 0 + dd sound_interface ; 55-Sound interface + dd 0 + dd 0 + dd file_system ; 58-Common file system interface + dd 0 + dd sys_IPC ; 60-Inter Process Communication + dd sys_gs ; 61-Direct graphics access + dd sys_pci ; 62-PCI functions + dd sys_msg_board ; 63-System message board + dd 0 dd syscall_putimage_palette; 65-PutImagePalette - dd sys_process_def ; 66-Process definitions - keyboard - dd sys_window_move ; 67-Window move or resize - dd f68 ; 68-Some internal services - dd sys_debug_services ; 69-Debug - dd file_system_lfn ; 70-Common file system interface, version 2 - dd syscall_windowsettings ; 71-Window settings - + dd sys_process_def ; 66-Process definitions - keyboard + dd sys_window_move ; 67-Window move or resize + dd 0 + dd 0 + dd file_system_lfn ; 70-Common file system interface, version 2 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; NEW SYSTEM FUNCTIONS TABLE ;; @@ -183,83 +180,83 @@ iglobal align 4 servetable2: - dd sys_drawwindow ; 0-DrawWindow - dd syscall_setpixel ; 1-SetPixel - dd sys_getkey ; 2-GetKey - dd sys_clock ; 3-GetTime - dd syscall_writetext ; 4-WriteText - dd delay_hs ; 5-DelayHs + dd sys_drawwindow ; 0-DrawWindow + dd syscall_setpixel ; 1-SetPixel + dd sys_getkey ; 2-GetKey + dd sys_clock ; 3-GetTime + dd syscall_writetext ; 4-WriteText + dd delay_hs ; 5-DelayHs dd syscall_openramdiskfile ; 6-OpenRamdiskFile - dd syscall_putimage ; 7-PutImage - dd sys_button ; 8-DefineButton - dd sys_cpuusage ; 9-GetProcessInfo - dd sys_waitforevent ; 10-WaitForEvent - dd sys_getevent ; 11-CheckForEvent - dd sys_redrawstat ; 12-BeginDraw and EndDraw - dd syscall_drawrect ; 13-DrawRect + dd syscall_putimage ; 7-PutImage + dd syscall_button ; 8-DefineButton + dd sys_cpuusage ; 9-GetProcessInfo + dd sys_waitforevent ; 10-WaitForEvent + dd sys_getevent ; 11-CheckForEvent + dd sys_redrawstat ; 12-BeginDraw and EndDraw + dd syscall_drawrect ; 13-DrawRect dd syscall_getscreensize ; 14-GetScreenSize - dd sys_background ; 15-bgr + dd sys_background ; 15-bgr dd sys_cachetodiskette ; 16-FlushFloppyCache - dd sys_getbutton ; 17-GetButton - dd sys_system ; 18-System Services - dd paleholder ; 19-reserved - dd cross_order ; 20-ResetMidi and OutputMidi - dd cross_order ; 21-SetMidiBase,SetKeymap,SetShiftKeymap,. - dd cross_order ; 22-setting date,time,clock and alarm-clock + dd sys_getbutton ; 17-GetButton + dd sys_system ; 18-System Services + dd paleholder ; 19-reserved + dd sys_midi ; 20-ResetMidi and OutputMidi + dd sys_setup ; 21-SetMidiBase,SetKeymap,SetShiftKeymap,. + dd sys_settime ; 22-setting date,time,clock and alarm-clock dd sys_wait_event_timeout ; 23-TimeOutWaitForEvent - dd cross_order ; 24-PlayCdTrack,StopCd and GetCdPlaylist - dd undefined_syscall ; 25-reserved - dd cross_order ; 26-GetMidiBase,GetKeymap,GetShiftKeymap,. - dd undefined_syscall ; 27-reserved - dd undefined_syscall ; 28-reserved - dd sys_date ; 29-GetDate - dd cross_order ; 30-Get/SetCurrentDirectory - dd undefined_syscall ; 31-reserved - dd undefined_syscall ; 32-reserved - dd undefined_syscall ; 33-reserved - dd undefined_syscall ; 34-reserved - dd syscall_getpixel ; 35-GetPixel - dd syscall_getarea ; 36-GetArea - dd cross_order ; 37-GetMousePosition_ScreenRelative,. - dd syscall_drawline ; 38-DrawLine - dd cross_order ; 39-GetBackgroundSize,ReadBgrData,. - dd set_app_param ; 40-WantEvents + dd syscall_cdaudio ; 24-PlayCdTrack,StopCd and GetCdPlaylist + dd undefined_syscall ; 25-reserved + dd sys_getsetup ; 26-GetMidiBase,GetKeymap,GetShiftKeymap,. + dd undefined_syscall ; 27-reserved + dd undefined_syscall ; 28-reserved + dd sys_date ; 29-GetDate + dd sys_current_directory ; 30-Get/SetCurrentDirectory + dd undefined_syscall ; 31-reserved + dd undefined_syscall ; 32-reserved + dd undefined_syscall ; 33-reserved + dd undefined_syscall ; 34-reserved + dd syscall_getpixel ; 35-GetPixel + dd syscall_getarea ; 36-GetArea + dd readmousepos ; 37-GetMousePosition_ScreenRelative,. + dd syscall_drawline ; 38-DrawLine + dd sys_getbackground ; 39-GetBackgroundSize,ReadBgrData,. + dd set_app_param ; 40-WantEvents dd syscall_getirqowner ; 41-GetIrqOwner - dd get_irq_data ; 42-ReadIrqData - dd cross_order ; 43-SendDeviceData - dd sys_programirq ; 44-ProgramIrqs - dd reserve_free_irq ; 45-ReserveIrq and FreeIrq - dd cross_order ; 46-ReservePortArea and FreePortArea - dd cross_order ; 47-WriteNum - dd cross_order ; 48-SetRedrawType and SetButtonType - dd cross_order ; 49-Advanced Power Management (APM) - dd cross_order ; 50-Window shape & scale - dd cross_order ; 51-Threads - dd cross_order ; 52-Stack driver status - dd cross_order ; 53-Socket interface - dd undefined_syscall ; 54-reserved - dd cross_order ; 55-Sound interface - dd undefined_syscall ; 56-reserved - dd cross_order ; 57-PCI BIOS32 - dd cross_order ; 58-Common file system interface - dd undefined_syscall ; 59-reserved - dd cross_order ; 60-Inter Process Communication - dd cross_order ; 61-Direct graphics access - dd cross_order ; 62-PCI functions - dd cross_order ; 63-System message board - dd cross_order ; 64-Resize application memory usage - dd cross_order ; 65-PutImagePalette - dd cross_order ; 66-Process definitions - keyboard - dd cross_order ; 67-Window move or resize - dd cross_order ; 68-Some internal services - dd cross_order ; 69-Debug - dd cross_order ; 70-Common file system interface, version 2 - dd cross_order ; 71-Window settings - dd sys_sendwindowmsg ; 72-Send window message + dd get_irq_data ; 42-ReadIrqData + dd sys_outport ; 43-SendDeviceData + dd sys_programirq ; 44-ProgramIrqs + dd reserve_free_irq ; 45-ReserveIrq and FreeIrq + dd syscall_reserveportarea ; 46-ReservePortArea and FreePortArea + dd display_number ; 47-WriteNum + dd syscall_display_settings ; 48-SetRedrawType and SetButtonType + dd sys_apm ; 49-Advanced Power Management (APM) + dd syscall_set_window_shape ; 50-Window shape & scale + dd syscall_threads ; 51-Threads + dd undefined_syscall ; 52-Stack driver status + dd undefined_syscall ; 53-Socket interface + dd undefined_syscall ; 54-reserved + dd cross_order ; 55-Sound interface + dd undefined_syscall ; 56-reserved + dd sys_pcibios ; 57-PCI BIOS32 + dd cross_order ; 58-Common file system interface + dd undefined_syscall ; 59-reserved + dd cross_order ; 60-Inter Process Communication + dd cross_order ; 61-Direct graphics access + dd cross_order ; 62-PCI functions + dd cross_order ; 63-System message board + dd sys_resize_app_memory ; 64-Resize application memory usage + dd cross_order ; 65-PutImagePalette + dd cross_order ; 66-Process definitions - keyboard + dd cross_order ; 67-Window move or resize + dd f68 ; 68-Some internal services + dd sys_debug_services ; 69-Debug + dd cross_order ; 70-Common file system interface, version 2 + dd syscall_windowsettings ; 71-Window settings + dd sys_sendwindowmsg ; 72-Send window message dd sys_network ; 73-Network stack dd sys_socket ; 74-Sockets dd sys_protocols ; 75-Protocols - times 255 - ( ($-servetable2) /4 ) dd undefined_syscall - dd sys_end ; -1-end application + times 255 - ( ($-servetable2) /4 ) dd undefined_syscall + dd sys_end ; -1-end application endg diff --git a/kernel/branches/net/core/taskman.inc b/kernel/branches/net/core/taskman.inc index fb6ae4cf64..02a35f70f2 100644 --- a/kernel/branches/net/core/taskman.inc +++ b/kernel/branches/net/core/taskman.inc @@ -113,6 +113,7 @@ proc fs_execute popad mov eax, -ERROR_FILE_NOT_FOUND ret + .namecopied: mov [cmdline], ebx @@ -150,8 +151,8 @@ proc fs_execute .get_lock: mov eax, 1 xchg eax, [application_table_status] - cmp eax, 0 - jne .wait_lock + test eax, eax + jnz .wait_lock call set_application_table_status @@ -201,6 +202,14 @@ proc fs_execute mov eax,[hdr_mem] mov [ebx+APPDATA.mem_size],eax + xor edx, edx + cmp word [6], '02' + jne @f + + not edx +@@: + mov [ebx+APPDATA.tls_base],edx + if GREEDY_KERNEL else mov ecx, [hdr_mem] @@ -211,7 +220,7 @@ else jna @F xor eax, eax - cld + cld rep stosb @@: end if @@ -262,26 +271,28 @@ test_app_header: jne .check_01_header mov ecx,[APP_HEADER_00.start] - mov [ebx+0x08], ecx ;app_eip + mov [ebx+0x08], ecx ;app_eip mov edx,[APP_HEADER_00.mem_size] - mov [ebx+0x10], edx ;app_mem + mov [ebx+0x10], edx ;app_mem shr edx,1 sub edx,0x10 - mov [ebx+0x0C], edx ;app_esp + mov [ebx+0x0C], edx ;app_esp mov ecx,[APP_HEADER_00.i_param] - mov [ebx], ecx ;app_cmdline - mov [ebx+4], dword 0 ;app_path + mov [ebx], ecx ;app_cmdline + mov [ebx+4], dword 0 ;app_path mov edx, [APP_HEADER_00.i_end] mov [ebx+0x14], edx ret .check_01_header: - cmp [eax+6],word '01' - jne .fail - + cmp [eax+6], word '01' + je @f + cmp [eax+6], word '02' + jne .fail +@@: mov ecx,[APP_HEADER_01.start] - mov [ebx+0x08], ecx ;app_eip + mov [ebx+0x08], ecx ;app_eip mov edx,[APP_HEADER_01.mem_size] ; \begin{diamond}[20.08.2006] @@ -291,13 +302,13 @@ test_app_header: jb .fail ; \end{diamond}[20.08.2006] - mov [ebx+0x10], edx ;app_mem + mov [ebx+0x10], edx ;app_mem mov ecx,[APP_HEADER_01.stack_top] - mov [ebx+0x0C], ecx ;app_esp + mov [ebx+0x0C], ecx ;app_esp mov edx,[APP_HEADER_01.i_param] - mov [ebx], edx ;app_cmdline + mov [ebx], edx ;app_cmdline mov ecx,[APP_HEADER_01.i_icon] - mov [ebx+4], ecx ;app_path + mov [ebx+4], ecx ;app_path mov edx, [APP_HEADER_01.i_end] mov [ebx+0x14], edx ret @@ -451,7 +462,7 @@ proc create_app_space stdcall, app_size:dword,img_base:dword,img_size:dword if GREEDY_KERNEL mov eax, 0x02 - rep stosd + rep stosd else .alloc: @@ -475,7 +486,7 @@ end if dec [pg_data.pg_mutex] cmp [dir_addr], 0 je @f - stdcall destroy_app_space, [dir_addr] + stdcall destroy_app_space, [dir_addr], 0 @@: xor eax, eax ret @@ -512,12 +523,10 @@ proc destroy_page_table stdcall, pg_tab:dword endp align 4 -proc destroy_app_space stdcall, pg_dir:dword - - mov ebx, pg_data.pg_mutex - call wait_mutex ;ebx +proc destroy_app_space stdcall, pg_dir:dword, dlls_list:dword xor edx,edx + push edx mov eax,0x2 mov ebx, [pg_dir] .loop: @@ -527,8 +536,10 @@ proc destroy_app_space stdcall, pg_dir:dword cmp byte [CURRENT_TASK+ecx+0xa],9 ;if process running? jz @f ;skip empty slots shl ecx,3 - cmp [SLOT_BASE+ecx+0xB8],ebx ;compare page directory addresses + add ecx,SLOT_BASE + cmp [ecx+APPDATA.dir_table],ebx ;compare page directory addresses jnz @f + mov [ebp-4],ecx inc edx ;thread found @@: inc eax @@ -537,13 +548,19 @@ proc destroy_app_space stdcall, pg_dir:dword ;edx = number of threads ;our process is zombi so it isn't counted + pop ecx cmp edx,1 - jg .exit + jg .ret ;if there isn't threads then clear memory. + mov esi, [dlls_list] + call destroy_all_hdlls + + mov ebx, pg_data.pg_mutex + call wait_mutex ;ebx mov eax, [pg_dir] and eax, not 0xFFF - stdcall map_page,[tmp_task_pdir],eax,dword PG_SW + stdcall map_page,[tmp_task_pdir],eax,PG_SW mov esi, [tmp_task_pdir] mov edi, (OS_BASE shr 20)/4 .destroy: @@ -551,7 +568,7 @@ proc destroy_app_space stdcall, pg_dir:dword test eax, 1 jz .next and eax, not 0xFFF - stdcall map_page,[tmp_task_ptab],eax,dword PG_SW + stdcall map_page,[tmp_task_ptab],eax,PG_SW stdcall destroy_page_table, [tmp_task_ptab] mov eax, [esi] call free_page @@ -563,16 +580,17 @@ proc destroy_app_space stdcall, pg_dir:dword mov eax, [pg_dir] call free_page .exit: - stdcall map_page,[tmp_task_ptab],dword 0,dword PG_UNMAP - stdcall map_page,[tmp_task_pdir],dword 0,dword PG_UNMAP + stdcall map_page,[tmp_task_ptab],0,PG_UNMAP + stdcall map_page,[tmp_task_pdir],0,PG_UNMAP dec [pg_data.pg_mutex] +.ret: ret endp align 4 get_pid: mov eax, [TASK_BASE] - mov eax, [eax+TASKDATA.pid] + mov eax, [eax+TASKDATA.pid] ret pid_to_slot: @@ -613,24 +631,24 @@ pid_to_slot: check_region: ;input: -; ebx - start of buffer -; ecx - size of buffer +; esi - start of buffer +; edx - size of buffer ;result: ; eax = 1 region lays in app memory ; eax = 0 region don't lays in app memory mov eax,[CURRENT_TASK] - jmp check_process_region +; jmp check_process_region ;----------------------------------------------------------------------------- -check_process_region: +;check_process_region: ;input: ; eax - slot -; ebx - start of buffer -; ecx - size of buffer +; esi - start of buffer +; edx - size of buffer ;result: ; eax = 1 region lays in app memory ; eax = 0 region don't lays in app memory - test ecx,ecx + test edx,edx jle .ok shl eax,5 cmp word [CURRENT_TASK+eax+0xa],0 @@ -698,9 +716,9 @@ align 4 proc read_process_memory ;Input: ; eax - process slot -; ebx - buffer address -; ecx - buffer size -; edx - start address in other process +; ecx - buffer address +; edx - buffer size +; esi - start address in other process ;Output: ; eax - number of bytes read. locals @@ -712,10 +730,10 @@ proc read_process_memory endl mov [slot], eax - mov [buff], ebx + mov [buff], ecx and [r_count], 0 - mov [tmp_r_cnt], ecx - mov [offset], edx + mov [tmp_r_cnt], edx + mov [offset], esi pushad .read_mem: @@ -733,18 +751,22 @@ proc read_process_memory jna @F mov ecx, 0x8000 @@: - mov eax, [slot] - shl eax,8 mov ebx, [offset] - ; add ebx, new_app_base + push ecx stdcall map_memEx, [proc_mem_map],\ - [SLOT_BASE+eax+0xB8],\ - ebx, ecx + [slot], ebx, ecx, PG_MAP pop ecx mov esi, [offset] and esi, 0xfff + sub eax, esi + jbe .ret + cmp ecx, eax + jbe @f + mov ecx, eax + mov [tmp_r_cnt], eax +@@: add esi, [proc_mem_map] mov edi, [buff] mov edx, ecx @@ -754,7 +776,7 @@ proc read_process_memory add [offset], edx sub [tmp_r_cnt], edx jnz .read_mem - +.ret: popad mov eax, [r_count] ret @@ -764,9 +786,9 @@ align 4 proc write_process_memory ;Input: ; eax - process slot -; ebx - buffer address -; ecx - buffer size -; edx - start address in other process +; ecx - buffer address +; edx - buffer size +; esi - start address in other process ;Output: ; eax - number of bytes written @@ -779,10 +801,10 @@ proc write_process_memory endl mov [slot], eax - mov [buff], ebx + mov [buff], ecx and [w_count], 0 - mov [tmp_w_cnt], ecx - mov [offset], edx + mov [tmp_w_cnt], edx + mov [offset], esi pushad .read_mem: @@ -800,18 +822,22 @@ proc write_process_memory jna @F mov ecx, 0x8000 @@: - mov eax, [slot] - shl eax,8 mov ebx, [offset] ; add ebx, new_app_base push ecx stdcall map_memEx, [proc_mem_map],\ - [SLOT_BASE+eax+0xB8],\ - ebx, ecx + [slot], ebx, ecx, PG_SW pop ecx mov edi, [offset] and edi, 0xfff + sub eax, edi + jbe .ret + cmp ecx, eax + jbe @f + mov ecx, eax + mov [tmp_w_cnt], eax +@@: add edi, [proc_mem_map] mov esi, [buff] mov edx, ecx @@ -821,7 +847,7 @@ proc write_process_memory add [offset], edx sub [tmp_w_cnt], edx jnz .read_mem - +.ret: popad mov eax, [w_count] ret @@ -838,15 +864,14 @@ proc new_sys_threads app_mem dd ? ;0x10 endl - cmp eax,1 + cmp ebx,1 jne .failed ;other subfunctions xor eax,eax + mov [app_eip], ecx mov [app_cmdline], eax + mov [app_esp], edx mov [app_path], eax - mov [app_eip], ebx - mov [app_esp], ecx - ;mov esi,new_process_loading ;call sys_msg_board_str .wait_lock: @@ -858,8 +883,8 @@ proc new_sys_threads .get_lock: mov eax, 1 xchg eax, [application_table_status] - cmp eax, 0 - jne .wait_lock + test eax, eax + jnz .wait_lock call set_application_table_status @@ -895,21 +920,38 @@ proc new_sys_threads mov [edx+APPDATA.mem_size], eax mov ecx,[ebx+APPDATA.dir_table] - mov [edx+APPDATA.dir_table],ecx ;copy page directory + mov [edx+APPDATA.dir_table],ecx ;copy page directory + + mov eax,[ebx+APPDATA.dlls_list_ptr] + mov [edx+APPDATA.dlls_list_ptr],eax + + mov eax, [ebx+APPDATA.tls_base] + test eax, eax + jz @F + + push edx + stdcall user_alloc, 4096 + pop edx + test eax, eax + jz .failed1 ;eax=0 +@@: + mov [edx+APPDATA.tls_base], eax lea eax, [app_cmdline] stdcall set_app_params ,[slot],eax,dword 0,\ dword 0,dword 0 ;mov esi,new_process_running - ;call sys_msg_board_str ;output information about succefull startup - - mov [application_table_status],0 ;unlock application_table_status mutex - mov eax,[process_number] ;set result + ;call sys_msg_board_str ;output information about succefull startup + xor eax,eax + mov [application_table_status],eax ;unlock application_table_status mutex + mov eax,[process_number] ;set result ret .failed: - mov [application_table_status],0 - mov eax,-1 + xor eax,eax +.failed1: + mov [application_table_status],eax + dec eax ;-1 ret endp @@ -931,6 +973,24 @@ wait_mutex: pop eax ret +align 4 +tls_app_entry: + + call init_heap + stdcall user_alloc, 4096 + + mov edx, [current_slot] + mov [edx+APPDATA.tls_base], eax + mov [tls_data_l+2],ax + shr eax,16 + mov [tls_data_l+4],al + mov [tls_data_l+7],ah + mov dx, app_tls + mov fs, dx + popad + iretd + + EFL_IF equ 0x0200 EFL_IOPL1 equ 0x1000 EFL_IOPL2 equ 0x2000 @@ -959,10 +1019,10 @@ proc set_app_params stdcall,slot:dword, params:dword,\ mov [eax+SLOT_BASE+APPDATA.except_mask], 0 ;set default io permission map - mov [eax+SLOT_BASE+APPDATA.io_map],\ - (tss._io_map_0-OS_BASE+PG_MAP) - mov [eax+SLOT_BASE+APPDATA.io_map+4],\ - (tss._io_map_1-OS_BASE+PG_MAP) + mov ecx, [SLOT_BASE+256+APPDATA.io_map] + mov [eax+SLOT_BASE+APPDATA.io_map], ecx + mov ecx, [SLOT_BASE+256+APPDATA.io_map+4] + mov [eax+SLOT_BASE+APPDATA.io_map+4], ecx mov esi, fpu_data mov ecx, 512/4 @@ -1037,6 +1097,11 @@ proc set_app_params stdcall,slot:dword, params:dword,\ shl ebx,5 lea ecx,[draw_data+ebx] ;ecx - pointer to draw data + mov edx, irq0.return + cmp [ebx*8+SLOT_BASE+APPDATA.tls_base], -1 + jne @F + mov edx, tls_app_entry +@@: ; set window state to 'normal' (non-minimized/maximized/rolled-up) state mov [ebx+window_data+WDATA.fl_wstate], WSTATE_NORMAL mov [ebx+window_data+WDATA.fl_redraw], 1 @@ -1050,9 +1115,9 @@ proc set_app_params stdcall,slot:dword, params:dword,\ mov [ebx+4],eax ;set PID ;set draw data to full screen - - mov [ecx+0],dword 0 - mov [ecx+4],dword 0 + xor eax,eax + mov [ecx+0],dword eax + mov [ecx+4],dword eax mov eax,[Screen_Max_X] mov [ecx+8],eax mov eax,[Screen_Max_Y] @@ -1063,7 +1128,7 @@ proc set_app_params stdcall,slot:dword, params:dword,\ lea ecx, [ebx+REG_EIP] xor eax, eax - mov [ebx+REG_RET], dword irq0.return + mov [ebx+REG_RET], edx mov [ebx+REG_EDI], eax mov [ebx+REG_ESI], eax mov [ebx+REG_EBP], eax diff --git a/kernel/branches/net/core/test_malloc.asm b/kernel/branches/net/core/test_malloc.asm new file mode 100644 index 0000000000..56e7ef2eef --- /dev/null +++ b/kernel/branches/net/core/test_malloc.asm @@ -0,0 +1,223 @@ +; Tests of malloc()/free() from the kernel heap. +; This file is not included in the kernel, it is just test application. +use32 + db 'MENUET01' + dd 1, start, i_end, mem, mem, 0, 0 + +start: +; Zero-initialize uglobals (as in kernel at boot) + mov ecx, (zeroend - zerostart + 3) / 4 + xor eax, eax + mov edi, zerostart + rep stosd +; Initialize small heap (as in kernel at boot) + call init_malloc +; Run tests + call run_test1 + call run_test2 + call run_test3 +; All is OK, return + or eax, -1 + int 0x40 + +run_test1: +; basic test + mov eax, 1 + call malloc_with_test + mov byte [eax], 0xDD + mov esi, eax + mov eax, 1 + call malloc_with_test + cmp byte [esi], 0xDD + jnz memory_destroyed + mov byte [eax], 0xEE + xchg eax, esi + call free + cmp byte [esi], 0xEE + jnz memory_destroyed + xchg eax, esi + call free + ret + +run_test2: + ret + +run_test3: +; 1024000 times run random operation. +; Randomly select malloc(random size from 1 to 1023) +; or free(random of previously allocated areas) + mov edi, 0x12345678 + xor esi, esi ; 0 areas allocated + mov ebx, 1024000 +.loop: + imul edi, 1103515245 + add edi, 12345 + mov eax, edi + shr eax, 16 + test ebx, 64 + jz .prefer_free +.prefer_malloc: + test eax, 3 + jz .free + jmp @f +.prefer_free: + test eax, 3 + jnz .free +@@: + shr eax, 2 + and eax, 1023 + jz .loop + push ebx + push eax +; mov ecx, [saved_state_num] +; mov [saved_state+ecx*8], eax + call malloc_with_test +; mov ecx, [saved_state_num] +; mov [saved_state+ecx*8+4], eax +; inc [saved_state_num] + pop ecx + pop ebx + inc esi + push ecx eax + push edi + mov edi, eax + mov eax, esi + rep stosb + pop edi + jmp .common +.free: + test esi, esi + jz .loop + xor edx, edx + div esi + sub edx, esi + neg edx + dec edx + mov eax, [esp+edx*8] +; mov ecx, [saved_state_num] +; mov [saved_state+ecx*8], -1 +; mov [saved_state+ecx*8+4], eax +; inc [saved_state_num] + mov ecx, [esp+edx*8+4] + push edi eax + mov edi, eax + mov al, [edi] + repz scasb + jnz memory_destroyed + pop eax edi + push ebx edx + call free + pop edx ebx + dec esi + pop eax ecx + push edi + lea edi, [esp+4] +@@: + dec edx + js @f + xchg eax, [edi] + xchg ecx, [edi+4] + add edi, 8 + jmp @b +@@: + pop edi +.common: + dec ebx + jnz .loop +@@: + dec esi + js @f + pop eax ecx + call free + jmp @b +@@: + ret + +malloc_with_test: +; calls malloc() and checks returned value + call malloc + test eax, eax + jz generic_malloc_fail + call check_mutex + call check_range + ret + +; Stubs for kernel procedures used by heap code +wait_mutex: + inc dword [ebx] + ret + +kernel_alloc: + cmp dword [esp+4], bufsize + jnz error1 + mov eax, buffer + ret 4 + +macro $Revision [args] +{ +} + +; Error handlers +error1: + mov eax, 1 + jmp error_with_code + +generic_malloc_fail: + mov eax, 2 + jmp error_with_code + +check_mutex: + cmp [mst.mutex], 0 + jnz @f + ret +@@: + mov eax, 3 + jmp error_with_code + +check_range: + cmp eax, buffer + jb @f + cmp eax, buffer+bufsize + jae @f + ret +@@: + mov eax, 4 + jmp error_with_code + +memory_destroyed: + mov eax, 5 + jmp error_with_code + +error_with_code: + mov edx, saved_state_num +; eax = error code +; 1 signals error in testing code (wrong bufsize) +; 2 = malloc() returned NULL +; 3 = mutex not released +; 4 = weird returned value from malloc() +; 5 = memory destroyed by malloc() or free() + int3 ; simplest way to report error + jmp $-1 ; just in case + +; Include main heap code +include '../proc32.inc' +include '../const.inc' +include 'malloc.inc' + +i_end: + +align 4 +zerostart: +mst MEM_STATE + +align 16 +bufsize = 0x40000 ; change if malloc.inc changes +buffer rb bufsize +zeroend: + +saved_state_num dd ? +saved_state rd 0x10000 + +align 4 + rb 0x10000 ; for stack +mem: diff --git a/kernel/branches/net/data32.inc b/kernel/branches/net/data32.inc index 704936bc81..5de4741dd6 100644 --- a/kernel/branches/net/data32.inc +++ b/kernel/branches/net/data32.inc @@ -1,468 +1,466 @@ -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; ;; -;; Copyright (C) KolibriOS team 2004-2008. All rights reserved. ;; -;; Distributed under terms of the GNU General Public License ;; -;; ;; -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -$Revision$ - - -keymap: - - db '6',27 - db '1234567890-=',8,9 - db 'qwertyuiop[]',13 - db '~asdfghjkl;',39,96,0,'\zxcvbnm,./',0,'45 ' - db '@234567890123',180,178,184,'6',176,'7' - db 179,'8',181,177,183,185,182 - db 'AB?',0,'45 ' - db '@234567890123',180,178,184,'6',176,'7' - db 179,'8',181,177,183,185,182 - db 'AB>D',255,'FGHIJKLMNOPQRSTUVWXYZ' - db 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' - db 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' - db 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' - - -keymap_alt: - db ' ',27 - db ' @ $ {[]}\ ',8,9 - db ' ',13 - db ' ',0,' ',0,'4',0,' ' - db ' ',180,178,184,'6',176,'7' - db 179,'8',181,177,183,185,182 - db 'ABCD',255,'FGHIJKLMNOPQRSTUVWXYZ' - db 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' - db 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' - db 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' - - - - boot_memdetect db 'Determining amount of memory',0 - boot_fonts db 'Fonts loaded',0 - boot_tss db 'Setting TSSs',0 - boot_cpuid db 'Reading CPUIDs',0 - boot_devices db 'Detecting devices',0 - boot_timer db 'Setting timer',0 - boot_irqs db 'Reprogramming IRQs',0 - boot_setmouse db 'Setting mouse',0 - boot_windefs db 'Setting window defaults',0 - boot_bgr db 'Calculating background',0 - boot_resirqports db 'Reserving IRQs & ports',0 - boot_setrports db 'Setting addresses for IRQs',0 - boot_setostask db 'Setting OS task',0 - boot_allirqs db 'Unmasking all IRQs',0 - boot_tsc db 'Reading TSC',0 - boot_cpufreq db 'CPU frequency is ',' ',' MHz',0 - boot_pal_ega db 'Setting EGA/CGA 320x200 palette',0 - boot_pal_vga db 'Setting VGA 640x480 palette',0 - boot_failed db 'Failed to start first app',0 - boot_mtrr db 'Setting MTRR',0 -if preboot_blogesc - boot_tasking db 'All set - press ESC to start',0 -end if - -;new_process_loading db 'K : New Process - loading',13,10,0 -;new_process_running db 'K : New Process - done',13,10,0 -start_not_enough_memory db 'K : New Process - not enough memory',13,10,0 - -msg_unresolved db 'unresolved ',0 -msg_module db 'in module ',0 -msg_version db 'incompatible driver version',13,10,0 -msg_www db 'please visit www.kolibrios.org',13,10,0 -msg_CR db 13,10,0 -aSis db 'SIS',0 - -intel_str db "GenuineIntel",0 -AMD_str db "AuthenticAMD",0 - -;szSound db 'SOUND',0 -;szInfinity db 'INFINITY',0 -szHwMouse db 'ATI2D',0 -szPS2MDriver db 'PS2MOUSE',0 -;szCOM_MDriver db 'COM_MOUSE',0 -szUSB db 'USB',0 -szAtiHW db '/rd/1/drivers/ati2d.drv',0 - -szSTART db 'START',0 -szEXPORTS db 'EXPORTS',0 -sz_EXPORTS db '_EXPORTS',0 - -szIMPORTS db 'IMPORTS',0 - -read_firstapp db '/sys/' -firstapp db 'LAUNCHER',0 - -char db '/sys/FONTS/CHAR.MT',0 -char2 db '/sys/FONTS/CHAR2.MT',0 - -bootpath db '/KOLIBRI ' -bootpath2 db 0 -vmode db '/sys/drivers/VMODE.MDR',0 -vrr_m db 'VRR_M',0 -kernel_file db 'KERNEL MNT' - - -align 4 - -shmem_list: - .bk dd shmem_list - .fd dd shmem_list - -; supported videomodes - -mode_1280_1024_32: - dw 1280,1024,32,60 -mode_1280_1024_24: - dw 1280,1024,24,60 -mode_1024_768_32: - dw 1024,768,32,60 -mode_1024_768_24: - dw 1024,768,24,60 -mode_800_600_32: - dw 800,600,32,60 -mode_800_600_24: - dw 800,600,24,60 -mode_640_480_32: - dw 640,480,32,60 -mode_640_480_24: - dw 640,480,24,60 -mode_640_480_16: - dw 640,480,16,60 -mode_320_240_8: - dw 320,240,8,60 - -; mike.dld { -db 0 -dd servetable-0x10000 -draw_line dd __sys_draw_line -disable_mouse dd __sys_disable_mouse -draw_pointer dd __sys_draw_pointer -;//mike.dld, 2006-08-02 [ -;drawbar dd __sys_drawbar -drawbar dd __sys_drawbar.forced -;//mike.dld, 2006-08-02 ] -putpixel dd __sys_putpixel -; } mike.dld - - -align 4 -keyboard dd 1 -syslang dd 1 - -boot_y dd 10 - -pci_bios_entry dd 0 - dw pci_code_sel - -if __DEBUG__ eq 1 - include_debug_strings -end if - -IncludeIGlobals - -align 16 -gdts: - - dw gdte-$-1 - dd gdts - dw 0 - -; Attention! Do not change the order of the first four selectors. They are used in Fast System Call -; must be : os_code, os_data, app_code, app_data, .... - -int_code_l: -os_code_l: - dw 0xffff - dw 0x0000 - db 0x00 - dw 11011111b *256 +10011010b - db 0x00 - -int_data_l: -os_data_l: - dw 0xffff - dw 0x0000 - db 0x00 - dw 11011111b *256 +10010010b - db 0x00 - -app_code_l: - dw 0xFFFF - dw 0 - db 0 - db cpl3 - dw G32+D32+(new_app_base shr 16)+0xF; - -app_data_l: - dw 0xFFFF - dw 0 - db 0 - db drw3 - dw G32+D32+(new_app_base shr 16)+0xF; - -; ------------- PCI BIOS ------------------ - -pci_code_32: - dw 0 ;lim 0-15 - dw 0 ;base 0-15 - db 0 ;base 16-23 - db cpl0 ;type - db D32 ;lim 16-19+props - db 0 ;base 24-31 - -pci_data_32: - dw 0 ;lim 0-15 - dw 0 ;base 0-15 - db 0 ;base 16-23 - db dpl0 ;type - db D32 ;lim 16-19+props - db 0 ;base 24-31 - -; --------------- APM --------------------- -apm_code_32: - dw 0x0f ; limit 64kb - db 0, 0, 0 - dw 11010000b *256 +10011010b - db 0x00 -apm_code_16: - dw 0x0f - db 0, 0, 0 - dw 10010000b *256 +10011010b - db 0x00 -apm_data_16: - dw 0x0f - db 0, 0, 0 - dw 10010000b *256 +10010010b - db 0x00 -; ----------------------------------------- - -graph_data_l: - - dw 0x7ff - dw 0x0000 - db 0x00 - dw 11010000b *256 +11110010b - db 0x00 -tss0_l: - dw TSS_SIZE-1 - dw tss and 0xFFFF - db (tss shr 16) and 0xFF - db 10001001b - dw (tss shr 16) and 0xFF00 -endofcode: -gdte: - -align 16 -cur_saved_data rb 4096 -fpu_data: rb 512 - -; device irq owners -irq_owner rd 16 ; process id - -; on irq read ports - -irq00read rd 16 -irq01read rd 16 -irq02read rd 16 -irq03read rd 16 -irq04read rd 16 -irq05read rd 16 -irq06read rd 16 -irq07read rd 16 -irq08read rd 16 -irq09read rd 16 -irq10read rd 16 -irq11read rd 16 -irq12read rd 16 -irq13read rd 16 -irq14read rd 16 -irq15read rd 16 - -irq_tab rd 16 - -mem_block_map rb 512 -mem_block_list rd 64 -large_block_list rd 31 -mem_block_mask rd 2 -large_block_mask rd 1 - -mem_used.fd rd 1 -mem_used.bk rd 1 - -mem_block_arr rd 1 -mem_block_start rd 1 -mem_block_end rd 1 - -heap_mutex rd 1 -heap_size rd 1 -heap_free rd 1 -heap_blocks rd 1 -free_blocks rd 1 - -mst MEM_STATE - -page_start rd 1 -page_end rd 1 -sys_page_map rd 1 -os_stack_seg rd 1 - - -srv.fd rd 1 -srv.bk rd 1 - -scr_width rd 1 -scr_height rd 1 - -create_cursor rd 1 -select_hw_cursor rd 1 -set_hw_cursor rd 1 -hw_restore rd 1 - -def_cursor rd 1 -current_cursor rd 1 -hw_cursor rd 1 -cur_def_interl rd 1 -cur_saved_base rd 1 -cur_saved_interl rd 1 -cur_saved_w rd 1 -cur_saved_h rd 1 - -ipc_tmp rd 1 -ipc_pdir rd 1 -ipc_ptab rd 1 - -proc_mem_map rd 1 -proc_mem_pdir rd 1 -proc_mem_tab rd 1 - -tmp_task_pdir rd 1 -tmp_task_ptab rd 1 - -default_io_map rd 1 - -LFBSize rd 1 - -stall_mcs rd 1 -current_slot rd 1 - -; status -hd1_status rd 1 ; 0 - free : other - pid -application_table_status rd 1 ; 0 - free : other - pid - -; device addresses -mididp rd 1 -midisp rd 1 - -cdbase rd 1 -cdid rd 1 - -hdbase rd 1 ; for boot 0x1f0 -hdid rd 1 -hdpos rd 1 ; for boot 0x1 -fat32part rd 1 ; for boot 0x1 -cdpos rd 1 - -;CPUID information -cpu_vendor rd 3 -cpu_sign rd 1 -cpu_info rd 1 -cpu_caps rd 4 - - -pg_data PG_DATA -heap_test rd 1 - -buttontype rd 1 -windowtypechanged rd 1 - -hd_entries rd 1 ;unused ? 0xfe10 - -;* start code - Mario79 - -mouse_active rd 1 -mouse_pause rd 1 -MouseTickCounter rd 1 - -;* end code - Mario79 - -img_background rd 1 -mem_BACKGROUND rd 1 -static_background_data rd 1 - -cache_ide0: -cache_ide0_pointer rd 1 -cache_ide0_size rd 1 ; not use -cache_ide0_data_pointer rd 1 -cache_ide0_system_data_size rd 1 ; not use -cache_ide0_appl_data_size rd 1 ; not use -cache_ide0_system_data rd 1 -cache_ide0_appl_data rd 1 -cache_ide0_system_sad_size rd 1 -cache_ide0_appl_sad_size rd 1 -cache_ide0_search_start rd 1 -cache_ide0_appl_search_start rd 1 - -cache_ide1: -cache_ide1_pointer rd 1 -cache_ide1_size rd 1 ; not use -cache_ide1_data_pointer rd 1 -cache_ide1_system_data_size rd 1 ; not use -cache_ide1_appl_data_size rd 1 ; not use -cache_ide1_system_data rd 1 -cache_ide1_appl_data rd 1 -cache_ide1_system_sad_size rd 1 -cache_ide1_appl_sad_size rd 1 -cache_ide1_search_start rd 1 -cache_ide1_appl_search_start rd 1 - -cache_ide2: -cache_ide2_pointer rd 1 -cache_ide2_size rd 1 ; not use -cache_ide2_data_pointer rd 1 -cache_ide2_system_data_size rd 1 ; not use -cache_ide2_appl_data_size rd 1 ; not use -cache_ide2_system_data rd 1 -cache_ide2_appl_data rd 1 -cache_ide2_system_sad_size rd 1 -cache_ide2_appl_sad_size rd 1 -cache_ide2_search_start rd 1 -cache_ide2_appl_search_start rd 1 - -cache_ide3: -cache_ide3_pointer rd 1 -cache_ide3_size rd 1 ; not use -cache_ide3_data_pointer rd 1 -cache_ide3_system_data_size rd 1 ; not use -cache_ide3_appl_data_size rd 1 ; not use -cache_ide3_system_data rd 1 -cache_ide3_appl_data rd 1 -cache_ide3_system_sad_size rd 1 -cache_ide3_appl_sad_size rd 1 -cache_ide3_search_start rd 1 -cache_ide3_appl_search_start rd 1 - -debug_step_pointer rd 1 -hdd_appl_data rb 1 ; 0 = system cache, 1 - application cache -cd_appl_data rb 1 ; 0 = system cache, 1 - application cache - -lba_read_enabled rd 1 ; 0 = disabled , 1 = enabled -pci_access_enabled rd 1 ; 0 = disabled , 1 = enabled -timer_ticks_enable rb 1 ; for cd driver - -NumBiosDisks rd 1 -BiosDisksData rb 200h -BiosDiskCaches rb 80h*(cache_ide1-cache_ide0) -BiosDiskPartitions rd 80h - -IncludeUGlobals +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; ;; +;; Copyright (C) KolibriOS team 2004-2009. All rights reserved. ;; +;; Distributed under terms of the GNU General Public License ;; +;; ;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +$Revision$ + + +keymap: + + db '6',27 + db '1234567890-=',8,9 + db 'qwertyuiop[]',13 + db '~asdfghjkl;',39,96,0,'\zxcvbnm,./',0,'45 ' + db '@234567890123',180,178,184,'6',176,'7' + db 179,'8',181,177,183,185,182 + db 'AB?',0,'45 ' + db '@234567890123',180,178,184,'6',176,'7' + db 179,'8',181,177,183,185,182 + db 'AB>D',255,'FGHIJKLMNOPQRSTUVWXYZ' + db 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' + db 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' + db 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' + + +keymap_alt: + db ' ',27 + db ' @ $ {[]}\ ',8,9 + db ' ',13 + db ' ',0,' ',0,'4',0,' ' + db ' ',180,178,184,'6',176,'7' + db 179,'8',181,177,183,185,182 + db 'ABCD',255,'FGHIJKLMNOPQRSTUVWXYZ' + db 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' + db 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' + db 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' + + + boot_memdetect db 'Determining amount of memory',0 + boot_fonts db 'Fonts loaded',0 + boot_tss db 'Setting TSSs',0 + boot_cpuid db 'Reading CPUIDs',0 + boot_devices db 'Detecting devices',0 + boot_timer db 'Setting timer',0 + boot_irqs db 'Reprogramming IRQs',0 + boot_setmouse db 'Setting mouse',0 + boot_windefs db 'Setting window defaults',0 + boot_bgr db 'Calculating background',0 + boot_resirqports db 'Reserving IRQs & ports',0 + boot_setrports db 'Setting addresses for IRQs',0 + boot_setostask db 'Setting OS task',0 + boot_allirqs db 'Unmasking all IRQs',0 + boot_tsc db 'Reading TSC',0 + boot_cpufreq db 'CPU frequency is ',' ',' MHz',0 + boot_pal_ega db 'Setting EGA/CGA 320x200 palette',0 + boot_pal_vga db 'Setting VGA 640x480 palette',0 + boot_failed db 'Failed to start first app',0 + boot_mtrr db 'Setting MTRR',0 +if preboot_blogesc + boot_tasking db 'All set - press ESC to start',0 +end if + +;new_process_loading db 'K : New Process - loading',13,10,0 +;new_process_running db 'K : New Process - done',13,10,0 +start_not_enough_memory db 'K : New Process - not enough memory',13,10,0 + +msg_unresolved db 'unresolved ',0 +msg_module db 'in module ',0 +msg_version db 'incompatible driver version',13,10,0 +msg_www db 'please visit www.kolibrios.org',13,10,0 +msg_CR db 13,10,0 +aSis db 'SIS',0 + +intel_str db "GenuineIntel",0 +AMD_str db "AuthenticAMD",0 + +;szSound db 'SOUND',0 +;szInfinity db 'INFINITY',0 +szHwMouse db 'ATI2D',0 +szPS2MDriver db 'PS2MOUSE',0 +;szCOM_MDriver db 'COM_MOUSE',0 +szUSB db 'USB',0 +szAtiHW db '/rd/1/drivers/ati2d.drv',0 + +szSTART db 'START',0 +szEXPORTS db 'EXPORTS',0 +sz_EXPORTS db '_EXPORTS',0 + +szIMPORTS db 'IMPORTS',0 + +read_firstapp db '/sys/' +firstapp db 'LAUNCHER',0 + +char db '/sys/FONTS/CHAR.MT',0 +char2 db '/sys/FONTS/CHAR2.MT',0 + +bootpath db '/KOLIBRI ' +bootpath2 db 0 +vmode db '/sys/drivers/VMODE.MDR',0 +vrr_m db 'VRR_M',0 +kernel_file db 'KERNEL MNT' + + +align 4 + +shmem_list: + .bk dd shmem_list + .fd dd shmem_list + +dll_list: + .bk dd dll_list + .fd dd dll_list + +MAX_DEFAULT_DLL_ADDR = 0x20000000 +MIN_DEFAULT_DLL_ADDR = 0x10000000 +dll_cur_addr dd MIN_DEFAULT_DLL_ADDR + +; supported videomodes + + +; mike.dld { +db 0 +dd servetable-0x10000 +draw_line dd __sys_draw_line +draw_pointer dd __sys_draw_pointer +;//mike.dld, 2006-08-02 [ +;drawbar dd __sys_drawbar +drawbar dd __sys_drawbar.forced +;//mike.dld, 2006-08-02 ] +putpixel dd __sys_putpixel +; } mike.dld + + +align 4 +keyboard dd 1 +syslang dd 1 + +boot_y dd 10 + +pci_bios_entry dd 0 + dw pci_code_sel + +if __DEBUG__ eq 1 + include_debug_strings +end if + +IncludeIGlobals + +align 16 +gdts: + + dw gdte-$-1 + dd gdts + dw 0 + +; Attention! Do not change the order of the first four selectors. They are used in Fast System Call +; must be : os_code, os_data, app_code, app_data, .... + +int_code_l: +os_code_l: + dw 0xffff + dw 0x0000 + db 0x00 + dw 11011111b *256 +10011010b + db 0x00 + +int_data_l: +os_data_l: + dw 0xffff + dw 0x0000 + db 0x00 + dw 11011111b *256 +10010010b + db 0x00 + +app_code_l: + dw 0xFFFF + dw 0 + db 0 + db cpl3 + dw G32+D32+0xF; + +app_data_l: + dw 0xFFFF + dw 0 + db 0 + db drw3 + dw G32+D32+0xF; + +; ------------- PCI BIOS ------------------ + +pci_code_32: + dw 0 ;lim 0-15 + dw 0 ;base 0-15 + db 0 ;base 16-23 + db cpl0 ;type + db D32 ;lim 16-19+props + db 0 ;base 24-31 + +pci_data_32: + dw 0 ;lim 0-15 + dw 0 ;base 0-15 + db 0 ;base 16-23 + db dpl0 ;type + db D32 ;lim 16-19+props + db 0 ;base 24-31 + +; --------------- APM --------------------- +apm_code_32: + dw 0x0f ; limit 64kb + db 0, 0, 0 + dw 11010000b *256 +10011010b + db 0x00 +apm_code_16: + dw 0x0f + db 0, 0, 0 + dw 10010000b *256 +10011010b + db 0x00 +apm_data_16: + dw 0x0f + db 0, 0, 0 + dw 10010000b *256 +10010010b + db 0x00 +; ----------------------------------------- + +graph_data_l: + + dw 0x7ff + dw 0x0000 + db 0x00 + dw 11010000b *256 +11110010b + db 0x00 +tss0_l: + dw TSS_SIZE-1 + dw tss and 0xFFFF + db (tss shr 16) and 0xFF + db 10001001b + dw (tss shr 16) and 0xFF00 + +tls_data_l: + dw 0x0FFF + dw 0 + db 0 + db drw3 + dw D32 + +endofcode: +gdte: + +align 16 +cur_saved_data rb 4096 +fpu_data: rb 512 + +; device irq owners +irq_owner rd 16 ; process id + +; on irq read ports + +irq00read rd 16 +irq01read rd 16 +irq02read rd 16 +irq03read rd 16 +irq04read rd 16 +irq05read rd 16 +irq06read rd 16 +irq07read rd 16 +irq08read rd 16 +irq09read rd 16 +irq10read rd 16 +irq11read rd 16 +irq12read rd 16 +irq13read rd 16 +irq14read rd 16 +irq15read rd 16 + +irq_tab rd 16 + +mem_block_map rb 512 +mem_block_list rd 64 +large_block_list rd 31 +mem_block_mask rd 2 +large_block_mask rd 1 + +mem_used.fd rd 1 +mem_used.bk rd 1 + +mem_block_arr rd 1 +mem_block_start rd 1 +mem_block_end rd 1 + +heap_mutex rd 1 +heap_size rd 1 +heap_free rd 1 +heap_blocks rd 1 +free_blocks rd 1 + +mst MEM_STATE + +page_start rd 1 +page_end rd 1 +sys_page_map rd 1 +os_stack_seg rd 1 + + +srv.fd rd 1 +srv.bk rd 1 + + +align 16 + +_display display_t + +_WinMapAddress rd 1 +_WinMapSize rd 1 + +def_cursor rd 1 +current_cursor rd 1 +hw_cursor rd 1 +cur_saved_base rd 1 + +cur.lock rd 1 ;1 - lock update, 2- hide +cur.left rd 1 ;cursor clip box +cur.top rd 1 +cur.right rd 1 +cur.bottom rd 1 +cur.w rd 1 +cur.h rd 1 + +ipc_tmp rd 1 +ipc_pdir rd 1 +ipc_ptab rd 1 + +proc_mem_map rd 1 +proc_mem_pdir rd 1 +proc_mem_tab rd 1 + +tmp_task_pdir rd 1 +tmp_task_ptab rd 1 + +default_io_map rd 1 + +LFBSize rd 1 + +stall_mcs rd 1 +current_slot rd 1 + +; status +hd1_status rd 1 ; 0 - free : other - pid +application_table_status rd 1 ; 0 - free : other - pid + +; device addresses +mididp rd 1 +midisp rd 1 + +cdbase rd 1 +cdid rd 1 + +hdbase rd 1 ; for boot 0x1f0 +hdid rd 1 +hdpos rd 1 ; for boot 0x1 +fat32part rd 1 ; for boot 0x1 +cdpos rd 1 + +;CPUID information +cpu_vendor rd 3 +cpu_sign rd 1 +cpu_info rd 1 +cpu_caps rd 4 + + +pg_data PG_DATA +heap_test rd 1 + +buttontype rd 1 +windowtypechanged rd 1 + +hd_entries rd 1 ;unused ? 0xfe10 + +;* start code - Mario79 + +mouse_active rd 1 +mouse_pause rd 1 +MouseTickCounter rd 1 + +;* end code - Mario79 + +img_background rd 1 +mem_BACKGROUND rd 1 +static_background_data rd 1 + +cache_ide0: +cache_ide0_pointer rd 1 +cache_ide0_size rd 1 ; not use +cache_ide0_data_pointer rd 1 +cache_ide0_system_data_size rd 1 ; not use +cache_ide0_appl_data_size rd 1 ; not use +cache_ide0_system_data rd 1 +cache_ide0_appl_data rd 1 +cache_ide0_system_sad_size rd 1 +cache_ide0_appl_sad_size rd 1 +cache_ide0_search_start rd 1 +cache_ide0_appl_search_start rd 1 + +cache_ide1: +cache_ide1_pointer rd 1 +cache_ide1_size rd 1 ; not use +cache_ide1_data_pointer rd 1 +cache_ide1_system_data_size rd 1 ; not use +cache_ide1_appl_data_size rd 1 ; not use +cache_ide1_system_data rd 1 +cache_ide1_appl_data rd 1 +cache_ide1_system_sad_size rd 1 +cache_ide1_appl_sad_size rd 1 +cache_ide1_search_start rd 1 +cache_ide1_appl_search_start rd 1 + +cache_ide2: +cache_ide2_pointer rd 1 +cache_ide2_size rd 1 ; not use +cache_ide2_data_pointer rd 1 +cache_ide2_system_data_size rd 1 ; not use +cache_ide2_appl_data_size rd 1 ; not use +cache_ide2_system_data rd 1 +cache_ide2_appl_data rd 1 +cache_ide2_system_sad_size rd 1 +cache_ide2_appl_sad_size rd 1 +cache_ide2_search_start rd 1 +cache_ide2_appl_search_start rd 1 + +cache_ide3: +cache_ide3_pointer rd 1 +cache_ide3_size rd 1 ; not use +cache_ide3_data_pointer rd 1 +cache_ide3_system_data_size rd 1 ; not use +cache_ide3_appl_data_size rd 1 ; not use +cache_ide3_system_data rd 1 +cache_ide3_appl_data rd 1 +cache_ide3_system_sad_size rd 1 +cache_ide3_appl_sad_size rd 1 +cache_ide3_search_start rd 1 +cache_ide3_appl_search_start rd 1 + +debug_step_pointer rd 1 +hdd_appl_data rb 1 ; 0 = system cache, 1 - application cache +cd_appl_data rb 1 ; 0 = system cache, 1 - application cache + +lba_read_enabled rd 1 ; 0 = disabled , 1 = enabled +pci_access_enabled rd 1 ; 0 = disabled , 1 = enabled +timer_ticks_enable rb 1 ; for cd driver + +NumBiosDisks rd 1 +BiosDisksData rb 200h +BiosDiskCaches rb 80h*(cache_ide1-cache_ide0) +BiosDiskPartitions rd 80h + +IncludeUGlobals diff --git a/kernel/branches/net/detect/biosdisk.inc b/kernel/branches/net/detect/biosdisk.inc index 5f3d19eb2a..2fc98039bf 100644 --- a/kernel/branches/net/detect/biosdisk.inc +++ b/kernel/branches/net/detect/biosdisk.inc @@ -55,7 +55,8 @@ bdds: inc ax cmp word [si], 170h jz @f - mov ax, -1 + or ax,-1 +; mov ax, -1 @@: stosw pop ds @@ -63,10 +64,14 @@ bdds: bddl: mov al, dl stosb - mov al, 0 - stosb - mov ax, -1 - stosw + xor ax,ax + stosb + dec ax + stosw +; mov al, 0 +; stosb +; mov ax, -1 +; stosw bddc2: cmp cl, [es:0x475] jae bdde diff --git a/kernel/branches/net/detect/dev_fd.inc b/kernel/branches/net/detect/dev_fd.inc index 0bf633582f..41bedcbdc2 100644 --- a/kernel/branches/net/detect/dev_fd.inc +++ b/kernel/branches/net/detect/dev_fd.inc @@ -24,7 +24,7 @@ $Revision$ mov cx,0xff wait_cmos: dec cx - cmp cx,0 - jne wait_cmos + test cx,cx + jnz wait_cmos in al,0x71 mov [DRIVE_DATA],al diff --git a/kernel/branches/net/detect/dev_hdcd.inc b/kernel/branches/net/detect/dev_hdcd.inc index 1a956950d5..64b9327f34 100644 --- a/kernel/branches/net/detect/dev_hdcd.inc +++ b/kernel/branches/net/detect/dev_hdcd.inc @@ -72,8 +72,9 @@ FindHDD_3: ; Адрес считываемого сектора в режиме LBA +uglobal SectorAddress DD ? - +endg ;************************************************* ;* ЧТЕНИЕ ИДЕНТИФИКАТОРА ЖЕСТКОГО ДИСКА * ;* Входные параметры передаются через глобальные * @@ -99,8 +100,8 @@ ReadHDD_ID: @@WaitCompleet: ; Проверить время выполнения команды dec ecx - cmp ecx,0 - je @@Error1 ;ошибка тайм-аута +; cmp ecx,0 + jz @@Error1 ;ошибка тайм-аута ; Проверить готовность in AL,DX test AL,80h ;состояние сигнала BSY @@ -116,19 +117,21 @@ ReadHDD_ID: mov DX,[ATABasePortAddr] ;регистр данных mov CX,256 ;число считываемых слов rep insw ;принять блок данных - jmp @@End + ret ; Записать код ошибки @@Error1: mov [DevErrorCode],1 - jmp @@End + ret @@Error6: mov [DevErrorCode],6 @@End: ret - +iglobal ; Стандартные базовые адреса каналов 1 и 2 StandardATABases DW 1F0h, 170h +endg +uglobal ; Номер канала ChannelNumber DW ? ; Номер диска @@ -148,8 +151,8 @@ ATACommand DB ? ; ; 3 - неверный номер канала, 4 - неверный номер диска, ; 5 - неверный номер головки, 6 - ошибка при выполнении ; команды) -DevErrorCode DB ? - +DevErrorCode dd ? +endg ;**************************************************** ;* ПОСЛАТЬ КОМАНДУ ЗАДАННОМУ ДИСКУ * ;* Входные параметры передаются через глобальные * @@ -203,8 +206,8 @@ SendCommandToHDD: @@WaitHDReady: ; Проверить время ожидани dec ecx - cmp ecx,0 - je @@Err1 +; cmp ecx,0 + jz @@Err1 ; mov eax,[timer_ticks] ; sub eax,[TickCounter_1] ; cmp eax,300 ;ожидать 300 тиков @@ -253,19 +256,18 @@ SendCommandToHDD: sti ; Сбросить признак ошибки mov [DevErrorCode],0 - jmp @@End_2 + ret ; Записать код ошибки @@Err1: mov [DevErrorCode],1 - jmp @@End_2 + ret @@Err2: mov [DevErrorCode],2 - jmp @@End_2 + ret @@Err3: mov [DevErrorCode],3 - jmp @@End_2 + ret @@Err4: mov [DevErrorCode],4 - jmp @@End_2 + ret @@Err5: mov [DevErrorCode],5 ; Завершение работы программы -@@End_2: ret ;************************************************* @@ -293,12 +295,12 @@ ReadCD_ID: ; Ожидать готовность данных HDD mov DX,[ATABasePortAddr] add DX,7 ;порт 1х7h - mov ecx,0xffff + mov ecx,0xffff @@WaitCompleet_1: ; Проверить врем - dec ecx - cmp ecx,0 - je @@Error1_1 ;ошибка тайм-аута + dec ecx +; cmp ecx,0 + jz @@Error1_1 ;ошибка тайм-аута ; Проверить готовность in AL,DX test AL,80h ;состояние сигнала BSY @@ -314,11 +316,11 @@ ReadCD_ID: mov DX,[ATABasePortAddr] ;порт 1x0h mov CX,256 ;число считываемых слов rep insw - jmp @@End_1 + ret ; Записать код ошибки @@Error1_1: mov [DevErrorCode],1 - jmp @@End_1 + ret @@Error6_1: mov [DevErrorCode],6 @@End_1: @@ -360,7 +362,7 @@ DeviceReset: @@WaitHDReady_1: ; Проверить время ожидани dec ecx - cmp ecx,0 +; cmp ecx,0 je @@Err1_2 ;ошибка тайм-аута ; Прочитать регистр состояни in AL,DX @@ -369,15 +371,14 @@ DeviceReset: jnz @@WaitHDReady_1 ; Сбросить признак ошибки mov [DevErrorCode],0 - jmp @@End_3 + ret ; Обработка ошибок @@Err1_2: mov [DevErrorCode],1 - jmp @@End_3 + ret @@Err3_2: mov [DevErrorCode],3 - jmp @@End_3 + ret @@Err4_2: mov [DevErrorCode],4 ; Записать код ошибки -@@End_3: ret EndFindHDD: diff --git a/kernel/branches/net/fdo.inc b/kernel/branches/net/fdo.inc index 21d6c45bf8..787401aa7b 100644 --- a/kernel/branches/net/fdo.inc +++ b/kernel/branches/net/fdo.inc @@ -6,6 +6,7 @@ $Revision$ +_esp equ esp ; ; Formatted Debug Output (FDO) @@ -61,11 +62,13 @@ macro DEBUGS_N _sign,_num,[_str] { jmp ..label ..str db _str,0 ..label: - add esp,4*8+4 - mov edx,..str - sub esp,4*8+4 +; add esp,4*8+4 +esp equ esp+4*8+4 + mov edx,..str +esp equ _esp +; sub esp,4*8+4 else - mov edx,_str + mov edx,_str end if if ~_num eq if _num eqtype eax @@ -147,7 +150,8 @@ macro DEBUGD_N _sign,_num,_dec { else if _dec eqtype 0 mov eax,_dec else - add esp,4*8+4 +; add esp,4*8+4 +esp equ esp+4*8+4 if _num eq mov eax,dword _dec else if _num = 1 @@ -165,7 +169,8 @@ macro DEBUGD_N _sign,_num,_dec { else mov eax,dword _dec end if - sub esp,4*8+4 +esp equ _esp +; sub esp,4*8+4 end if mov cl,_sign call fdo_debug_outdec @@ -215,9 +220,11 @@ macro DEBUGH_N _sign,_num,_hex { else if _hex eqtype 0 mov eax,_hex else - add esp,4*8+4 +; add esp,4*8+4 +esp equ esp+4*8+4 mov eax,dword _hex - sub esp,4*8+4 +esp equ _esp +; sub esp,4*8+4 end if if ~_num eq mov edx,_num @@ -235,75 +242,74 @@ macro DEBUGH_N _sign,_num,_hex { debug_func fdo_debug_outchar debug_beginf - pushad - movzx ebx,al - mov eax,1 - mov ecx,sys_msg_board - call ecx ; sys_msg_board - popad - ret + pushad + movzx ebx,al + mov eax,1 + mov ecx,sys_msg_board + call ecx ; sys_msg_board + popad + ret debug_endf debug_func fdo_debug_outstr debug_beginf - mov eax,1 - .l1: dec esi - js .l2 - movzx ebx,byte[edx] - or bl,bl - jz .l2 - mov ecx,sys_msg_board - call ecx ; sys_msg_board - inc edx - jmp .l1 - .l2: ret + mov eax,1 + .l1: dec esi + js .l2 + movzx ebx,byte[edx] + or bl,bl + jz .l2 + mov ecx,sys_msg_board + call ecx ; sys_msg_board + inc edx + jmp .l1 + .l2: ret debug_endf debug_func fdo_debug_outdec debug_beginf - or cl,cl - jz @f - or eax,eax - jns @f - neg eax - push eax - mov al,'-' - call fdo_debug_outchar - pop eax - @@: push 10 - pop ecx - push -'0' - .l1: xor edx,edx - div ecx - push edx - test eax,eax - jnz .l1 - .l2: pop eax - add al,'0' - jz .l3 - call fdo_debug_outchar - jmp .l2 - .l3: ret + or cl,cl + jz @f + or eax,eax + jns @f + neg eax + push eax + mov al,'-' + call fdo_debug_outchar + pop eax + @@: push 10 + pop ecx + push -'0' + .l1: xor edx,edx + div ecx + push edx + test eax,eax + jnz .l1 + .l2: pop eax + add al,'0' + jz .l3 + call fdo_debug_outchar + jmp .l2 + .l3: ret debug_endf - __fdo_hexdigits db '0123456789ABCDEF' debug_func fdo_debug_outhex - + __fdo_hexdigits db '0123456789ABCDEF' debug_beginf - mov cl,dl - neg cl - add cl,8 - shl cl,2 - rol eax,cl - .l1: rol eax,4 - push eax - and eax,0x0000000F - mov al,[__fdo_hexdigits+eax] - call fdo_debug_outchar - pop eax - dec edx - jnz .l1 - ret + mov cl,dl + neg cl + add cl,8 + shl cl,2 + rol eax,cl + .l1: rol eax,4 + push eax + and eax,0x0000000F + mov al,[__fdo_hexdigits+eax] + call fdo_debug_outchar + pop eax + dec edx + jnz .l1 + ret debug_endf ;----------------------------------------------------------------------------- diff --git a/kernel/branches/net/fs/fat12.inc b/kernel/branches/net/fs/fat12.inc index 5866494d00..52cec3ff35 100644 --- a/kernel/branches/net/fs/fat12.inc +++ b/kernel/branches/net/fs/fat12.inc @@ -65,13 +65,13 @@ floppy_fileread: mov [save_flag],0 mov [path_pointer_flp],edi - cmp esi,0 ; return ramdisk root - jne fr_noroot_1 + test esi,esi ; return ramdisk root + jnz fr_noroot_1 cmp ebx,224/16 jbe fr_do_1 mov eax,5 - mov ebx,0 - mov [flp_status],0 + xor ebx,ebx + mov [flp_status],ebx ret fr_do_1: @@ -88,26 +88,29 @@ fr_do_1: shl ecx,9 cld rep movsb - mov eax,0 ; ok read - mov ebx,0 - mov [flp_status],0 + xor eax,eax + xor ebx,ebx +; mov eax,0 ; ok read +; mov ebx,0 + mov [flp_status],eax ret fdc_status_error_1: - mov [flp_status],0 + xor eax,eax + mov [flp_status],eax mov eax,10 - mov ebx,-1 + or ebx,-1 ret fr_noroot_1: sub esp,32 call expand_filename frfloppy_1: - cmp ebx,0 - jne frfl5_1 + test ebx,ebx + jnz frfl5_1 mov ebx,1 frfl5_1: - cmp ecx,0 - jne frfl6_1 + test ecx,ecx + jnz frfl6_1 mov ecx,1 frfl6_1: dec ebx @@ -137,14 +140,14 @@ l.21_1: add ecx,21 add edi, ecx ;Advance to next entry dec dl - cmp dl,0 - jne l.21_1 + test dl,dl + jnz l.21_1 dec dh - cmp dh,0 - jne l.20_1 + test dh,dh + jnz l.20_1 fdc_status_error_3: mov eax,5 ; file not found ? - mov ebx,-1 + or ebx,-1 add esp,32+28 mov [flp_status],0 ret @@ -232,8 +235,8 @@ frnoread_1: add esp,4 pop ebx ; ebx <- eax : size of file add esp,36 - mov eax,0 - mov [flp_status],0 + xor eax,eax + mov [flp_status],eax ret fdc_status_error_5: @@ -499,8 +502,8 @@ calculate_chs: div ebx mov [FDD_Track],al mov [FDD_Head],0 - cmp edx,0 - je no_head_2 + test edx,edx + jz no_head_2 inc [FDD_Head] no_head_2: mov dl,[old_track] @@ -2131,7 +2134,7 @@ fs_FloppySetFileInfo: popa pop edi xor eax, eax - cmp [FDC_Status], 0 + cmp [FDC_Status], al jz @f mov al, 11 @@: diff --git a/kernel/branches/net/fs/fat32.inc b/kernel/branches/net/fs/fat32.inc index 9477eb0077..40dd7d5045 100644 --- a/kernel/branches/net/fs/fat32.inc +++ b/kernel/branches/net/fs/fat32.inc @@ -169,6 +169,7 @@ reserve_hd_channel: call clear_hd_cache @@: pop eax + sti .ret: ret diff --git a/kernel/branches/net/fs/fs_lfn.inc b/kernel/branches/net/fs/fs_lfn.inc index a80e50740b..5aa7940278 100644 --- a/kernel/branches/net/fs/fs_lfn.inc +++ b/kernel/branches/net/fs/fs_lfn.inc @@ -1,6 +1,6 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; -;; Copyright (C) KolibriOS team 2004-2008. All rights reserved. ;; +;; Copyright (C) KolibriOS team 2004-2009. All rights reserved. ;; ;; Distributed under terms of the GNU General Public License ;; ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -372,7 +372,7 @@ file_system_lfn: mov edi, fs_additional_handlers @@: cmp dword [edi], 0 - jz @f + jz .notfound call dword [edi] scasd scasd @@ -967,43 +967,76 @@ process_replace_file_name: ret sys_current_directory: - mov esi, [current_slot] - mov esi, [esi+APPDATA.cur_dir] - mov edx, esi - dec eax +; mov esi, [current_slot] +; mov esi, [esi+APPDATA.cur_dir] +; mov edx, esi + +;get length string of appdata.cur_dir + mov eax, [current_slot] + mov edi, [eax+APPDATA.cur_dir] + + dec ebx jz .set - dec eax + dec ebx jz .get ret .get: ; sysfunction 30.2: [for app] eax=30,ebx=2,ecx->buffer,edx=len ; for our code: ebx->buffer,ecx=len +max_cur_dir equ 0x1000 + + mov ebx,edi + + push ecx + push edi + + xor eax,eax + mov ecx,max_cur_dir + + repne scasb ;find zerro at and string + jnz .error ; no zero in cur_dir: internal error, should not happen + + sub edi,ebx ;lenght for copy + inc edi + mov [esp+32+8],edi ;return in eax + + cmp edx, edi + jbe @f + mov edx, edi @@: - lodsb - test al, al - jnz @b - sub esi, edx - inc esi - mov [esp+36], esi - cmp ecx, esi - jbe @f - mov ecx, esi -@@: - cmp ecx, 1 +;source string + pop esi +;destination string + pop edi + cmp edx, 1 jbe .ret - mov esi, edx - mov edi, ebx - mov al, '/' + + mov al,'/' ;start string with '/' stosb - dec ecx - dec ecx - rep movsb - mov byte [edi], 0 -.ret: + mov ecx,edx + rep movsb ;copy string +.ret: ret + +.error: add esp,8 + or dword [esp+32],-1 ;error not found zerro at string ->[eax+APPDATA.cur_dir] ret .set: ; sysfunction 30.1: [for app] eax=30,ebx=1,ecx->string ; for our code: ebx->string to set +; use generic resolver with APPDATA.cur_dir as destination + push max_cur_dir ;0x1000 + push edi ;destination + mov ebx,ecx + call get_full_file_name + ret + +; in: ebx = file name, [esp+4] = destination, [esp+8] = sizeof destination +; destroys all registers except ebp,esp +get_full_file_name: + push ebp + mov esi, [current_slot] + mov esi, [esi+APPDATA.cur_dir] + mov edx, esi @@: inc esi cmp byte [esi-1], 0 @@ -1012,6 +1045,7 @@ sys_current_directory: cmp byte [ebx], '/' jz .set_absolute ; string gives relative path + mov edi, [esp+8] ; destination .relative: cmp byte [ebx], 0 jz .set_ok @@ -1032,33 +1066,67 @@ sys_current_directory: dec esi cmp byte [esi], '/' jnz @b - mov byte [esi], 0 add ebx, 3 jmp .relative +.set_ok: + cmp edx, edi ; is destination equal to APPDATA.cur_dir? + jz .set_ok.cur_dir + sub esi, edx + cmp esi, [esp+12] + jb .set_ok.copy +.fail: + mov byte [edi], 0 + xor eax, eax ; fail + pop ebp + ret 8 +.set_ok.copy: + mov ecx, esi + mov esi, edx + rep movsb + mov byte [edi], 0 +.ret.ok: + mov al, 1 ; ok + pop ebp + ret 8 +.set_ok.cur_dir: + mov byte [esi], 0 + jmp .ret.ok .doset_relative: - add edx, 0x1000 - mov byte [esi], '/' - inc esi - cmp esi, edx - jae .overflow_esi + cmp edx, edi + jz .doset_relative.cur_dir + sub esi, edx + cmp esi, [esp+12] + jae .fail + mov ecx, esi + mov esi, edx + mov edx, edi + rep movsb + jmp .doset_relative.copy +.doset_relative.cur_dir: + mov edi, esi +.doset_relative.copy: + add edx, [esp+12] + mov byte [edi], '/' + inc edi + cmp edi, edx + jae .overflow @@: mov al, [ebx] inc ebx - mov [esi], al - inc esi + stosb test al, al - jz .set_ok - cmp esi, edx + jz .ret.ok + cmp edi, edx jb @b -.overflow_esi: - mov byte [esi-1], 0 ; force null-terminated string -.set_ok: - ret +.overflow: + dec edi + jmp .fail .set_absolute: lea esi, [ebx+1] call process_replace_file_name - mov edi, edx - add edx, 0x1000 + mov edi, [esp+8] + mov edx, [esp+12] + add edx, edi .set_copy: lodsb stosb @@ -1067,13 +1135,11 @@ sys_current_directory: .set_copy_cont: cmp edi, edx jb .set_copy -.overflow_edi: - mov byte [edi-1], 0 - ret + jmp .overflow .set_part2: mov esi, ebp xor ebp, ebp test esi, esi - jz .set_ok + jz .ret.ok mov byte [edi-1], '/' jmp .set_copy_cont diff --git a/kernel/branches/net/fs/iso9660.inc b/kernel/branches/net/fs/iso9660.inc index 8f0555e29c..dad1361bf8 100644 --- a/kernel/branches/net/fs/iso9660.inc +++ b/kernel/branches/net/fs/iso9660.inc @@ -5,7 +5,7 @@ ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -$Revision$ +$Revision:1322 $ uglobal @@ -625,8 +625,8 @@ cd_get_name: mov ebp,[cd_current_pointer_of_input_2] mov [cd_current_pointer_of_input],ebp mov eax,[ebp] - cmp eax,0 ; входы закончились? - je .next_sector + test eax,eax ; входы закончились? + jz .next_sector cmp ebp,CDDataBuf+2048 ; буфер закончился? jae .next_sector movzx eax, byte [ebp] diff --git a/kernel/branches/net/gui/button.inc b/kernel/branches/net/gui/button.inc index f498180f2a..bda7acf276 100644 --- a/kernel/branches/net/gui/button.inc +++ b/kernel/branches/net/gui/button.inc @@ -1,644 +1,579 @@ -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; ;; -;; Copyright (C) KolibriOS team 2004-2008. All rights reserved. ;; -;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa ;; -;; Distributed under terms of the GNU General Public License ;; -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -$Revision$ - - -max_buttons=4095 -dececx: - push edx - push ecx - - mov edx,2 - .loop: - - cmp byte [esp+edx],0x20 - jae @f - mov [esp+edx],byte 0x20 - @@: - sub [esp+edx],byte 0x20 - - dec edx - jns .loop - - pop ecx - pop edx - ret - -incecx: - push edx - push ecx - - mov edx,2 - .loop: - - cmp byte [esp+edx],0xdf - jbe @f - mov [esp+edx],byte 0xdf - @@: - add [esp+edx],byte 0x20 - - dec edx - jns .loop - pop ecx - pop edx - ret - -incecx2: - push edx - push ecx - - mov edx,2 - .loop: - - cmp byte [esp+edx],0xeb - jbe @f - mov [esp+edx],byte 0xeb - @@: - add [esp+edx],byte 0x14 - - dec edx - jns .loop - pop ecx - pop edx - ret - -drawbuttonframes: - - push esi - push edi - push eax - push ebx - push ecx - push edx - - shr ebx,16 - shr ecx,16 - mov eax,[TASK_BASE] - - add ebx,[eax-twdw + WDATA.box.left] - add ecx,[eax-twdw + WDATA.box.top] - mov eax, ebx - shl eax, 16 - mov ax, bx - add ax, word [esp+8] - mov ebx, ecx - shl ebx, 16 - mov bx, cx - push ebx - xor edi, edi - mov ecx, esi - call incecx - call [draw_line] - - movzx edx,word [esp+4+4] - add ebx,edx - shl edx,16 - add ebx,edx - mov ecx,esi - call dececx - call [draw_line] - - pop ebx - push edx - mov edx,eax - shr edx,16 - mov ax,dx - mov edx,ebx - shr edx,16 - mov bx,dx - mov dx,[esp+4+4] - add bx,dx - pop edx - mov ecx,esi - call incecx - call [draw_line] - - mov dx,[esp+8] - add ax,dx - shl edx,16 - add eax,edx - add ebx,1*65536 - mov ecx,esi - call dececx - call [draw_line] - - pop edx - pop ecx - pop ebx - pop eax - pop edi - pop esi - - ret - -button_dececx: - - cmp [buttontype],dword 1 - jne .finish -; je bdece -; ret -; bdece: - push eax - mov eax,0x01 - cmp edi,20 - jg @f - mov eax,0x02 - @@: - test ecx,0xff - jz @f - sub ecx,eax - @@: - shl eax,8 - test ecx,0xff00 - jz @f - sub ecx,eax - @@: - shl eax,8 - test ecx,0xff0000 - jz @f - sub ecx,eax - @@: - pop eax - .finish: - ret - - -sys_button: - - mov eax, [current_slot] - rol ebx, 16 - add bx, word [eax+APPDATA.wnd_clientbox.left] - rol ebx, 16 - rol ecx, 16 - add cx, word [eax+APPDATA.wnd_clientbox.top] - rol ecx, 16 -.forced: - - test edx, 0x80000000 - jnz remove_button - - or bx, bx - jle noaddbutt - or cx, cx - jle noaddbutt - - test edx, 0x40000000 - jnz button_no_draw - - pushad ; button body - movzx edi, cx - shr ebx, 16 - shr ecx, 16 - mov eax, [TASK_BASE] - add ebx, [eax-twdw + WDATA.box.left] - add ecx, [eax-twdw + WDATA.box.top] - mov eax, ebx - shl eax, 16 - mov ax, bx - add ax, word [esp+16] - mov ebx, ecx - shl ebx, 16 - mov bx, cx - mov ecx, esi - cmp [buttontype], 0 - je @f - call incecx2 -@@: - mov edx, edi - -.newline: - call button_dececx - push edi - xor edi, edi - call [draw_line] - pop edi - add ebx, 1*65536+1 ; [ y start | y end ] - dec edx - jnz .newline - popad - - call drawbuttonframes - -button_no_draw: - - mov edi, [BTN_ADDR] - movzx eax, word [edi] - cmp eax, max_buttons - jge noaddbutt - inc eax - mov [edi], ax - - shl eax, 4 - add edi, eax - - mov ax, [CURRENT_TASK] - stosw - mov ax, dx - stosw ; button id number: bits 0-15 - mov eax, ebx - rol eax, 16 - stosd ; x start | x size - mov eax, ecx - rol eax, 16 - stosd ; y start | y size - mov eax, edx - shr eax, 16 - stosw ; button id number: bits 16-31 - -noaddbutt: - - ret - - -remove_button: - - and edx, 0x7fffffff - -rnewba2: - - mov edi, [BTN_ADDR] - mov eax, edi - movzx ebx, word [edi] - inc ebx - -rnewba: - - dec ebx - jz rnmba - - add eax, 0x10 - - mov cx, [CURRENT_TASK] - cmp cx, [eax] - jnz rnewba - cmp dx, [eax+2] - jnz rnewba - - lea ecx, [ebx+1] - shl ecx, 4 - mov ebx, eax - add eax, 0x10 - call memmove - dec dword [edi] - jmp rnewba2 - -rnmba: - - ret - -find_pressed_button_frames: - - pushad - - movzx ebx,word [eax+0] - shl ebx,5 - add ebx,window_data - mov ecx, [ebx+ WDATA.box.left] ; window x start - movzx edx,word [eax+4] ; button x start - add ecx,edx - push ecx - - mov dx,[eax+6] ; button x size - add cx,dx - mov esi,ecx - inc esi - mov ecx, [ebx+WDATA.box.top] ; window y start - mov dx,[eax+8] ; button y start - add ecx,edx - mov ebx,ecx - mov dx,[eax+10] ; button y size - add dx,cx - inc dx - - pop eax - - ; eax x beginning - ; ebx y beginning - ; esi x end - ; edx y end - ; ecx color - - mov [pressed_button_eax],eax - mov [pressed_button_ebx],ebx - mov [pressed_button_ecx],ecx - mov [pressed_button_edx],edx - mov [pressed_button_esi],esi - - popad - ret - -uglobal - pressed_button_eax dd 0 - pressed_button_ebx dd 0 - pressed_button_ecx dd 0 - pressed_button_edx dd 0 - pressed_button_esi dd 0 -endg - -; negative button image - -negativebutton: - ; If requested, do not display button - ; boarder on press. - test ebx,0x20000000 - jz draw_negative_button - ret - draw_negative_button: - - pushad - - mov eax,[pressed_button_eax] - mov ebx,[pressed_button_ebx] - mov ecx,[pressed_button_ecx] - mov edx,[pressed_button_edx] - mov esi,[pressed_button_esi] - mov ecx,0x01000000 - - dec edx - push edx - inc edx - dec esi - push esi - inc esi - - push eax - push ebx - push ecx - push edx - push edi - - call [disable_mouse] - - bdbnewline: - mov edi,1 ; force - cmp eax,[esp+16] - jz bneg - cmp eax,[esp+20] - jz bneg - cmp ebx,[esp+12] - jz bneg - cmp ebx,[esp+24] - jnz nbneg -; jz bneg -; jmp nbneg - - bneg: - - ;;;call [disable_mouse] - call [putpixel] - - nbneg: - - inc eax - cmp eax,esi - jnz bdbnewline - mov eax,[esp+16] - inc ebx - cmp ebx,edx - jnz bdbnewline - - add esp,28 - - popad - - ret - -; check buttons - - -; 0000 word process number -; 0002 word button id number : bits 0-15 -; 0004 word x start -; 0006 word x size -; 0008 word y start -; 000A word y size -; 000C word button id number : bits 16-31 -; -; button table in 0x10 increments -; -; first at 0x10 - -align 4 -checkbuttons: - - cmp [BTN_DOWN],byte 0 ; mouse buttons pressed - jnz @f -;..................................... start 1/5 : modified by vhanla ............................. - mov [bPressedMouseXY_B],0 -;..................................... end 1/5 : modified by vhanla ............................. - ret - @@: - pushad - - xor esi, esi - mov edi, [BTN_ADDR] - movzx edx, word [edi] - test edx, edx - jne @f - popad - ret - - @@: -;..................................... start 2/5 : modified by vhanla ............................. - ;here i catch the coordinates when the mouse's button is clicked - push ax - cmp [bPressedMouseXY_B],0;FALSE - jnz @f - mov [bPressedMouseXY_B],1;TRUE - it was already clicked - mov ax,[MOUSE_X] - mov [mx],ax - mov ax,[MOUSE_Y] - mov [my],ax - @@: - pop ax - ;and it is only refreshed after the mouse's button release -;..................................... end 2/5 : modified by vhanla ............................. - - push esi - inc edx - push edx - - buttonnewcheck: - - pop edx - pop esi - inc esi - cmp edx,esi - jge bch - - popad ; no button pressed - ret - - bch: - - push esi - push edx - mov eax,esi - shl eax,4 - add eax,edi - - ; check that button is at top of windowing stack - - movzx ebx,word [eax] - movzx ecx,word [WIN_STACK + ebx * 2] - cmp ecx,[TASK_COUNT] - jne buttonnewcheck - - ; check that button start is inside window x/y end - - movzx ebx,word [eax+0] - shl ebx,5 - - test [ebx+window_data+WDATA.fl_wstate],WSTATE_MINIMIZED - jnz buttonnewcheck - -; add ebx,window_data -; mov ecx,[window_data+ebx+8] ; window end X - movzx edx,word [eax+4] ; button start X - cmp edx, [window_data+ebx+WDATA.box.width] ;ecx - jge buttonnewcheck - -; mov ecx,[window_data+ebx+12] ; window end Y - movzx edx, word [eax+8] ; button start Y - cmp edx, [window_data+ebx+WDATA.box.height] ;ecx - jge buttonnewcheck - - ; check coordinates - ; mouse x >= button x ? - movzx ebx,word [eax+0] - shl ebx,5 - add ebx,window_data - mov ecx, [ebx+WDATA.box.left] ; window x start - movzx edx,word [eax+4] ; button x start - add edx,ecx -;..................................... start 3/5 : modified by vhanla ............................. - mov cx,[mx] ;mov cx,[MOUSE_X] -;..................................... end 3/5 : modified by vhanla ............................. - cmp edx,ecx - jg buttonnewcheck - - movzx ebx,word [eax+6] ; button x size - add edx,ebx - cmp ecx,edx - jg buttonnewcheck - - ; mouse y >= button y ? - movzx ebx,word [eax+0] - shl ebx,5 - add ebx,window_data - mov ecx, [ebx+WDATA.box.top] ; window y start - movzx edx,word [eax+8] ; button y start - add edx,ecx -;..................................... start 4/5 : modified by vhanla ............................. - mov cx,[my] ;mov cx,[MOUSE_Y] -;..................................... start 4/5 : modified by vhanla ............................. - cmp edx,ecx - jg buttonnewcheck - - movzx ebx,word [eax+10] ; button y size - add edx,ebx - cmp ecx,edx - jg buttonnewcheck - - ; mouse on button - - pop edx - pop esi - - mov bx,[eax+0xc] ; button id : bits 16-31 - shl ebx,16 - mov bx,[eax+2] ; button id : bits 00-16 - push ebx - - mov [MOUSE_DOWN],byte 1 ; no mouse down checks - call find_pressed_button_frames - call negativebutton - - pushad -; // Alver 22.06.2008 // { - push eax - mov al, byte [BTN_DOWN] - mov byte [btn_down_determ], al - pop eax -; } \\ Alver \\ - - cbwaitmouseup: - - call checkidle - - call [draw_pointer] - - pushad - call stack_handler - popad - - cmp [BTN_DOWN],byte 0 ; mouse buttons pressed ? - jnz cbwaitmouseup - popad - - call negativebutton - mov [MOUSE_BACKGROUND],byte 0 ; no mouse background - mov [DONT_DRAW_MOUSE],byte 0 ; draw mouse -;..................................... start 5/5 : modified by vhanla ............................. - ; check coordinates -iglobal - mx dw 0x0 ; keeps the x mouse's position when it was clicked - my dw 0x0 ; keeps the y mouse's position when it was clicked - bPressedMouseXY_B db 0x0 - btn_down_determ db 0x0 ; << // Alver 22.06.2008// << -endg - - pusha - ; mouse x >= button x ? - movzx ebx,word [eax+0] - shl ebx,5 - add ebx,window_data - mov ecx, [ebx+WDATA.box.left] ; window x start - movzx edx,word [eax+4] ; button x start - add edx,ecx - mov cx,[MOUSE_X] - cmp edx,ecx - jg no_on_button ;if we release the pointer out of the button area - - movzx ebx,word [eax+6] ; button x size - add edx,ebx - cmp ecx,edx - jg no_on_button - - ; mouse y >= button y ? - movzx ebx,word [eax+0] - shl ebx,5 - add ebx,window_data - mov ecx, [ebx+WDATA.box.top] ; window y start - movzx edx,word [eax+8] ; button y start - add edx,ecx - mov cx,[MOUSE_Y] - cmp edx,ecx - jg no_on_button - - movzx ebx,word [eax+10] ; button y size - add edx,ebx - cmp ecx,edx - jg no_on_button - popa - mov [BTN_COUNT],byte 1 ; no of buttons in buffer - pop ebx - mov [BTN_BUFF],ebx ; lets put the button id in buffer - push ebx - pusha - jmp yes_on_button -no_on_button: - mov [BTN_COUNT],byte 0 ; no of buttons in buffer -yes_on_button: - mov [MOUSE_DOWN],byte 0 ; mouse down -> do not draw - popa - pop ebx - popa - ret - -;..................................... end 5/5 : modified by vhanla ................................ +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; ;; +;; Copyright (C) KolibriOS team 2004-2008. All rights reserved. ;; +;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa ;; +;; Distributed under terms of the GNU General Public License ;; +;; ;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +$Revision$ + + +button._.MAX_BUTTONS = 4095 + + +;============================================================================== +;///// public functions /////////////////////////////////////////////////////// +;============================================================================== + +struc SYS_BUTTON +{ + .pslot dw ? + .id_lo dw ? + .left dw ? + .width dw ? + .top dw ? + .height dw ? + .id_hi dw ? + .sizeof: +} +virtual at 0 + SYS_BUTTON SYS_BUTTON +end virtual + +iglobal + mx dw 0x0 ; keeps the x mouse's position when it was clicked + my dw 0x0 ; keeps the y mouse's position when it was clicked + bPressedMouseXY_B db 0x0 + btn_down_determ db 0x0 +endg + +align 4 +;------------------------------------------------------------------------------ +syscall_button: ;///// system function 8 ////////////////////////////////////// +;------------------------------------------------------------------------------ +;? Define/undefine GUI button object +;------------------------------------------------------------------------------ +;; Define button: +;> ebx = pack[16(x), 16(width)] +;> ecx = pack[16(y), 16(height)] +;> edx = pack[8(flags), 24(button identifier)] +;> flags bits: +;> 7 (31) = 0 +;> 6 (30) = don't draw button +;> 5 (29) = don't draw button frame when pressed +;> esi = button color +; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +;; Undefine button: +;> edx = pack[8(flags), 24(button identifier)] +;> flags bits: +;> 7 (31) = 1 +;------------------------------------------------------------------------------ + ; do we actually need to undefine the button? + test edx, 0x80000000 + jnz .remove_button + + ; do we have free button slots available? + mov edi, [BTN_ADDR] + mov eax, [edi] + cmp eax, button._.MAX_BUTTONS + jge .exit + + ; does it have positive size? (otherwise it doesn't have sense) + or bx, bx + jle .exit + or cx, cx + jle .exit + + ; make coordinates clientbox-relative + push eax + mov eax, [current_slot] + rol ebx, 16 + add bx, word[eax + APPDATA.wnd_clientbox.left] + rol ebx, 16 + rol ecx, 16 + add cx, word[eax + APPDATA.wnd_clientbox.top] + rol ecx, 16 + pop eax + + ; basic checks passed, define the button + push ebx ecx edx + inc eax + mov [edi], ax + shl eax, 4 + add edi, eax + ; NOTE: this code doesn't rely on SYS_BUTTON struct, please revise it + ; if you change something + mov ax, [CURRENT_TASK] + stosw + mov ax, dx + stosw ; button id number: bits 0-15 + mov eax, ebx + rol eax, 16 + stosd ; x start | x size + mov eax, ecx + rol eax, 16 + stosd ; y start | y size + mov eax, edx + shr eax, 16 + stosw ; button id number: bits 16-31 + pop edx ecx ebx + + ; do we also need to draw the button? + test edx, 0x40000000 + jnz .exit + + ; draw button body + + pushad + + ; calculate window-relative coordinates + movzx edi, cx + shr ebx, 16 + shr ecx, 16 + mov eax, [TASK_BASE] + add ebx, [eax - twdw + WDATA.box.left] + add ecx, [eax - twdw + WDATA.box.top] + mov eax, ebx + shl eax, 16 + mov ax, bx + add ax, word[esp + 16] + mov ebx, ecx + shl ebx, 16 + mov bx, cx + + ; calculate initial color + mov ecx, esi + cmp [buttontype], 0 + je @f + call button._.incecx2 + + ; set button height counter + @@: mov edx, edi + + .next_line: + call button._.button_dececx + push edi + xor edi, edi + call [draw_line] + pop edi + add ebx, 0x00010001 + dec edx + jnz .next_line + + popad + + ; draw button frame + + push ebx ecx + + ; calculate window-relative coordinates + shr ebx, 16 + shr ecx, 16 + mov eax, [TASK_BASE] + add ebx, [eax - twdw + WDATA.box.left] + add ecx, [eax - twdw + WDATA.box.top] + + ; top border + mov eax, ebx + shl eax, 16 + mov ax, bx + add ax, [esp + 4] + mov ebx, ecx + shl ebx, 16 + mov bx, cx + push ebx + xor edi, edi + mov ecx, esi + call button._.incecx + call [draw_line] + + ; bottom border + movzx edx, word[esp + 4 + 0] + add ebx, edx + shl edx, 16 + add ebx, edx + mov ecx, esi + call button._.dececx + call [draw_line] + + ; left border + pop ebx + push edx + mov edx, eax + shr edx, 16 + mov ax, dx + mov edx, ebx + shr edx, 16 + mov bx, dx + add bx, [esp + 4 + 0] + pop edx + mov ecx, esi + call button._.incecx + call [draw_line] + + ; right border + mov dx, [esp + 4] + add ax, dx + shl edx, 16 + add eax, edx + add ebx, 0x00010000 + mov ecx, esi + call button._.dececx + call [draw_line] + + pop ecx ebx + + .exit: + ret + +; FIXME: mutex needed +syscall_button.remove_button: + and edx, 0x00ffffff + mov edi, [BTN_ADDR] + mov ebx, [edi] + inc ebx + imul esi, ebx, SYS_BUTTON.sizeof + add esi, edi + xor ecx, ecx + add ecx, -SYS_BUTTON.sizeof + + .next_button: + dec ebx + jz .exit + + add ecx, SYS_BUTTON.sizeof + add esi, -SYS_BUTTON.sizeof + + ; does it belong to our process? + mov ax, [CURRENT_TASK] + cmp ax, [esi + SYS_BUTTON.pslot] + jne .next_button + + ; does the identifier match? + mov eax, dword[esi + SYS_BUTTON.id_hi - 2] + mov ax, [esi + SYS_BUTTON.id_lo] + and eax, 0x00ffffff + cmp edx, eax + jne .next_button + + ; okay, undefine it + push ebx + mov ebx, esi + lea eax, [esi + SYS_BUTTON.sizeof] + call memmove + dec dword[edi] + add ecx, -SYS_BUTTON.sizeof + pop ebx + jmp .next_button + + .exit: + ret + +align 4 +;------------------------------------------------------------------------------ +check_buttons: ;/////////////////////////////////////////////////////////////// +;------------------------------------------------------------------------------ +;? +;------------------------------------------------------------------------------ + cmp byte[BTN_DOWN], 0 ; mouse buttons pressed + jnz @f + mov [bPressedMouseXY_B], 0 + ret + + @@: pushad + xor esi, esi + mov edi, [BTN_ADDR] + mov edx, [edi] + test edx, edx + jne @f + popad + ret + + ;here i catch the coordinates when the mouse's button is clicked + @@: push ax + cmp [bPressedMouseXY_B], 0 ; FALSE + jnz @f + mov [bPressedMouseXY_B], 1 ; TRUE - it was already clicked + mov ax, [MOUSE_X] + mov [mx], ax + mov ax, [MOUSE_Y] + mov [my], ax + @@: pop ax + ;and it is only refreshed after the mouse's button release + + push esi + inc edx + push edx + + .buttonnewcheck: + pop edx + pop esi + inc esi + cmp edx, esi + jge .bch + + popad + ret + + .bch: + push esi + push edx + mov eax, esi + shl eax, 4 + add eax, edi + + ; check that button is at top of windowing stack + movzx ebx, [eax + SYS_BUTTON.pslot] + movzx ecx, word[WIN_STACK + ebx * 2] + cmp ecx, [TASK_COUNT] + jne .buttonnewcheck + + ; check that button start is inside window x/y end + shl ebx, 5 + + test [ebx + window_data + WDATA.fl_wstate], WSTATE_MINIMIZED + jnz .buttonnewcheck + + movzx edx, [eax + SYS_BUTTON.left] + cmp edx, [window_data + ebx + WDATA.box.width] ;ecx + jge .buttonnewcheck + + movzx edx, [eax + SYS_BUTTON.top] + cmp edx, [window_data + ebx + WDATA.box.height] ;ecx + jge .buttonnewcheck + + ; check coordinates + + ; mouse x >= button x ? + add ebx, window_data + mov ecx, [ebx + WDATA.box.left] + movzx edx, [eax + SYS_BUTTON.left] + add edx, ecx + mov cx, [mx] ;mov cx,[MOUSE_X] + cmp edx, ecx + jg .buttonnewcheck + + movzx ebx, [eax + SYS_BUTTON.width] + add edx, ebx + cmp ecx, edx + jg .buttonnewcheck + + ; mouse y >= button y ? + movzx ebx, [eax + SYS_BUTTON.pslot] + shl ebx, 5 + add ebx, window_data + mov ecx, [ebx + WDATA.box.top] + movzx edx, [eax + SYS_BUTTON.top] + add edx, ecx + mov cx, [my] ;mov cx,[MOUSE_Y] + cmp edx, ecx + jg .buttonnewcheck + + movzx ebx, [eax + SYS_BUTTON.height] + add edx, ebx + cmp ecx, edx + jg .buttonnewcheck + + ; mouse on button + + pop edx + pop esi + + mov ebx, dword[eax + SYS_BUTTON.id_hi - 2] ; button id : bits 16-31 + mov bx, [eax + SYS_BUTTON.id_lo] ; button id : bits 00-16 + push ebx + + mov byte[MOUSE_DOWN], 1 ; no mouse down checks + call button._.negative_button + + pushad + push eax + mov al, [BTN_DOWN] + mov byte[btn_down_determ], al + pop eax + + .cbwaitmouseup: + call checkidle + call [draw_pointer] + + pushad + call stack_handler + popad + + cmp byte[BTN_DOWN], 0 ; mouse buttons pressed ? + jnz .cbwaitmouseup + popad + + call button._.negative_button + mov byte[MOUSE_BACKGROUND], 0 ; no mouse background + mov byte[DONT_DRAW_MOUSE], 0 ; draw mouse + + ; check coordinates + pusha + + ; mouse x >= button x ? + movzx ebx, [eax + SYS_BUTTON.pslot] + shl ebx, 5 + add ebx, window_data + mov ecx, [ebx + WDATA.box.left] + movzx edx, [eax + SYS_BUTTON.left] + add edx, ecx + mov cx, [MOUSE_X] + cmp edx, ecx + jg .no_on_button ;if we release the pointer out of the button area + + movzx ebx, [eax + SYS_BUTTON.width] + add edx, ebx + cmp ecx, edx + jg .no_on_button + + ; mouse y >= button y ? + movzx ebx, [eax + SYS_BUTTON.pslot] + shl ebx, 5 + add ebx, window_data + mov ecx, [ebx + WDATA.box.top] + movzx edx, [eax + SYS_BUTTON.top] + add edx, ecx + mov cx, [MOUSE_Y] + cmp edx, ecx + jg .no_on_button + + movzx ebx, [eax + SYS_BUTTON.height] + add edx, ebx + cmp ecx, edx + jg .no_on_button + + popa + + mov byte[BTN_COUNT], 1 ; no of buttons in buffer + pop ebx + mov [BTN_BUFF], ebx ; lets put the button id in buffer + push ebx + pusha + jmp .yes_on_button + + .no_on_button: + mov byte[BTN_COUNT], 0 ; no of buttons in buffer + + .yes_on_button: + mov byte[MOUSE_DOWN], 0 ; mouse down -> do not draw + popa + pop ebx + popa + ret + +;============================================================================== +;///// private functions ////////////////////////////////////////////////////// +;============================================================================== + +;------------------------------------------------------------------------------ +button._.dececx: ;///////////////////////////////////////////////////////////// +;------------------------------------------------------------------------------ +;? +;------------------------------------------------------------------------------ + sub cl, 0x20 + jnc @f + xor cl, cl + @@: sub ch, 0x20 + jnc @f + xor ch, ch + @@: rol ecx, 16 + sub cl, 0x20 + jnc @f + xor cl, cl + @@: rol ecx, 16 + ret + +;------------------------------------------------------------------------------ +button._.incecx: ;///////////////////////////////////////////////////////////// +;------------------------------------------------------------------------------ +;? +;------------------------------------------------------------------------------ + add cl, 0x20 + jnc @f + or cl, -1 + @@: add ch, 0x20 + jnc @f + or ch, -1 + @@: rol ecx, 16 + add cl, 0x20 + jnc @f + or cl, -1 + @@: rol ecx, 16 + ret + +;------------------------------------------------------------------------------ +button._.incecx2: ;//////////////////////////////////////////////////////////// +;------------------------------------------------------------------------------ +;? +;------------------------------------------------------------------------------ + add cl, 0x14 + jnc @f + or cl, -1 + @@: add ch, 0x14 + jnc @f + or ch, -1 + @@: rol ecx, 16 + add cl, 0x14 + jnc @f + or cl, -1 + @@: rol ecx, 16 + ret + +;------------------------------------------------------------------------------ +button._.button_dececx: ;////////////////////////////////////////////////////// +;------------------------------------------------------------------------------ +;? +;------------------------------------------------------------------------------ + cmp [buttontype], 1 + jne .finish + + push eax + mov al, 1 + cmp edi, 20 + jg @f + mov al, 2 + + @@: sub cl, al + jnc @f + xor cl, cl + @@: sub ch, al + jnc @f + xor ch, ch + @@: rol ecx, 16 + sub cl, al + jnc @f + xor cl, cl + @@: rol ecx, 16 + + pop eax + + .finish: + ret + +;------------------------------------------------------------------------------ +button._.negative_button: ;//////////////////////////////////////////////////// +;------------------------------------------------------------------------------ +;? +;------------------------------------------------------------------------------ + ; if requested, do not display button border on press. + test ebx, 0x20000000 + jnz .exit + + pushad + + xchg esi, eax + + movzx ecx, [esi + SYS_BUTTON.pslot] + shl ecx, 5 + add ecx, window_data + + mov eax, dword[esi + SYS_BUTTON.left] + mov ebx, dword[esi + SYS_BUTTON.top] + add eax, [ecx + WDATA.box.left] + add ebx, [ecx + WDATA.box.top] + push eax ebx + pop edx ecx + rol eax, 16 + rol ebx, 16 + add ax, cx + add bx, dx + + mov esi, 0x01000000 + call draw_rectangle.forced + + popad + + .exit: + ret diff --git a/kernel/branches/net/gui/font.inc b/kernel/branches/net/gui/font.inc index e693361153..b5fbbab459 100644 --- a/kernel/branches/net/gui/font.inc +++ b/kernel/branches/net/gui/font.inc @@ -33,7 +33,7 @@ dtext: ; Text String Output (rw by Johnny_B[john@kolibrios.org]) .1: ; } \\ Alver \\ pushad - call [disable_mouse] + call [_display.disable_mouse] movsx eax, bx ; eax=y sar ebx, 16 ; ebx=x diff --git a/kernel/branches/net/gui/skincode.inc b/kernel/branches/net/gui/skincode.inc index 9e6ffbce96..7012f74b9e 100644 --- a/kernel/branches/net/gui/skincode.inc +++ b/kernel/branches/net/gui/skincode.inc @@ -68,10 +68,10 @@ ends struct SKIN_BUTTONS .type dd ? - .pos: + .pos: .left dw ? .top dw ? - .size: + .size: .width dw ? .height dw ? ends @@ -311,7 +311,6 @@ drawwindow_IV: ; shr esi,1 ; and esi,0x007f7f7f mov esi,[ebp+SKIN_DATA.colors.outer] - or [edi+WDATA.fl_wdrawn], 4 call draw_rectangle mov ecx,3 _dw3l: @@ -455,12 +454,6 @@ drawwindow_IV: no_skin_add_button: pop edi - and [edi+WDATA.fl_wdrawn], not 4 - test [edi+WDATA.fl_wdrawn], 2 - jz @f - call drawwindowframes2 -@@: - popa ret 4 diff --git a/kernel/branches/net/gui/window.inc b/kernel/branches/net/gui/window.inc index 793dda681a..b4dedf55fc 100644 --- a/kernel/branches/net/gui/window.inc +++ b/kernel/branches/net/gui/window.inc @@ -1,1823 +1,1846 @@ -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; ;; -;; Copyright (C) KolibriOS team 2004-2009. All rights reserved. ;; -;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa ;; -;; Distributed under terms of the GNU General Public License ;; -;; ;; -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -$Revision$ - - -get_titlebar_height: ; edi = window draw_data pointer - mov al,[edi+WDATA.fl_wstyle] - and al,0x0F - cmp al,0x03 - jne @f - mov eax,[_skinh] - ret - @@: mov eax,21 - ret - -get_rolledup_height: ; edi = window draw_data pointer - mov al,[edi+WDATA.fl_wstyle] - and al,0x0F - cmp al,0x03 - jb @f - mov eax,[_skinh] - add eax,3 - ret - @@: or al,al - jnz @f - mov eax,21 - ret - @@: mov eax,21+2 - ret - - -setwindowdefaults: - pushad - - xor eax,eax - mov ecx,WIN_STACK - @@: - inc eax - add ecx,2 - mov [ecx+0x000],ax ; process no - mov [ecx+0x400],ax ; positions in stack - cmp ecx,WIN_POS-2 ; the more high, the more surface - jnz @b - - popad - ret - - - -; eax = cx -; ebx = cy -; ecx = ex -; edx = ey -; идея: перебрать все окна, начиная с самого нижнего, -; и для попавших в заданную область -; частей окон вызвать setscreen -align 4 -calculatescreen: - pushad - pushfd - cli - - push edx ecx ebx eax - - mov esi, 1 - call setscreen - - mov ebp, [TASK_COUNT] ; number of processes - cmp ebp, 1 - jbe .finish - align 4 - .new_wnd: - movzx edi, word [WIN_POS + esi * 2] - shl edi, 5 - - cmp [CURRENT_TASK+edi+TASKDATA.state], byte 9 - je .not_wnd - - add edi, window_data - test [edi+WDATA.fl_wstate], WSTATE_MINIMIZED - jnz .not_wnd - - mov eax,[edi+WDATA.box.left] - cmp eax, [esp+RECT.right] - ja .out_of_bounds - mov ebx,[edi+WDATA.box.top] - cmp ebx, [esp+RECT.bottom] - ja .out_of_bounds - mov ecx,[edi+WDATA.box.width] - add ecx, eax - cmp ecx, [esp+RECT.left] - jb .out_of_bounds - mov edx,[edi+WDATA.box.height] - add edx, ebx - cmp edx, [esp+RECT.top] - jb .out_of_bounds - - cmp eax, [esp+RECT.left] - jae @f - mov eax, [esp+RECT.left] - @@: - cmp ebx, [esp+RECT.top] - jae @f - mov ebx, [esp+RECT.top] - @@: - cmp ecx, [esp+RECT.right] - jbe @f - mov ecx, [esp+RECT.right] - @@: - cmp edx, [esp+RECT.bottom] - jbe @f - mov edx, [esp+RECT.bottom] - @@: - - push esi - movzx esi, word [WIN_POS + esi * 2] - call setscreen - pop esi - - .not_wnd: - .out_of_bounds: - inc esi - dec ebp - jnz .new_wnd - .finish: - - pop eax ebx ecx edx - - popfd - popad -ret - - - -virtual at esp - ff_x dd ? - ff_y dd ? - ff_width dd ? - ff_xsz dd ? - ff_ysz dd ? - ff_scale dd ? -end virtual - -align 4 -; резервирует место под окно заданного процесса -setscreen: -; eax x start -; ebx y start -; ecx x end -; edx y end -; esi process number -pushad -; \begin{diamond}[29.08.2006] - cmp esi, 1 - jz @f - mov edi, esi - shl edi, 5 - cmp [edi+window_data+WDATA.box.width], 0 - jnz @f - cmp [edi+window_data+WDATA.box.height], 0 - jz .ret -@@: -; \end{diamond}[29.08.2006] - mov edi, esi ;;;word [esi*2+WIN_POS] - shl edi, 8 - add edi, SLOT_BASE ; address of random shaped window area - cmp [edi+APPDATA.wnd_shape], dword 0 - jne .free_form - - ; get x&y size - sub ecx, eax - sub edx, ebx - inc ecx - inc edx - - ; get WinMap start - mov edi, [Screen_Max_X] ; screen_sx - inc edi - imul edi, ebx - add edi, eax - add edi, WinMapAddress - - .new_y: - push ecx ; sx - push edx - - mov edx, esi - align 4 - .new_x: - mov byte [edi], dl - inc edi - dec ecx - jnz .new_x - - pop edx - pop ecx - add edi, [Screen_Max_X] - inc edi - sub edi, ecx - dec edx - jnz .new_y -.ret: - popad - ret - .read_byte: - ;eax - address - ;esi - slot - push eax - push ebx - push ecx - push edx - mov edx,eax - mov eax,esi - lea ebx,[esp+12] - mov ecx,1 - call read_process_memory - pop edx - pop ecx - pop ebx - pop eax - ret - .free_form: - - ; for (y=0; y <= x_size; y++) - ; for (x=0; x <= x_size; x++) - ; if (shape[coord(x,y,scale)]==1) - ; set_pixel(x, y, process_number); - - sub ecx, eax - sub edx, ebx - inc ecx - inc edx - - push dword [edi+APPDATA.wnd_shape_scale] ; push scale first -> for loop - - ; get WinMap start -> ebp - push eax - mov eax, [Screen_Max_X] ; screen_sx - inc eax - imul eax, ebx - add eax, [esp] - add eax, WinMapAddress - mov ebp, eax - - mov edi, [edi+APPDATA.wnd_shape] - pop eax - - ; eax = x_start - ; ebx = y_start - ; ecx = x_size - ; edx = y_size - ; esi = process_number - ; edi = &shape - ; [scale] - push edx ecx ; for loop - x,y size - - mov ecx, esi - shl ecx, 5 - mov edx, [window_data+ecx+WDATA.box.top] - push [window_data+ecx+WDATA.box.width] ; for loop - width - mov ecx, [window_data+ecx+WDATA.box.left] - sub ebx, edx - sub eax, ecx - push ebx eax ; for loop - x,y - - add [ff_xsz], eax - add [ff_ysz], ebx - - mov ebx, [ff_y] - - .ff_new_y: - mov edx, [ff_x] - - .ff_new_x: - ; -- body -- - mov ecx, [ff_scale] - mov eax, [ff_width] - inc eax - shr eax, cl - push ebx edx - shr ebx, cl - shr edx, cl - imul eax, ebx - add eax, edx - pop edx ebx - add eax, edi - call .read_byte - test al,al - jz @f - mov eax, esi - mov [ebp], al - @@: - ; -- end body -- - inc ebp - inc edx - cmp edx, [ff_xsz] - jb .ff_new_x - sub ebp, [ff_xsz] - add ebp, [ff_x] - add ebp, [Screen_Max_X] ; screen.x - inc ebp - inc ebx - cmp ebx, [ff_ysz] - jb .ff_new_y - - add esp, 24 -popad -ret - - -display_settings: - -; eax = 0 ; DISPLAY redraw -; ebx = 0 ; all -; -; eax = 1 ; BUTTON type -; ebx = 0 ; flat -; ebx = 1 ; 3D -; eax = 2 ; set WINDOW colours -; ebx = pointer to table -; ecx = number of bytes define -; eax = 3 ; get WINDOW colours -; ebx = pointer to table -; ecx = number of bytes wanted -; eax = 4 ; get skin height -; input : nothing -; output : eax = skin height in pixel -; eax = 5 ; get screen workarea -; input : nothing -; output : eax = [left]*65536+[right] -; ebx = [top]*65536+[bottom] -; eax = 6 ; set screen workarea -; input : ecx = [left]*65536+[right] -; edx = [top]*65536+[bottom] -; output : nothing -; eax = 7 ; get skin margins -; input : nothing -; output : eax = [left]*65536+[right] -; ebx = [top]*65536+[bottom] -; eax = 8 ; set window skin -; input : ecx = pointer to file info block -; output : eax = FS error code - - - pushad - - test eax, eax ; redraw display - jnz dspl0 - test ebx, ebx - jnz dspl0 - cmp [windowtypechanged],dword 1 - jne dspl00 - mov [windowtypechanged],dword 0 - redraw_screen_direct: - mov [dlx],dword 0 - mov [dly],dword 0 - mov eax,[Screen_Max_X] - mov [dlxe],eax - mov eax,[Screen_Max_Y] - mov [dlye],eax - mov eax,window_data - call redrawscreen - dspl00: - popad - ret - dspl0: - - cmp eax,1 ; button type - jne dspl1 - and ebx,1 - cmp ebx,[buttontype] - je dspl9 - mov [buttontype],ebx - mov [windowtypechanged],dword 1 - dspl9: - popad - ret - dspl1: - - cmp eax,2 ; set common window colours - jne no_com_colours - mov [windowtypechanged],dword 1 - mov esi,[TASK_BASE] - add esi,TASKDATA.mem_start - add ebx,[esi] - mov esi,ebx - mov edi,common_colours - and ecx,127 - cld - rep movsb - popad - ret - no_com_colours: - - cmp eax,3 ; get common window colours - jne no_get_com - mov esi,[TASK_BASE] - add esi,TASKDATA.mem_start - add ebx,[esi] - mov edi,ebx - mov esi,common_colours - and ecx,127 - cld - rep movsb - popad - ret - no_get_com: - - cmp eax,4 ; get skin height - jne no_skin_height - popad - mov eax,[_skinh] - mov [esp+36],eax - ret - no_skin_height: - - cmp eax,5 ; get screen workarea - jne no_get_workarea - popad - mov eax,[screen_workarea.left-2] - mov ax,word[screen_workarea.right] - mov [esp+36],eax - mov eax,[screen_workarea.top-2] - mov ax,word[screen_workarea.bottom] - mov [esp+24],eax - ret - no_get_workarea: - - cmp eax,6 ; set screen workarea - jne no_set_workarea - movsx eax,word[esp+16+2] - movsx ebx,word[esp+16] - cmp eax,ebx - jge .lp1 - or eax,eax;[Screen_Max_X] - jl @f - mov [screen_workarea.left],eax - @@: cmp ebx,[Screen_Max_X] - jg .lp1 - mov [screen_workarea.right],ebx - .lp1: movsx eax,word[esp+24+2] - movsx ebx,word[esp+24] - cmp eax,ebx - jge .lp2 - or eax,eax;[0xFE04] - jl @f - mov [screen_workarea.top],eax - @@: cmp ebx,[Screen_Max_Y] - jg .lp2 - mov [screen_workarea.bottom],ebx - .lp2: call repos_windows - mov eax, 0 - mov ebx, 0 - mov ecx, [Screen_Max_X] - mov edx, [Screen_Max_Y] - call calculatescreen -; jmp redraw_screen_direct - .exit: - popad - ret - no_set_workarea: - - cmp eax,7 ; get skin margins - jne no_get_skinmargins - popad - mov eax,dword[_skinmargins+0] - mov [esp+36],eax - mov eax,dword[_skinmargins+4] - mov [esp+24],eax - ret - no_get_skinmargins: - - cmp eax,8 ; set window skin - jne no_set_skin - call read_skin_file - mov [esp+32+36], eax - test eax, eax - jnz .ret - xor eax, eax - xor ebx, ebx - mov ecx, [Screen_Max_X] - mov edx, [Screen_Max_Y] - call calculatescreen - jmp redraw_screen_direct -.ret: - popad - ret - no_set_skin: - - popad - ret - - -repos_windows: - mov ecx,[TASK_COUNT] - mov edi, OS_BASE+0x20*2 - call force_redraw_background - dec ecx - jge @f - ret - @@: mov [edi+WDATA.fl_redraw],1 - test [edi+WDATA.fl_wstate],WSTATE_MAXIMIZED - jz .lp2 - mov eax,[screen_workarea.left] - mov [edi+WDATA.box.left],eax - sub eax,[screen_workarea.right] - neg eax - mov [edi+WDATA.box.width],eax - mov eax,[screen_workarea.top] - mov [edi+WDATA.box.top],eax - test [edi+WDATA.fl_wstate],WSTATE_ROLLEDUP - jnz .lp1 - sub eax,[screen_workarea.bottom] - neg eax - mov [edi+WDATA.box.height],eax - .lp1: - - call set_window_clientbox - add edi,0x20 - loop @b - ret - .lp2: mov eax,[edi+WDATA.box.left] - add eax,[edi+WDATA.box.width] - mov ebx,[Screen_Max_X] -; inc ebx - cmp eax,ebx - jle .lp4 - mov eax,[edi+WDATA.box.width] - sub eax,ebx - jle .lp3 - mov [edi+WDATA.box.width],ebx - .lp3: sub ebx,[edi+WDATA.box.width] - mov [edi+WDATA.box.left],ebx - .lp4: mov eax,[edi+WDATA.box.top] - add eax,[edi+WDATA.box.height] - mov ebx,[Screen_Max_Y] -; inc ebx - cmp eax,ebx - jle .lp6 - mov eax,[edi+WDATA.box.height] - sub eax,ebx - jle .lp5 - mov [edi+WDATA.box.height],ebx - .lp5: sub ebx,[edi+WDATA.box.height] - mov [edi+WDATA.box.top],ebx - .lp6: jmp .lp1 - -uglobal - common_colours: - times 128 db 0x0 -endg - - - - -check_window_position: - - pushad ; window inside screen ? - - mov eax, [edi+WDATA.box.left] - mov ebx, [edi+WDATA.box.top] - mov ecx, [edi+WDATA.box.width] - mov edx, [edi+WDATA.box.height] - - cmp ecx,[Screen_Max_X] ; check x size - jbe x_size_ok - mov ecx,[Screen_Max_X] - mov [edi+WDATA.box.width],ecx - - x_size_ok: - - cmp edx,[Screen_Max_Y] ; check y size - jbe y_size_ok - mov edx,[Screen_Max_Y] - mov [edi+WDATA.box.height],edx - - y_size_ok: - - cmp eax,0 ; check x pos - jnle @f - xor eax,eax - mov [edi+WDATA.box.left],eax - jmp x_pos_ok - @@: - add eax,ecx - cmp eax,[Screen_Max_X] - jbe x_pos_ok - mov eax,[Screen_Max_X] - sub eax,ecx - mov [edi+WDATA.box.left],eax - - x_pos_ok: - - cmp ebx,0 ; check x pos - jnle @f - xor ebx,ebx - mov [edi+WDATA.box.top],ebx - jmp y_pos_ok - @@: - add ebx,edx - cmp ebx,[Screen_Max_Y] - jbe y_pos_ok - mov ebx,[Screen_Max_Y] - sub ebx,edx - mov [edi+WDATA.box.top],ebx - - y_pos_ok: - - popad - - ret - - -uglobal - new_window_starting dd 0 -endg - - -sys_window_mouse: - - push eax - - mov eax,[timer_ticks] - cmp [new_window_starting],eax - jb swml1 - - mov [MOUSE_BACKGROUND],byte 0 ; no mouse background - mov [DONT_DRAW_MOUSE],byte 0 ; draw mouse - - mov [new_window_starting],eax - - swml1: - - pop eax - - ret - - - - -drawwindow_I_caption: - - mov ecx,[edx+WDATA.cl_titlebar] ; grab bar - push ecx - mov esi,edx - mov edx,[esi+WDATA.box.top] - add edx,1 - mov ebx,[esi+WDATA.box.top] - add ebx,21 - mov eax,[esi+WDATA.box.top] - add eax,[esi+WDATA.box.height] - cmp ebx,eax - jb .wdsizeok - mov ebx,eax - .wdsizeok: - push ebx - .drwi: - mov ebx,edx - shl ebx,16 - add ebx,edx - mov eax,[esi+WDATA.box.left] - inc eax - shl eax,16 - add eax,[esi+WDATA.box.left] - add eax,[esi+WDATA.box.width] - sub eax,1 - push edx - mov edx,0x80000000 - mov ecx,[esi+WDATA.cl_titlebar] - and ecx,edx - cmp ecx,edx - jnz .nofa - mov ecx,[esi+WDATA.cl_titlebar] - sub ecx,0x00040404 - mov [esi+WDATA.cl_titlebar],ecx - and ecx,0x00ffffff - jmp .faj - .nofa: - mov ecx,[esi+WDATA.cl_titlebar] - and ecx,0x00ffffff - .faj: - pop edx - mov edi,0 - call [draw_line] - inc edx - cmp edx,[esp] - jb .drwi - add esp,4 - pop ecx - mov [esi+WDATA.cl_titlebar],ecx - - ret - - -drawwindow_I: - - pushad - or [edx+WDATA.fl_wdrawn], 4 - - mov esi,[edx+WDATA.cl_frames] ; rectangle - mov eax,[edx+WDATA.box.left] - shl eax,16 - add eax,[edx+WDATA.box.left] - add eax,[edx+WDATA.box.width] - mov ebx,[edx+WDATA.box.top] - shl ebx,16 - add ebx,[edx+WDATA.box.top] - add ebx,[edx+WDATA.box.height] - call draw_rectangle - - and [edx+WDATA.fl_wdrawn], not 4 - test [edx+WDATA.fl_wdrawn], 2 - jz @f - call drawwindowframes2 -@@: - - call drawwindow_I_caption - - mov edx,[esi+WDATA.box.top] ; inside work area - add edx,21+5 - mov ebx,[esi+WDATA.box.top] - add ebx,[esi+WDATA.box.height] - cmp edx,ebx - jg noinside - mov eax,1 - mov ebx,21 - mov ecx,[esi+WDATA.box.width] - mov edx,[esi+WDATA.box.height] - mov edi,[esi+WDATA.cl_workarea] - test edi,0x40000000 - jnz noinside - call [drawbar] - noinside: - - popad - - ret - - -draw_rectangle: - -r_eax equ [esp+28] ; x start -r_ax equ [esp+30] ; x end -r_ebx equ [esp+16] ; y start -r_bx equ [esp+18] ; y end -;esi ; color - - pushad - - mov ecx,esi ; yb,xb -> yb,xe - mov eax, r_eax - rol eax, 16 - mov ebx,r_ebx - shl ebx,16 - mov bx,r_ebx - xor edi, edi - call [draw_line] - - mov ebx,r_bx ; ye,xb -> ye,xe - shl ebx,16 - mov bx,r_bx - call [draw_line] - - mov ecx,esi ; ya,xa -> ye,xa - mov eax,r_eax - shl eax,16 - mov ax,r_eax - mov ebx,r_ebx - shl ebx,16 - mov bx,r_bx - mov edi,0 - call [draw_line] - - mov eax,r_ax ; ya,xe -> ye,xe - shl eax,16 - mov ax,r_ax - call [draw_line] - - popad - ret - - -drawwindow_III_caption: - - mov ecx,[edx+WDATA.cl_titlebar] ; GRAB BAR - push ecx - mov esi,edx - mov edx,[esi+WDATA.box.top] - add edx,4 - mov ebx,[esi+WDATA.box.top] - add ebx,20 - mov eax,[esi+WDATA.box.top] - add eax,[esi+WDATA.box.height] - cmp ebx,eax - jb .wdsizeok - mov ebx,eax - .wdsizeok: - push ebx - .drwi: - mov ebx,edx - shl ebx,16 - add ebx,edx - mov eax,[esi+WDATA.box.left] - shl eax,16 - add eax,[esi+WDATA.box.left] - add eax,[esi+WDATA.box.width] - add eax,4*65536-4 - mov ecx,[esi+WDATA.cl_titlebar] - test ecx,0x40000000 - jz .nofa - add ecx,0x040404 - .nofa: - test ecx,0x80000000 - jz .nofa2 - sub ecx,0x040404 - .nofa2: - mov [esi+WDATA.cl_titlebar],ecx - and ecx,0xffffff - xor edi, edi - call [draw_line] - inc edx - cmp edx,[esp] - jb .drwi - add esp,4 - pop ecx - mov [esi+WDATA.cl_titlebar],ecx - - ret - - -drawwindow_III: - - pushad - - mov edi,edx ; RECTANGLE - mov eax,[edi+WDATA.box.left] - shl eax,16 - mov ax, word [edi+WDATA.box.left] - add ax, word [edi+WDATA.box.width] - mov ebx,[edi+WDATA.box.top] - shl ebx,16 - mov bx, word [edi+WDATA.box.top] - add bx, word [edi+WDATA.box.height] - mov esi,[edi+WDATA.cl_frames] - shr esi,1 - and esi,0x007f7f7f - push esi - or [edi+WDATA.fl_wdrawn], 4 - call draw_rectangle - and [edi+WDATA.fl_wdrawn], not 4 - test [edi+WDATA.fl_wdrawn], 2 - jz @f - call drawwindowframes2 -@@: - mov ecx,3 - dw3l: - add eax,1*65536-1 - add ebx,1*65536-1 - mov esi,[edi+WDATA.cl_frames] - call draw_rectangle - dec ecx - jnz dw3l - pop esi - add eax,1*65536-1 - add ebx,1*65536-1 - call draw_rectangle - - call drawwindow_III_caption - - mov edx,[esi+WDATA.box.top] ; WORK AREA - add edx,21+5 - mov ebx,[esi+WDATA.box.top] - add ebx,[esi+WDATA.box.height] - cmp edx,ebx - jg noinside2 - mov eax,5 - mov ebx,20 - mov ecx,[esi+WDATA.box.width] - mov edx,[esi+WDATA.box.height] - sub ecx,4 - sub edx,4 - mov edi,[esi+WDATA.cl_workarea] - test edi,0x40000000 - jnz noinside2 - call [drawbar] - noinside2: - - popad - - ret - - - -; activate window -align 4 -windowactivate: - - ; esi = abs mem position in stack 0xC400+ - - pushad - - ; if type of current active window is 3, - ; it must be redrawn - mov eax, [TASK_COUNT] - movzx eax, word [WIN_POS + eax*2] - shl eax, 5 - add eax, window_data - mov ebx, [eax + WDATA.cl_workarea] - and ebx, 0x0f000000 - cmp ebx, 0x03000000 - je .set_WDATA_fl_redraw ; for 3 and 4 style - cmp ebx, 0x04000000 - je .set_WDATA_fl_redraw - jmp @f - .set_WDATA_fl_redraw: - mov [eax + WDATA.fl_redraw], byte 1 - @@: - - push esi - movzx eax, word [esi] ; ax <- process no - movzx eax, word [WIN_STACK+eax*2] ; ax <- position in window stack - - xor esi, esi ; drop others - waloop: - cmp esi, dword [TASK_COUNT] - jae wacont - inc esi - lea edi, [WIN_STACK + esi*2] - mov bx, [edi] ; position of the current process - cmp bx, ax - jbe @f - dec bx ; upper? => drop! - mov [edi], bx - @@: - jmp waloop - wacont: - ; set to no 1 - pop esi ; esi = pointer at 0xC400 - - movzx eax, word [esi] - mov bx, [TASK_COUNT] ; number of processes - mov [WIN_STACK+eax*2], bx ; this is the last (and the upper) - - ; update on screen -window stack - xor esi, esi - waloop2: - mov edi, [TASK_COUNT] - cmp esi, edi - jae wacont2 - inc esi - movzx ebx, word [esi*2 + WIN_STACK] - mov [ebx*2 + WIN_POS], si - jmp waloop2 - wacont2: - mov [KEY_COUNT], byte 0 ; empty keyboard buffer - mov [BTN_COUNT], byte 0 ; empty button buffer - mov [MOUSE_SCROLL_H], word 0 ; zero mouse z-index - mov [MOUSE_SCROLL_V], word 0 ; zero mouse z-index - popad - ret - - -; check if window is necessary to draw - -checkwindowdraw: - - ; edi = position in window_data+ - - mov eax, [edi + WDATA.cl_workarea] - and eax, 0x0f000000 - cmp eax, 0x03000000 - je .return_yes ; window type 3 - cmp eax, 0x04000000 - je .return_yes ; window type 4 - - mov esi, edi - sub esi, window_data - shr esi, 5 - - ; esi = process number - - movzx eax, word [WIN_STACK + esi * 2] ; get value of the curr process - lea esi, [WIN_POS + eax * 2] ; get address of this process at 0xC400 - - push esi - - .new_check: - - pop esi - add esi, 2 - push esi - - mov eax, [TASK_COUNT] - lea eax, word [WIN_POS + eax * 2] ; number of the upper window - - cmp esi, eax - ja .all_wnds_to_top - - movzx eax, word [esi] - shl eax, 5 - cmp [CURRENT_TASK + eax + TASKDATA.state], byte 9 - je .new_check ; skip dead windows - - lea esi, [eax+window_data] - - mov ebx, [edi+WDATA.box.top] ; y0 - mov edx, [edi+WDATA.box.height] - add edx, ebx ; y0e - - mov ecx, [esi+WDATA.box.top] ; y ; y check - cmp ecx, edx - jae .new_check ; y < y0e - mov eax, [esi+WDATA.box.height] - add ecx, eax ; ye - cmp ebx, ecx ; y0 >= ye - ja .new_check - - mov eax, [edi+WDATA.box.left] ; x0 - mov ecx, [edi+WDATA.box.width] - add ecx, eax ; x0e - - mov edx, [esi+WDATA.box.left] ; x ; x check - cmp edx, ecx - jae .new_check ; x < x0e - mov ecx, [esi+WDATA.box.width] - add edx, ecx - cmp eax, edx - ja .new_check - - pop esi - .return_yes: - mov ecx,1 ; overlap some window - ret - - .all_wnds_to_top: - - pop esi - - xor ecx, ecx ; passed all windows to top - ret - - - - -waredraw: ; if redraw necessary at activate - - pushad - - call checkwindowdraw ; draw window on activation ? - test ecx, ecx - jz .do_not_draw - - popad - mov [MOUSE_DOWN], byte 1 ; do draw mouse - call windowactivate - - ; update screen info - pushad - mov edi, [TASK_COUNT] ; the last process (number) - movzx esi, word [WIN_POS + edi * 2] - shl esi, 5 - add esi, window_data - - ; coordinates of the upper window - mov eax, [esi + WDATA.box.left] ; cx - mov ebx, [esi + WDATA.box.top] ; cy - mov ecx, [esi + WDATA.box.width] ; sx - mov edx, [esi + WDATA.box.height] ; sy - - add ecx, eax ; ecx = x_end - add edx, ebx ; edx = y_end - - mov edi, [TASK_COUNT] - movzx esi, word [WIN_POS + edi * 2] - call setscreen - popad - - mov [edi + WDATA.fl_redraw], 1 ; redraw flag for app - mov [MOUSE_DOWN],byte 0 ; mouse down checks - - ret - - .do_not_draw: - - popad - - call windowactivate - mov [MOUSE_DOWN],byte 0 ; mouse down checks - mov [MOUSE_BACKGROUND],byte 0 ; no mouse background - mov [DONT_DRAW_MOUSE],byte 0 ; draw mouse - ret - - -; eax = window number on screen -; corrupts registers and [dl*] -minimize_window: - movzx eax, word [WIN_POS+eax*2] - shl eax, 5 - add eax, window_data - test [eax+WDATA.fl_wstate], WSTATE_MINIMIZED - jnz .skip_redrawings - pushfd - cli - or [eax+WDATA.fl_wstate], WSTATE_MINIMIZED - mov edi, eax - ;call calculatescreen - mov eax, [edi+WDATA.box.left] - mov [dlx], eax - mov ecx, eax - add ecx, [edi+WDATA.box.width] - mov [dlxe], ecx - mov ebx, [edi+WDATA.box.top] - mov [dly], ebx - mov edx, ebx - add edx, [edi+WDATA.box.height] - mov [dlye], edx - call calculatescreen - xor esi, esi - xor eax, eax - call redrawscreen - popfd -.skip_redrawings: - ret - -; eax = window number on screen -; corrupts registers and [dl*] -restore_minimized_window: - pushfd - cli - movzx esi, word [WIN_POS+eax*2] - mov edi, esi - shl edi, 5 - add edi, window_data - test [edi+WDATA.fl_wstate], WSTATE_MINIMIZED - jz .skip_redrawings - mov [edi+WDATA.fl_redraw], 1 - and [edi+WDATA.fl_wstate], not WSTATE_MINIMIZED - cmp eax, [TASK_COUNT] ; the uppermost window - jnz .no_uppermost - mov eax, [edi+WDATA.box.left] - mov ebx, [edi+WDATA.box.top] - mov ecx, eax - mov edx, ebx - add ecx, [edi+WDATA.box.width] - add edx, [edi+WDATA.box.height] - call setscreen - jmp .done -.no_uppermost: - mov eax, [edi+WDATA.box.left] - mov ebx, [edi+WDATA.box.top] - mov ecx, eax - mov edx, ebx - add ecx, [edi+WDATA.box.width] - add edx, [edi+WDATA.box.height] - call calculatescreen -.done: - mov [MOUSE_BACKGROUND],byte 0 ; no mouse under -.skip_redrawings: - popfd - ret - - -;iglobal -; window_moving db 'K : Window - move/resize',13,10,0 -; window_moved db 'K : Window - done',13,10,0 -;endg - -; check window touch -align 4 -checkwindows: - pushad - - cmp [window_minimize], 0 - je .no_minimizing - mov eax, [TASK_COUNT] ; the uppermost window - mov bl, 0 - xchg [window_minimize], bl - cmp bl, 1 - jne .restore - call minimize_window - jmp .continue - .restore: - call restore_minimized_window - .continue: - .no_minimizing: - - cmp [BTN_DOWN],byte 0 ; mouse buttons pressed ? - jne .mouse_buttons_pressed -;..................................... start 1/4 : modified by vhanla ................. - mov [bPressedMouseXY_W],0 -;..................................... end 1/4 : modified by vhanla ................... - popad - ret - .mouse_buttons_pressed: -;..................................... start 2/4 : modified by vhanla ................. -uglobal - bPressedMouseXY_W db 0x0 -endg -;..................................... end 2/4 : modified by vhanla ................... - mov esi,[TASK_COUNT] - inc esi - -;..................................... start 3/4 : modified by vhanla ................. - cmp [bPressedMouseXY_W],1 - ja @f - inc [bPressedMouseXY_W] - jnc @f - ;mov ax,[MOUSE_X] - ;mov [mx],ax - ;mov ax,[MOUSE_Y] - ;mov [my],ax - mov eax,dword[MOUSE_X] - mov dword[mx],eax - @@: -;..................................... end 3/4 : modified by vhanla ................... - - cwloop: - cmp esi,2 - jb .exit - - dec esi - movzx edi, word [WIN_POS + esi * 2] ; ebx - shl edi, 5 - add edi, window_data -; mov edi, ebx - mov ecx, [edi + WDATA.box.left] - mov edx, [edi + WDATA.box.top] - - mov eax,ecx - mov ebx,edx - test [edi+WDATA.fl_wstate],WSTATE_MINIMIZED - jnz cwloop - -;..................................... start 4/4 : modified by vhanla ................. - movzx eax, word [mx]; movzx eax,word[MOUSE_X] - movzx ebx, word [my]; movzx ebx,word[MOUSE_Y] -;..................................... endt 4/4 : modified by vhanla .................. - cmp ecx, eax - jae cwloop - cmp edx, ebx - jae cwloop - add ecx, [edi + WDATA.box.width] - add edx, [edi + WDATA.box.height] - cmp eax, ecx - jae cwloop - cmp ebx, edx - jae cwloop - - pushad - mov eax, esi - mov ebx, [TASK_COUNT] - cmp eax, ebx ; is this window active? - jz .move_resize_window - - cmp [bPressedMouseXY_W], 1 - ja .exit_popa - - ; eax = position in windowing stack - ; redraw must ? - lea esi, [WIN_POS + esi * 2] - call waredraw - .exit_popa: - add esp, 32 - - .exit: - popad - ret - - .move_resize_window: ; MOVE OR RESIZE WINDOW - popad - - ; Check for user enabled fixed window - mov edx, [edi + WDATA.cl_titlebar] - and edx, 0x0f000000 - cmp edx, 0x01000000 - jne .window_move_enabled_for_user - popad - ret - .window_move_enabled_for_user: - - test [edi+WDATA.fl_wstate],WSTATE_ROLLEDUP - jnz .no_resize_2 - - mov [do_resize_from_corner],byte 0 ; resize for skinned window - mov edx, [edi + WDATA.cl_workarea] - and edx, 0x0f000000 - cmp edx, 0x00000000 ;{test for resized} - je .no_resize_2 - cmp edx, 0x01000000 ;{test for resized} - je .no_resize_2 - cmp edx, 0x04000000 ;{test for resized} - je .no_resize_2 -; jb .no_resize_2 ; not type 2 wnd - - mov edx, [edi + WDATA.box.top] - add edx, [edi + WDATA.box.height] - sub edx, 6 ; edx = y_end - 6 - cmp ebx, edx ; ebx = mouse_y - jb .no_resize_2 - mov [do_resize_from_corner],byte 1 - jmp .continue - .no_resize_2: - - push eax - call get_titlebar_height - add eax,[edi + WDATA.box.top] - cmp ebx,eax - pop eax - jae .exit - - .continue: - -; push esi -; mov esi, window_moving -; call sys_msg_board_str -; pop esi - - mov ecx, [timer_ticks] ; double-click ? - mov edx, ecx - sub edx, [latest_window_touch] - mov [latest_window_touch], ecx - mov [latest_window_touch_delta], edx - - mov cl, [BTN_DOWN] ; save for shade check - mov [do_resize], cl - no_emulation_righ_button: - mov ecx, [edi + WDATA.box.left] - mov edx, [edi + WDATA.box.top] - - push eax ecx edx - mov [dlx], ecx ; save for drawlimits - mov [dly], edx - mov eax, [edi + WDATA.box.width] - add ecx, eax - mov eax, [edi + WDATA.box.height] - add edx, eax - mov [dlxe], ecx - mov [dlye], edx - pop edx ecx eax - - sub eax, ecx - sub ebx, edx - - mov esi, [MOUSE_X] - mov [WIN_TEMP_XY], esi - - pushad ; wait for putimages to finish -; mov ebx,5 -; call delay_hs - mov eax,[edi + WDATA.box.left] - mov [npx],eax - mov eax,[edi + WDATA.box.top] - mov [npy],eax - popad - - push eax ; save old coordinates - mov ax, word [edi + WDATA.box.left] - mov word [oldc+BOX.left],ax - mov ax, word [edi + WDATA.box.top] - mov word [oldc+BOX.top],ax - mov ax, word [edi + WDATA.box.width] - mov word [oldc+BOX.width],ax - mov word [npxe],ax - mov ax, word [edi + WDATA.box.height] - mov word [oldc+BOX.height],ax - mov word [npye],ax - pop eax - - call drawwindowframes - - mov [reposition],0 - mov [MOUSE_DOWN],byte 1 ; no reaction to mouse up/down - - ; move window - - newchm: - - mov [DONT_DRAW_MOUSE],byte 1 - - call checkidle - - call checkVga_N13 - - mov [MOUSE_BACKGROUND],byte 0 - - call [draw_pointer] - - pushad - call stack_handler - popad - - mov esi,[WIN_TEMP_XY] - cmp esi,[MOUSE_X] - je cwb - - mov cx,[MOUSE_X] - mov dx,[MOUSE_Y] - sub cx,ax - sub dx,bx - - push ax - push bx - - call drawwindowframes - - mov ax,[Screen_Max_X] - mov bx,[Screen_Max_Y] - - cmp [do_resize_from_corner],1 - je no_new_position - - mov word [npx],word 0 ; x repos ? - cmp ax,cx - jb noreposx - mov [reposition],1 - sub ax,word [npxe] - mov word [npx],ax - cmp ax,cx - jb noreposx - mov word [npx],cx - noreposx: - - mov word [npy],word 0 ; y repos ? - cmp bx,dx - jb noreposy - mov [reposition],1 - sub bx,word [npye] - mov word [npy],bx - cmp bx,dx - jb noreposy - mov word [npy],dx - noreposy: - - no_new_position: - - cmp [do_resize_from_corner],0 ; resize from right corner - je norepos_size - pushad - - mov edx,edi - sub edx,window_data - ;shr edx,5 - ;shl edx,8 - ;add edx,0x80000 ; process base at 0x80000+ - lea edx, [SLOT_BASE + edx*8] - - movzx eax,word [MOUSE_X] - cmp eax,[edi + WDATA.box.left] - jb nnepx - sub eax,[edi + WDATA.box.left] - cmp eax,32 ; [edx+0x90+8] - jge nnepx2 - mov eax,32 ; [edx+0x90+8] - nnepx2: - mov [npxe],eax - nnepx: - - call get_rolledup_height - mov ebx,eax - movzx eax,word [MOUSE_Y] - cmp eax,[edi + WDATA.box.top] - jb nnepy - sub eax,[edi + WDATA.box.top] - cmp eax,ebx ; [edx+0x90+12] - jge nnepy2 - mov eax,ebx ; [edx+0x90+12] - nnepy2: - mov [npye],eax - nnepy: - - mov [reposition],1 - - popad - norepos_size: - - pop bx - pop ax - call drawwindowframes - - mov esi,[MOUSE_X] - mov [WIN_TEMP_XY],esi - - cwb: - cmp [BTN_DOWN],byte 0 - jne newchm - ; new position done - mov [DONT_DRAW_MOUSE],byte 1 - mov cl,0 - test [edi+WDATA.fl_wstate],WSTATE_MAXIMIZED - jnz @f - mov cl,[reposition] - call drawwindowframes - - mov eax,[npx] - mov [edi + WDATA.box.left],eax - mov eax,[npy] - mov [edi + WDATA.box.top],eax - mov eax,[npxe] - mov [edi + WDATA.box.width],eax - mov eax,[npye] - mov [edi + WDATA.box.height],eax - call set_window_clientbox - - @@: mov [reposition],cl - - cmp [reposition],1 ; save new position and size - jne no_bounds_save - push esi edi ecx - mov esi,edi - mov ecx,2 - test [edi+WDATA.fl_wstate],WSTATE_ROLLEDUP or WSTATE_MAXIMIZED - jnz @f - add ecx,2 - @@: sub edi,window_data - shr edi,5 - shl edi,8 - add edi,SLOT_BASE+APPDATA.saved_box - cld - rep movsd - pop ecx edi esi - no_bounds_save: - - pushad ; WINDOW SHADE/FULLSCREEN - - ;{doule click not worked for 4 type window} - mov edx, [edi + WDATA.cl_workarea] - and edx, 0x0f000000 - cmp edx, 0x00000000 - je no_fullscreen_restore - cmp edx, 0x01000000 - je no_fullscreen_restore - - cmp [reposition],1 - je no_window_sizing - mov edx,edi - sub edx,window_data - shr edx,5 - shl edx,8 - add edx,SLOT_BASE ; process base at 0x80000+ - - cmp [do_resize],2 ; window shade ? - jne no_window_shade - mov [reposition],1 - - test [edi+WDATA.fl_wstate],WSTATE_ROLLEDUP - jnz wnd_rolldown - wnd_rollup: - or [edi+WDATA.fl_wstate],WSTATE_ROLLEDUP - call get_rolledup_height - jmp @f - wnd_rolldown: - and [edi+WDATA.fl_wstate],not WSTATE_ROLLEDUP - mov eax,[edx + APPDATA.saved_box.height] ; 0x90+BOX.height - test [edi+WDATA.fl_wstate],WSTATE_MAXIMIZED - jz @f - mov eax,[screen_workarea.bottom] - sub eax,[screen_workarea.top] - @@: mov [edi+WDATA.box.height],eax - add eax, [edi+WDATA.box.top] - cmp eax, [Screen_Max_Y] - jbe @f - mov eax, [Screen_Max_Y] - sub eax, [edi+WDATA.box.height] - mov [edi+WDATA.box.top], eax - @@: call check_window_position - call set_window_clientbox - - no_window_shade: - - push edx - mov edx, [edi + WDATA.cl_workarea] - and edx, 0x0f000000 - cmp edx, 0x04000000 - pop edx - je no_fullscreen_restore - - cmp [do_resize],1 ; fullscreen/restore ? - jne no_fullscreen_restore - cmp [latest_window_touch_delta],dword 50 - jg no_fullscreen_restore - mov [reposition],1 - test [edi+WDATA.fl_wstate],WSTATE_MAXIMIZED - jnz restore_from_fullscreen - or [edi+WDATA.fl_wstate],WSTATE_MAXIMIZED - mov eax,[screen_workarea.left] - mov [edi+WDATA.box.left],eax - sub eax,[screen_workarea.right] - neg eax - mov [edi+WDATA.box.width],eax - mov eax,[screen_workarea.top] - mov [edi+WDATA.box.top],eax - test [edi+WDATA.fl_wstate],WSTATE_ROLLEDUP - jnz @f - sub eax,[screen_workarea.bottom] - neg eax - mov [edi+WDATA.box.height],eax - @@: - jmp restore_from_fullscreen.clientbox - restore_from_fullscreen: - and [edi+WDATA.fl_wstate],not WSTATE_MAXIMIZED - push [edi+WDATA.box.height] - push edi ; restore - lea esi, [edx + APPDATA.saved_box] - mov ecx,4 - cld - rep movsd - pop edi - pop eax - test [edi+WDATA.fl_wstate],WSTATE_ROLLEDUP - jz @f - mov [edi+WDATA.box.height],eax - @@: - .clientbox: - call set_window_clientbox - - no_fullscreen_restore: - - mov eax,[edi+WDATA.box.top] ; check Y inside screen - add eax,[edi+WDATA.box.height] - cmp eax,[Screen_Max_Y] - jbe no_window_sizing - mov eax,[edi+WDATA.box.left] ; check X inside screen - add eax,[edi+WDATA.box.width] - cmp eax,[Screen_Max_X] - jbe no_window_sizing - mov eax,[Screen_Max_X] - sub eax,[edi+WDATA.box.width] - mov [edi+WDATA.box.left],eax - mov eax,[Screen_Max_Y] - sub eax,[edi+WDATA.box.height] - mov [edi+WDATA.box.top],eax - call set_window_clientbox - no_window_sizing: - - popad - - cmp [reposition],0 - je retwm - - mov [DONT_DRAW_MOUSE],byte 1 ; no mouse - - - push eax ebx ecx edx - mov eax,[edi+WDATA.box.left] - mov ebx,[edi+WDATA.box.top] - mov ecx,[edi+WDATA.box.width] - mov edx,[edi+WDATA.box.height] - add ecx,eax - add edx,ebx - call calculatescreen - - mov eax,[oldc+BOX.left] - mov ebx,[oldc+BOX.top] - mov ecx,[oldc+BOX.width] - mov edx,[oldc+BOX.height] - add ecx,eax - add edx,ebx - call calculatescreen - pop edx ecx ebx eax - - mov eax,edi - call redrawscreen - - - mov [edi+WDATA.fl_redraw],1 - - mov ecx,100 ; wait to avoid mouse residuals - waitre2: - mov [DONT_DRAW_MOUSE],byte 1 - call checkidle - cmp [edi+WDATA.fl_redraw],0 - jz retwm - loop waitre2 - - retwm: - - mov [DONT_DRAW_MOUSE],byte 0 ; mouse pointer - mov [MOUSE_BACKGROUND],byte 0 ; no mouse under - mov [MOUSE_DOWN],byte 0 ; react to mouse up/down - -; mov esi,window_moved -; call sys_msg_board_str - - popad - - ret - - -uglobal - add_window_data dd 0 - do_resize_from_corner db 0x0 - reposition db 0x0 - latest_window_touch dd 0x0 - latest_window_touch_delta dd 0x0 - - do_resize db 0x0 - - oldc dd 0x0,0x0,0x0,0x0 - - dlx dd 0x0 - dly dd 0x0 - dlxe dd 0x0 - dlye dd 0x0 - - npx dd 0x0 - npy dd 0x0 - npxe dd 0x0 - npye dd 0x0 - - mpx dd 0x0 - mpy dd 0x0 -endg - - -; draw negative window frames -drawwindowframes2: - pushad - cli - jmp drawwindowframes.do -drawwindowframes: - pushad - cli - - test [edi+WDATA.fl_wstate],WSTATE_MAXIMIZED - jnz .ret - mov eax, [npx] - cmp eax, [edi+WDATA.box.left] - jnz .nowndframe - mov eax, [npxe] - cmp eax, [edi+WDATA.box.width] - jnz .nowndframe - mov eax, [npy] - cmp eax, [edi+WDATA.box.top] - jnz .nowndframe - mov eax, [npye] - cmp eax, [edi+WDATA.box.height] - jnz .nowndframe - xor [edi+WDATA.fl_wdrawn], 2 - test [edi+WDATA.fl_wdrawn], 4 - jnz .ret - -.nowndframe: -.do: - mov edi, 1 - mov ecx, 0x01000000 - mov eax,[npx] - shl eax,16 - add eax,[npx] - add eax,[npxe] - add eax,65536*1-1 - mov ebx,[npy] - shl ebx,16 - add ebx,[npy] - call [draw_line] - - mov eax,[npx] - shl eax,16 - add eax,[npx] - add eax,[npxe] - add eax,65536*1-1 - mov ebx,[npy] - add ebx,[npye] - shl ebx,16 - add ebx,[npy] - add ebx,[npye] - call [draw_line] - - mov eax,[npx] - shl eax,16 - add eax,[npx] - mov ebx,[npy] - shl ebx,16 - add ebx,[npy] - add ebx,[npye] - call [draw_line] - - mov eax,[npx] - add eax,[npxe] - shl eax,16 - add eax,[npx] - add eax,[npxe] - mov ebx,[npy] - shl ebx,16 - add ebx,[npy] - add ebx,[npye] - call [draw_line] - -.ret: - sti - popad - ret - - - -random_shaped_window: - -; -; eax = 0 giving address of data area -; ebx address -; eax = 1 shape area scale -; ebx 2^ebx scale - - test eax, eax - jne rsw_no_address - mov eax,[current_slot] - mov [eax+APPDATA.wnd_shape],ebx -rsw_no_address: - - cmp eax,1 - jne rsw_no_scale - mov eax,[current_slot] - mov byte [eax+APPDATA.wnd_shape_scale], bl -rsw_no_scale: - - ret - - +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; ;; +;; Copyright (C) KolibriOS team 2004-2009. All rights reserved. ;; +;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa ;; +;; Distributed under terms of the GNU General Public License ;; +;; ;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +$Revision$ + + +;============================================================================== +;///// public functions /////////////////////////////////////////////////////// +;============================================================================== + +macro FuncTable name, [label] +{ + common + align 4 + \label name#.ftable dword + forward + dd name#.#label + common + name#.sizeof.ftable = $ - name#.ftable +} + +iglobal + FuncTable syscall_display_settings, \ + 00, 01, 02, 03, 04, 05, 06, 07, 08 +endg + +uglobal + common_colours rd 32 + new_window_starting dd ? + latest_window_touch dd ? + latest_window_touch_delta dd ? + old_window_pos BOX + new_window_pos BOX + draw_limits RECT + bPressedMouseXY_W db ? + do_resize db ? + do_resize_from_corner db ? + reposition db ? +endg + +align 4 +;------------------------------------------------------------------------------ +syscall_display_settings: ;///// system function 48 /////////////////////////// +;------------------------------------------------------------------------------ +;; Redraw screen: +;< ebx = 0 +; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +;; Set button style: +;< ebx = 1 +;< ecx = 0 (flat) or 1 (with gradient) +; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +;; Set system color palette: +;< ebx = 2 +;< ecx = pointer to color table +;< edx = size of color table +; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +;; Get system color palette: +;< ebx = 3 +;< ecx = pointer to color table buffer +;< edx = size of color table buffer +; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +;; Get skinned caption height: +;< ebx = 4 +;> eax = height in pixels +; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +;; Get screen working area: +;< ebx = 5 +;> eax = pack[16(left), 16(right)] +;> ebx = pack[16(top), 16(bottom)] +; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +;; Set screen working area: +;< ebx = 6 +;< ecx = pack[16(left), 16(right)] +;< edx = pack[16(top), 16(bottom)] +; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +;; Get skin margins: +;< ebx = 7 +;> eax = pack[16(left), 16(right)] +;> ebx = pack[16(top), 16(bottom)] +; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +;; Set skin: +;< ebx = 8 +;< ecx = pointer to FileInfoBlock struct +;> eax = FS error code +;------------------------------------------------------------------------------ + cmp ebx, .sizeof.ftable / 4 + ja @f + jmp [.ftable + ebx * 4] + @@: ret + + +align 4 +syscall_display_settings.00: + xor eax, eax + inc ebx + cmp [windowtypechanged], ebx + jne .exit + mov [windowtypechanged], eax + + jmp syscall_display_settings._.redraw_whole_screen + + .exit: + ret + +align 4 +syscall_display_settings.01: + and ecx, 1 + cmp ecx, [buttontype] + je .exit + mov [buttontype], ecx + mov [windowtypechanged], ebx + + .exit: + ret + +align 4 +syscall_display_settings.02: + dec ebx + mov esi, ecx + and edx, 127 + mov edi, common_colours + mov ecx, edx + rep movsb + mov [windowtypechanged], ebx + ret + +align 4 +syscall_display_settings.03: + mov edi, ecx + and edx, 127 + mov esi, common_colours + mov ecx, edx + rep movsb + ret + +align 4 +syscall_display_settings.04: + mov eax, [_skinh] + mov [esp + 32], eax + ret + +align 4 +syscall_display_settings.05: + mov eax, [screen_workarea.left - 2] + mov ax, word[screen_workarea.right] + mov [esp + 32], eax + mov eax, [screen_workarea.top - 2] + mov ax, word[screen_workarea.bottom] + mov [esp + 20], eax + ret + +align 4 +syscall_display_settings.06: + xor esi, esi + + mov edi, [Screen_Max_X] + mov eax, ecx + movsx ebx, ax + sar eax, 16 + cmp eax, ebx + jge .check_horizontal + inc esi + or eax, eax + jge @f + xor eax, eax + @@: mov [screen_workarea.left], eax + cmp ebx, edi + jle @f + mov ebx, edi + @@: mov [screen_workarea.right], ebx + + .check_horizontal: + mov edi, [Screen_Max_Y] + mov eax, edx + movsx ebx, ax + sar eax, 16 + cmp eax, ebx + jge .check_if_redraw_needed + inc esi + or eax, eax + jge @f + xor eax, eax + @@: mov [screen_workarea.top], eax + cmp ebx, edi + jle @f + mov ebx, edi + @@: mov [screen_workarea.bottom], ebx + + .check_if_redraw_needed: + or esi, esi + jz .exit + + call repos_windows + jmp syscall_display_settings._.calculate_whole_screen + + .exit: + ret + +align 4 +syscall_display_settings.07: + mov eax, [_skinmargins + 0] + mov [esp + 32], eax + mov eax, [_skinmargins + 4] + mov [esp + 20], eax + ret + +align 4 +syscall_display_settings.08: + mov ebx, ecx + call read_skin_file + mov [esp + 32], eax + test eax, eax + jnz .exit + + call syscall_display_settings._.calculate_whole_screen + jmp syscall_display_settings._.redraw_whole_screen + + .exit: + ret + +syscall_display_settings._.calculate_whole_screen: + xor eax, eax + xor ebx, ebx + mov ecx, [Screen_Max_X] + mov edx, [Screen_Max_Y] + jmp calculatescreen + +syscall_display_settings._.redraw_whole_screen: + xor eax, eax + mov [draw_limits.left], eax + mov [draw_limits.top], eax + mov eax, [Screen_Max_X] + mov [draw_limits.right], eax + mov eax, [Screen_Max_Y] + mov [draw_limits.bottom], eax + mov eax, window_data + jmp redrawscreen + +align 4 +;------------------------------------------------------------------------------ +syscall_set_window_shape: ;///// system function 50 /////////////////////////// +;------------------------------------------------------------------------------ +;; Set window shape address: +;> ebx = 0 +;> ecx = shape data address +; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +;; Set window shape scale: +;> ebx = 1 +;> ecx = scale power (resulting scale is 2^ebx) +;------------------------------------------------------------------------------ + mov edi, [current_slot] + + test ebx, ebx + jne .shape_scale + mov [edi + APPDATA.wnd_shape], ecx + + .shape_scale: + dec ebx + jnz .exit + mov [edi + APPDATA.wnd_shape_scale], ecx + + .exit: + ret + +align 4 +;------------------------------------------------------------------------------ +set_window_defaults: ;///////////////////////////////////////////////////////// +;------------------------------------------------------------------------------ +;? +;------------------------------------------------------------------------------ + push eax ecx + xor eax, eax + mov ecx, WIN_STACK + @@: inc eax + add ecx, 2 + ; process no + mov [ecx + 0x000], ax + ; positions in stack + mov [ecx + 0x400], ax + cmp ecx, WIN_POS - 2 + jne @b + pop ecx eax + ret + +align 4 +;------------------------------------------------------------------------------ +calculatescreen: ;///////////////////////////////////////////////////////////// +;------------------------------------------------------------------------------ +;? Scan all windows from bottom to top, calling `setscreen` for each one +;? intersecting given screen area +;------------------------------------------------------------------------------ +;> eax = left +;> ebx = top +;> ecx = right +;> edx = bottom +;------------------------------------------------------------------------------ + push esi + pushfd + cli + + mov esi, 1 + call window._.set_screen + + push ebp + + mov ebp, [TASK_COUNT] + cmp ebp, 1 + jbe .exit + + push edx ecx ebx eax + + .next_window: + movzx edi, word[WIN_POS + esi * 2] + shl edi, 5 + + cmp [CURRENT_TASK + edi + TASKDATA.state], TSTATE_FREE + je .skip_window + + add edi, window_data + test [edi + WDATA.fl_wstate], WSTATE_MINIMIZED + jnz .skip_window + + mov eax, [edi + WDATA.box.left] + cmp eax, [esp + RECT.right] + jg .skip_window + mov ebx, [edi + WDATA.box.top] + cmp ebx, [esp + RECT.bottom] + jg .skip_window + mov ecx, [edi + WDATA.box.width] + add ecx, eax + cmp ecx, [esp + RECT.left] + jl .skip_window + mov edx, [edi + WDATA.box.height] + add edx, ebx + cmp edx, [esp + RECT.top] + jl .skip_window + + cmp eax, [esp + RECT.left] + jae @f + mov eax, [esp + RECT.left] + @@: cmp ebx, [esp + RECT.top] + jae @f + mov ebx, [esp + RECT.top] + @@: cmp ecx, [esp + RECT.right] + jbe @f + mov ecx, [esp + RECT.right] + @@: cmp edx, [esp + RECT.bottom] + jbe @f + mov edx, [esp + RECT.bottom] + + @@: push esi + movzx esi, word[WIN_POS + esi * 2] + call window._.set_screen + pop esi + + .skip_window: + inc esi + dec ebp + jnz .next_window + + pop eax ebx ecx edx + + .exit: + pop ebp + popfd + pop esi + ret + +align 4 +;------------------------------------------------------------------------------ +repos_windows: ;/////////////////////////////////////////////////////////////// +;------------------------------------------------------------------------------ +;? +;------------------------------------------------------------------------------ + mov ecx, [TASK_COUNT] + mov edi, window_data + WDATA.sizeof * 2 + call force_redraw_background + dec ecx + jle .exit + + .next_window: + mov [edi + WDATA.fl_redraw], 1 + test [edi + WDATA.fl_wstate], WSTATE_MAXIMIZED + jnz .fix_maximized + + mov eax, [edi + WDATA.box.left] + add eax, [edi + WDATA.box.width] + mov ebx, [Screen_Max_X] + cmp eax, ebx + jle .fix_vertical + mov eax, [edi + WDATA.box.width] + sub eax, ebx + jle @f + mov [edi + WDATA.box.width], ebx + @@: sub ebx, [edi + WDATA.box.width] + mov [edi + WDATA.box.left], ebx + + .fix_vertical: + mov eax, [edi + WDATA.box.top] + add eax, [edi + WDATA.box.height] + mov ebx, [Screen_Max_Y] + cmp eax, ebx + jle .fix_client_box + mov eax, [edi + WDATA.box.height] + sub eax, ebx + jle @f + mov [edi + WDATA.box.height], ebx + @@: sub ebx, [edi + WDATA.box.height] + mov [edi + WDATA.box.top], ebx + jmp .fix_client_box + + .fix_maximized: + mov eax, [screen_workarea.left] + mov [edi + WDATA.box.left], eax + sub eax, [screen_workarea.right] + neg eax + mov [edi + WDATA.box.width], eax + mov eax, [screen_workarea.top] + mov [edi + WDATA.box.top], eax + test [edi + WDATA.fl_wstate], WSTATE_ROLLEDUP + jnz .fix_client_box + sub eax, [screen_workarea.bottom] + neg eax + mov [edi + WDATA.box.height], eax + + .fix_client_box: + call set_window_clientbox + + add edi, WDATA.sizeof + loop .next_window + + .exit: + ret + +align 4 +;------------------------------------------------------------------------------ +check_window_position: ;/////////////////////////////////////////////////////// +;------------------------------------------------------------------------------ +;? Check if window is inside screen area +;------------------------------------------------------------------------------ +;> edi = pointer to WDATA +;------------------------------------------------------------------------------ + push eax ebx ecx edx esi + + mov eax, [edi + WDATA.box.left] + mov ebx, [edi + WDATA.box.top] + mov ecx, [edi + WDATA.box.width] + mov edx, [edi + WDATA.box.height] + + mov esi, [Screen_Max_X] + cmp ecx, esi + ja .fix_width + + .check_left: + or eax, eax + jl .fix_left_low + add eax, ecx + cmp eax, esi + jg .fix_left_high + + .check_height: + mov esi, [Screen_Max_Y] + cmp edx, esi + ja .fix_height + + .check_top: + or ebx, ebx + jl .fix_top_low + add ebx, edx + cmp ebx, esi + jg .fix_top_high + + .exit: + pop esi edx ecx ebx eax + ret + + .fix_width: + mov ecx, esi + mov [edi + WDATA.box.width], esi + jmp .check_left + + .fix_left_low: + xor eax, eax + mov [edi + WDATA.box.left], eax + jmp .check_height + + .fix_left_high: + mov eax, esi + sub eax, ecx + mov [edi + WDATA.box.left], eax + jmp .check_height + + .fix_height: + mov edx, esi + mov [edi + WDATA.box.height], esi + jmp .check_top + + .fix_top_low: + xor ebx, ebx + mov [edi + WDATA.box.top], ebx + jmp .exit + + .fix_top_high: + mov ebx, esi + sub ebx, edx + mov [edi + WDATA.box.top], ebx + jmp .exit + +align 4 +;------------------------------------------------------------------------------ +sys_window_mouse: ;//////////////////////////////////////////////////////////// +;------------------------------------------------------------------------------ +;? +;------------------------------------------------------------------------------ + push eax + + mov eax, [timer_ticks] + cmp [new_window_starting], eax + jb .exit + + mov byte[MOUSE_BACKGROUND], 0 + mov byte[DONT_DRAW_MOUSE], 0 + + mov [new_window_starting], eax + + .exit: + pop eax + ret + +align 4 +;------------------------------------------------------------------------------ +draw_rectangle: ;////////////////////////////////////////////////////////////// +;------------------------------------------------------------------------------ +;> eax = pack[16(left), 16(right)] +;> ebx = pack[16(top), 16(bottom)] +;> esi = color +;------------------------------------------------------------------------------ + push eax ebx ecx edi + + xor edi, edi + + .flags_set: + push ebx + + ; set line color + mov ecx, esi + + ; draw top border + rol ebx, 16 + push ebx + rol ebx, 16 + pop bx + call [draw_line] + + ; draw bottom border + mov ebx, [esp - 2] + pop bx + call [draw_line] + + pop ebx + add ebx, 1 * 65536 - 1 + + ; draw left border + rol eax, 16 + push eax + rol eax, 16 + pop ax + call [draw_line] + + ; draw right border + mov eax, [esp - 2] + pop ax + call [draw_line] + + pop edi ecx ebx eax + ret + + .forced: + push eax ebx ecx edi + xor edi, edi + inc edi + jmp .flags_set + +align 4 +;------------------------------------------------------------------------------ +drawwindow_I_caption: ;//////////////////////////////////////////////////////// +;------------------------------------------------------------------------------ +;? +;------------------------------------------------------------------------------ + push [edx + WDATA.cl_titlebar] + mov esi, edx + + mov edx, [esi + WDATA.box.top] + mov eax, edx + lea ebx, [edx + 21] + inc edx + add eax, [esi + WDATA.box.height] + + cmp ebx, eax + jbe @f + mov ebx, eax + @@: push ebx + + xor edi, edi + + .next_line: + mov ebx, edx + shl ebx, 16 + add ebx, edx + mov eax, [esi + WDATA.box.left] + inc eax + shl eax, 16 + add eax, [esi + WDATA.box.left] + add eax, [esi + WDATA.box.width] + dec eax + mov ecx, [esi + WDATA.cl_titlebar] + test ecx, 0x80000000 + jz @f + sub ecx, 0x00040404 + mov [esi + WDATA.cl_titlebar], ecx + @@: and ecx, 0x00ffffff + call [draw_line] + inc edx + cmp edx, [esp] + jb .next_line + + add esp, 4 + pop [esi + WDATA.cl_titlebar] + ret + +align 4 +;------------------------------------------------------------------------------ +drawwindow_I: ;//////////////////////////////////////////////////////////////// +;------------------------------------------------------------------------------ +;? +;------------------------------------------------------------------------------ + pushad + + ; window border + + mov eax, [edx + WDATA.box.left - 2] + mov ax, word[edx + WDATA.box.left] + add ax, word[edx + WDATA.box.width] + mov ebx, [edx + WDATA.box.top - 2] + mov bx, word[edx + WDATA.box.top] + add bx, word[edx + WDATA.box.height] + + mov esi, [edx + WDATA.cl_frames] + call draw_rectangle + + ; window caption + + call drawwindow_I_caption + + ; window client area + + ; do we need to draw it? + mov edi, [esi + WDATA.cl_workarea] + test edi, 0x40000000 + jnz .exit + + ; does client area have a positive size on screen? + mov edx, [esi + WDATA.box.top] + add edx, 21 + 5 + mov ebx, [esi + WDATA.box.top] + add ebx, [esi + WDATA.box.height] + cmp edx, ebx + jg .exit + + ; okay, let's draw it + mov eax, 1 + mov ebx, 21 + mov ecx, [esi + WDATA.box.width] + mov edx, [esi + WDATA.box.height] + call [drawbar] + + .exit: + popad + ret + +align 4 +;------------------------------------------------------------------------------ +drawwindow_III_caption: ;///////////////////////////////////////////////////// +;------------------------------------------------------------------------------ +;? +;------------------------------------------------------------------------------ + mov ecx, [edx + WDATA.cl_titlebar] + push ecx + mov esi, edx + mov edx, [esi + WDATA.box.top] + add edx, 4 + mov ebx, [esi + WDATA.box.top] + add ebx, 20 + mov eax, [esi + WDATA.box.top] + add eax, [esi + WDATA.box.height] + + cmp ebx, eax + jb @f + mov ebx, eax + @@: push ebx + + xor edi, edi + + .next_line: + mov ebx, edx + shl ebx, 16 + add ebx, edx + mov eax, [esi + WDATA.box.left] + shl eax, 16 + add eax, [esi + WDATA.box.left] + add eax, [esi + WDATA.box.width] + add eax, 4 * 65536 - 4 + mov ecx, [esi + WDATA.cl_titlebar] + test ecx, 0x40000000 + jz @f + add ecx, 0x00040404 + @@: test ecx, 0x80000000 + jz @f + sub ecx, 0x00040404 + @@: mov [esi + WDATA.cl_titlebar], ecx + and ecx, 0x00ffffff + call [draw_line] + inc edx + cmp edx, [esp] + jb .next_line + + add esp, 4 + pop [esi + WDATA.cl_titlebar] + ret + +align 4 +;------------------------------------------------------------------------------ +drawwindow_III: ;////////////////////////////////////////////////////////////// +;------------------------------------------------------------------------------ +;? +;------------------------------------------------------------------------------ + pushad + + ; window border + + mov eax, [edx + WDATA.box.left - 2] + mov ax, word[edx + WDATA.box.left] + add ax, word[edx + WDATA.box.width] + mov ebx, [edx + WDATA.box.top - 2] + mov bx, word[edx + WDATA.box.top] + add bx, word[edx + WDATA.box.height] + + mov esi, [edx + WDATA.cl_frames] + shr esi, 1 + and esi, 0x007f7f7f + call draw_rectangle + + push esi + mov ecx, 3 + mov esi, [edx + WDATA.cl_frames] + + .next_frame: + add eax, 1 * 65536 - 1 + add ebx, 1 * 65536 - 1 + call draw_rectangle + dec ecx + jnz .next_frame + + pop esi + add eax, 1 * 65536 - 1 + add ebx, 1 * 65536 - 1 + call draw_rectangle + + ; window caption + + call drawwindow_III_caption + + ; window client area + + ; do we need to draw it? + mov edi, [esi + WDATA.cl_workarea] + test edi, 0x40000000 + jnz .exit + + ; does client area have a positive size on screen? + mov edx, [esi + WDATA.box.top] + add edx, 21 + 5 + mov ebx, [esi + WDATA.box.top] + add ebx, [esi + WDATA.box.height] + cmp edx, ebx + jg .exit + + ; okay, let's draw it + mov eax, 5 + mov ebx, 20 + mov ecx, [esi + WDATA.box.width] + mov edx, [esi + WDATA.box.height] + sub ecx, 4 + sub edx, 4 + call [drawbar] + + .exit: + popad + ret + +align 4 +;------------------------------------------------------------------------------ +waredraw: ;//////////////////////////////////////////////////////////////////// +;------------------------------------------------------------------------------ +;? Activate window, redrawing if necessary +;------------------------------------------------------------------------------ + ; is it overlapped by another window now? + push ecx + call window._.check_window_draw + test ecx, ecx + pop ecx + jz .do_not_draw + + ; yes it is, activate and update screen buffer + mov byte[MOUSE_DOWN], 1 + call window._.window_activate + + pushad + mov edi, [TASK_COUNT] + movzx esi, word[WIN_POS + edi * 2] + shl esi, 5 + add esi, window_data + + mov eax, [esi + WDATA.box.left] + mov ebx, [esi + WDATA.box.top] + mov ecx, [esi + WDATA.box.width] + mov edx, [esi + WDATA.box.height] + + add ecx, eax + add edx, ebx + + mov edi, [TASK_COUNT] + movzx esi, word[WIN_POS + edi * 2] + call window._.set_screen + popad + + ; tell application to redraw itself + mov [edi + WDATA.fl_redraw], 1 + mov byte[MOUSE_DOWN], 0 + ret + + .do_not_draw: + ; no it's not, just activate the window + call window._.window_activate + mov byte[MOUSE_DOWN], 0 + mov byte[MOUSE_BACKGROUND], 0 + mov byte[DONT_DRAW_MOUSE], 0 + ret + +align 4 +;------------------------------------------------------------------------------ +minimize_window: ;///////////////////////////////////////////////////////////// +;------------------------------------------------------------------------------ +;> eax = window number on screen +;------------------------------------------------------------------------------ +;# corrupts [dl*] +;------------------------------------------------------------------------------ + push edi + pushfd + cli + + ; is it already minimized? + movzx edi, word[WIN_POS + eax * 2] + shl edi, 5 + add edi, window_data + test [edi + WDATA.fl_wstate], WSTATE_MINIMIZED + jnz .exit + + push eax ebx ecx edx esi + + ; no it's not, let's do that + or [edi + WDATA.fl_wstate], WSTATE_MINIMIZED + mov eax, [edi + WDATA.box.left] + mov [draw_limits.left], eax + mov ecx, eax + add ecx, [edi + WDATA.box.width] + mov [draw_limits.right], ecx + mov ebx, [edi + WDATA.box.top] + mov [draw_limits.top], ebx + mov edx, ebx + add edx, [edi + WDATA.box.height] + mov [draw_limits.bottom], edx + call calculatescreen + xor esi, esi + xor eax, eax + call redrawscreen + + pop esi edx ecx ebx eax + + .exit: + popfd + pop edi + ret + +align 4 +;------------------------------------------------------------------------------ +restore_minimized_window: ;//////////////////////////////////////////////////// +;------------------------------------------------------------------------------ +;> eax = window number on screen +;------------------------------------------------------------------------------ +;# corrupts [dl*] +;------------------------------------------------------------------------------ + pushad + pushfd + cli + + ; is it already restored? + movzx esi, word[WIN_POS + eax * 2] + mov edi, esi + shl edi, 5 + add edi, window_data + test [edi + WDATA.fl_wstate], WSTATE_MINIMIZED + jz .exit + + ; no it's not, let's do that + mov [edi + WDATA.fl_redraw], 1 + and [edi + WDATA.fl_wstate], not WSTATE_MINIMIZED + mov ebp, window._.set_screen + cmp eax, [TASK_COUNT] + jz @f + mov ebp, calculatescreen + @@: mov eax, [edi + WDATA.box.left] + mov ebx, [edi + WDATA.box.top] + mov ecx, [edi + WDATA.box.width] + mov edx, [edi + WDATA.box.height] + add ecx, eax + add edx, ebx + call ebp + + mov byte[MOUSE_BACKGROUND], 0 + + .exit: + popfd + popad + ret + +align 4 +;------------------------------------------------------------------------------ +checkwindows: ;//////////////////////////////////////////////////////////////// +;------------------------------------------------------------------------------ +;? Check for user-initiated window operations +;------------------------------------------------------------------------------ + pushad + + ; do we have window minimize/restore request? + cmp [window_minimize], 0 + je .check_for_mouse_buttons_state + + ; okay, minimize or restore top-most window and exit + mov eax, [TASK_COUNT] + mov bl, 0 + xchg [window_minimize], bl + dec bl + jnz @f + call minimize_window + jmp .check_for_mouse_buttons_state + @@: call restore_minimized_window + + .check_for_mouse_buttons_state: + ; do we have any mouse buttons pressed? + cmp byte[BTN_DOWN], 0 + jne .mouse_buttons_pressed + + mov [bPressedMouseXY_W], 0 + jmp .exit + + .mouse_buttons_pressed: + ; yes we do, iterate and ... + mov esi, [TASK_COUNT] + inc esi + + cmp [bPressedMouseXY_W], 1 + ja .next_window + inc [bPressedMouseXY_W] + jnc .next_window + push dword[MOUSE_X] + pop dword[mx] + + .next_window: + cmp esi, 2 + jb .exit + + dec esi + + ; is that window not minimized? + movzx edi, word[WIN_POS + esi * 2] + shl edi, 5 + add edi, window_data + test [edi + WDATA.fl_wstate], WSTATE_MINIMIZED + jnz .next_window + + movzx eax, [mx] + movzx ebx, [my] + + ; is the cursor inside screen bounds of that window? + mov ecx, [edi + WDATA.box.left] + mov edx, [edi + WDATA.box.top] + cmp eax, ecx + jl .next_window + cmp ebx, edx + jl .next_window + add ecx, [edi + WDATA.box.width] + add edx, [edi + WDATA.box.height] + cmp eax, ecx + jge .next_window + cmp ebx, edx + jge .next_window + + ; is that a top-most (which means active) window? + cmp esi, [TASK_COUNT] + je .check_for_moving_or_resizing + + ; no it's not, did we just press mouse button down above it or was it + ; already pressed before? + cmp [bPressedMouseXY_W], 1 + ja .exit + + ; okay, we just pressed the button, activate this window and exit + lea esi, [WIN_POS + esi * 2] + call waredraw + jmp .exit + + .check_for_moving_or_resizing: + ; is that window movable? + test byte[edi + WDATA.cl_titlebar + 3], 0x01 + jnz .exit + + ; yes it is, is it rolled up? + test [edi + WDATA.fl_wstate], WSTATE_ROLLEDUP + jnz .check_for_cursor_on_caption + + ; no it's not, can it be resized then? + mov [do_resize_from_corner], 0 + mov dl, [edi + WDATA.fl_wstyle] + and dl, 0x0f + cmp dl, 0x00 + je .check_for_cursor_on_caption + cmp dl, 0x01 + je .check_for_cursor_on_caption + cmp dl, 0x04 + je .check_for_cursor_on_caption + + ; are we going to resize it? + mov edx, [edi + WDATA.box.top] + add edx, [edi + WDATA.box.height] + sub edx, 6 + cmp ebx, edx + jl .check_for_cursor_on_caption + + ; yes we do, remember that + mov [do_resize_from_corner], 1 + jmp .set_move_resize_flag + + .check_for_cursor_on_caption: + ; is the cursor inside window titlebar? + push eax + call window._.get_titlebar_height + add eax, [edi + WDATA.box.top] + cmp ebx, eax + pop eax + jge .exit + + ; calculate duration between two clicks + mov ecx, [timer_ticks] + mov edx, ecx + sub edx, [latest_window_touch] + mov [latest_window_touch], ecx + mov [latest_window_touch_delta], edx + + .set_move_resize_flag: + mov cl, [BTN_DOWN] + mov [do_resize], cl + + mov ecx, [edi + WDATA.box.left] + mov edx, [edi + WDATA.box.top] + + push ecx edx + mov [draw_limits.left], ecx + mov [draw_limits.top], edx + add ecx, [edi + WDATA.box.width] + add edx, [edi + WDATA.box.height] + mov [draw_limits.right], ecx + mov [draw_limits.bottom], edx + pop edx ecx + + ; calculate window-relative cursor coordinates + sub eax, ecx + sub ebx, edx + + push dword[MOUSE_X] + pop dword[WIN_TEMP_XY] + + ; save old window coordinates + push eax + mov eax, [edi + WDATA.box.left] + mov [old_window_pos.left], eax + mov [new_window_pos.left], eax + mov eax, [edi + WDATA.box.top] + mov [old_window_pos.top], eax + mov [new_window_pos.top], eax + mov eax, [edi + WDATA.box.width] + mov [old_window_pos.width], eax + mov [new_window_pos.width], eax + mov eax, [edi + WDATA.box.height] + mov [old_window_pos.height], eax + mov [new_window_pos.height], eax + pop eax + + ; draw negative moving/sizing frame + call window._.draw_window_frames + + mov [reposition], 0 + mov byte[MOUSE_DOWN], 1 + + .next_mouse_state_check: + ; process OS events + mov byte[DONT_DRAW_MOUSE], 1 + call checkidle + call checkVga_N13 + mov byte[MOUSE_BACKGROUND], 0 + call [draw_pointer] + pushad + call stack_handler + popad + + ; did cursor position change? + mov esi, [WIN_TEMP_XY] + cmp esi, [MOUSE_X] + je .check_for_new_mouse_buttons_state + + ; yes it did, calculate window-relative cursor coordinates + movzx ecx, word[MOUSE_X] + movzx edx, word[MOUSE_Y] + sub ecx, eax + sub edx, ebx + + push eax ebx + + ; we're going to draw new frame, erasing the old one + call window._.draw_window_frames + + ; are we moving it right now? + cmp [do_resize_from_corner], 0 + jne .resize_window + + ; yes we do, check if it's inside the screen area + mov eax, [Screen_Max_X] + mov ebx, [Screen_Max_Y] + + mov [new_window_pos.left], 0 + or ecx, ecx + jle .check_for_new_vert_cursor_pos + mov [reposition], 1 + sub eax, [new_window_pos.width] + mov [new_window_pos.left], eax + cmp ecx, eax + jge .check_for_new_vert_cursor_pos + mov [new_window_pos.left], ecx + + .check_for_new_vert_cursor_pos: + mov [new_window_pos.top], 0 + or edx, edx + jle .draw_new_window_frame + mov [reposition], 1 + sub ebx, [new_window_pos.height] + mov [new_window_pos.top], ebx + cmp edx, ebx + jge .draw_new_window_frame + mov [new_window_pos.top], edx + jmp .draw_new_window_frame + + .resize_window: + push eax ebx edx + + mov edx, edi + sub edx, window_data + lea edx, [SLOT_BASE + edx * 8] + + movzx eax, word[MOUSE_X] + cmp eax, [edi + WDATA.box.left] + jb .fix_new_vert_size + sub eax, [edi + WDATA.box.left] + cmp eax, 32 + jge @f + mov eax, 32 + @@: mov [new_window_pos.width], eax + + .fix_new_vert_size: + call window._.get_rolledup_height + mov ebx, eax + movzx eax, word[MOUSE_Y] + cmp eax, [edi + WDATA.box.top] + jb .set_reposition_flag + sub eax, [edi + WDATA.box.top] + cmp eax, ebx + jge @f + mov eax, ebx + @@: mov [new_window_pos.height], eax + + .set_reposition_flag: + mov [reposition], 1 + + pop edx ebx eax + + .draw_new_window_frame: + pop ebx eax + + ; draw new window moving/sizing frame + call window._.draw_window_frames + + mov esi, [MOUSE_X] + mov [WIN_TEMP_XY], esi + + .check_for_new_mouse_buttons_state: + ; did user release mouse button(s)? + cmp byte[BTN_DOWN], 0 + jne .next_mouse_state_check + + ; yes he did, moving/sizing is over + mov byte[DONT_DRAW_MOUSE], 1 + mov cl, 0 + test [edi + WDATA.fl_wstate], WSTATE_MAXIMIZED + jnz .check_other_actions + + mov cl, [reposition] + + ; draw negative frame once again to hide it + call window._.draw_window_frames + + ; save new window bounds + mov eax, [new_window_pos.left] + mov [edi + WDATA.box.left], eax + mov eax, [new_window_pos.top] + mov [edi + WDATA.box.top], eax + mov eax, [new_window_pos.width] + mov [edi + WDATA.box.width], eax + mov eax, [new_window_pos.height] + mov [edi + WDATA.box.height], eax + call set_window_clientbox + + cmp cl, 1 + jne .check_other_actions + push esi edi ecx + mov esi, edi + mov ecx, 2 + test [edi + WDATA.fl_wstate], WSTATE_ROLLEDUP or WSTATE_MAXIMIZED + jnz @f + add ecx, 2 + @@: sub edi, window_data + shr edi, 5 + shl edi, 8 + add edi, SLOT_BASE + APPDATA.saved_box + cld + rep movsd + pop ecx edi esi + + .check_other_actions: + mov [reposition], cl + + pushad + + mov dl, [edi + WDATA.fl_wstyle] + and dl, 0x0f + cmp dl, 0x00 + je .check_if_window_fits_screen + cmp dl, 0x01 + je .check_if_window_fits_screen + + cmp cl, 1 + je .no_window_sizing + mov edx, edi + sub edx, window_data + shr edx, 5 + shl edx, 8 + add edx, SLOT_BASE + + ; did we right-click on titlebar? + cmp [do_resize], 2 + jne .check_maximization_request + + ; yes we did, toggle normal/rolled up window state + xor [edi + WDATA.fl_wstate], WSTATE_ROLLEDUP + mov [reposition], 1 + + ; calculate and set appropriate window height + test [edi + WDATA.fl_wstate], WSTATE_ROLLEDUP + jz @f + call window._.get_rolledup_height + jmp .set_new_window_height + @@: mov eax, [edx + APPDATA.saved_box.height] + test [edi + WDATA.fl_wstate], WSTATE_MAXIMIZED + jz .set_new_window_height + mov eax, [screen_workarea.bottom] + sub eax, [screen_workarea.top] + + .set_new_window_height: + mov [edi + WDATA.box.height], eax + add eax, [edi + WDATA.box.top] + cmp eax, [Screen_Max_Y] + jbe @f + mov eax, [Screen_Max_Y] + sub eax, [edi + WDATA.box.height] + mov [edi + WDATA.box.top], eax + @@: call check_window_position + call set_window_clientbox + + .check_maximization_request: + ; can window change its height? + push edx + mov dl, [edi + WDATA.fl_wstyle] + and dl, 0x0f + cmp dl, 0x04 + pop edx + je .check_if_window_fits_screen + + ; was it really a maximize/restore request? + cmp [do_resize], 1 + jne .check_if_window_fits_screen + cmp [do_resize_from_corner], 0 + jne .check_if_window_fits_screen + cmp [latest_window_touch_delta], 50 + jg .check_if_window_fits_screen + + ; yes is was, toggle normal/maximized window state + xor [edi + WDATA.fl_wstate], WSTATE_MAXIMIZED + mov [reposition], 1 + + ; calculate and set appropriate window bounds + test [edi + WDATA.fl_wstate], WSTATE_MAXIMIZED + jz .restore_normal_window_size + mov eax, [screen_workarea.left] + mov [edi + WDATA.box.left], eax + sub eax, [screen_workarea.right] + neg eax + mov [edi + WDATA.box.width], eax + mov eax, [screen_workarea.top] + mov [edi + WDATA.box.top], eax + test [edi + WDATA.fl_wstate], WSTATE_ROLLEDUP + jnz .calculate_window_client_area + sub eax, [screen_workarea.bottom] + neg eax + mov [edi + WDATA.box.height], eax + jmp .calculate_window_client_area + + .restore_normal_window_size: + push [edi + WDATA.box.height] + push edi + lea esi, [edx + APPDATA.saved_box] + mov ecx, 4 + cld + rep movsd + pop edi + pop eax + test [edi + WDATA.fl_wstate], WSTATE_ROLLEDUP + jz .calculate_window_client_area + mov [edi + WDATA.box.height], eax + + .calculate_window_client_area: + call set_window_clientbox + + .check_if_window_fits_screen: + ; does window fit into screen area? + mov eax, [edi + WDATA.box.top] + add eax, [edi + WDATA.box.height] + cmp eax, [Screen_Max_Y] + jbe .no_window_sizing + mov eax, [edi + WDATA.box.left] + add eax, [edi + WDATA.box.width] + cmp eax, [Screen_Max_X] + jbe .no_window_sizing + + ; no it doesn't, fix that + mov eax, [Screen_Max_X] + sub eax, [edi + WDATA.box.width] + mov [edi + WDATA.box.left], eax + mov eax, [Screen_Max_Y] + sub eax, [edi + WDATA.box.height] + mov [edi + WDATA.box.top], eax + call set_window_clientbox + + .no_window_sizing: + popad + + ; did somethins actually change its place? + cmp [reposition], 0 + je .reset_vars + + mov byte[DONT_DRAW_MOUSE], 1 + + push eax ebx ecx edx + + ; recalculate screen buffer at new position + mov eax, [edi + WDATA.box.left] + mov ebx, [edi + WDATA.box.top] + mov ecx, [edi + WDATA.box.width] + mov edx, [edi + WDATA.box.height] + add ecx, eax + add edx, ebx + call calculatescreen + + ; recalculate screen buffer at old position + mov eax, [old_window_pos.left] + mov ebx, [old_window_pos.top] + mov ecx, [old_window_pos.width] + mov edx, [old_window_pos.height] + add ecx, eax + add edx, ebx + call calculatescreen + + pop edx ecx ebx eax + + mov eax, edi + call redrawscreen + + ; tell window to redraw itself + mov [edi + WDATA.fl_redraw], 1 + + ; wait a bit for window to redraw itself + mov ecx, 100 + + .next_idle_cycle: + mov byte[DONT_DRAW_MOUSE], 1 + call checkidle + cmp [edi + WDATA.fl_redraw], 0 + jz .reset_vars + loop .next_idle_cycle + + .reset_vars: + mov byte[DONT_DRAW_MOUSE], 0 ; mouse pointer + mov byte[MOUSE_BACKGROUND], 0 ; no mouse under + mov byte[MOUSE_DOWN], 0 ; react to mouse up/down + + .exit: + popad + ret + +;============================================================================== +;///// private functions ////////////////////////////////////////////////////// +;============================================================================== + +align 4 +;------------------------------------------------------------------------------ +window._.get_titlebar_height: ;//////////////////////////////////////////////// +;------------------------------------------------------------------------------ +;> edi = pointer to WDATA +;------------------------------------------------------------------------------ + mov al, [edi + WDATA.fl_wstyle] + and al, 0x0f + cmp al, 0x03 + jne @f + mov eax, [_skinh] + ret + @@: mov eax, 21 + ret + +align 4 +;------------------------------------------------------------------------------ +window._.get_rolledup_height: ;//////////////////////////////////////////////// +;------------------------------------------------------------------------------ +;> edi = pointer to WDATA +;------------------------------------------------------------------------------ + mov al, [edi + WDATA.fl_wstyle] + and al, 0x0f + cmp al, 0x03 + jb @f + mov eax, [_skinh] + add eax, 3 + ret + @@: or al, al + jnz @f + mov eax, 21 + ret + @@: mov eax, 21 + 2 + ret + +align 4 +;------------------------------------------------------------------------------ +window._.set_screen: ;///////////////////////////////////////////////////////// +;------------------------------------------------------------------------------ +;? Reserve window area in screen buffer +;------------------------------------------------------------------------------ +;> eax = left +;> ebx = top +;> ecx = right +;> edx = bottom +;> esi = process number +;------------------------------------------------------------------------------ +virtual at esp + ff_x dd ? + ff_y dd ? + ff_width dd ? + ff_xsz dd ? + ff_ysz dd ? + ff_scale dd ? +end virtual + + pushad + + cmp esi, 1 + jz .check_for_shaped_window + mov edi, esi + shl edi, 5 + cmp [window_data + edi + WDATA.box.width], 0 + jnz .check_for_shaped_window + cmp [window_data + edi + WDATA.box.height], 0 + jz .exit + + .check_for_shaped_window: + mov edi, esi + shl edi, 8 + add edi, SLOT_BASE + cmp [edi + APPDATA.wnd_shape], 0 + jne .shaped_window + + ; get x&y size + sub ecx, eax + sub edx, ebx + inc ecx + inc edx + + ; get WinMap start + push esi + mov edi, [Screen_Max_X] + inc edi + mov esi, edi + imul edi, ebx + add edi, eax + add edi, [_WinMapAddress] + pop eax + mov ah, al + push ax + shl eax, 16 + pop ax + + .next_line: + push ecx + shr ecx, 2 + rep stosd + mov ecx, [esp] + and ecx, 3 + rep stosb + pop ecx + add edi, esi + sub edi, ecx + dec edx + jnz .next_line + + jmp .exit + + .shaped_window: + ; for (y=0; y <= x_size; y++) + ; for (x=0; x <= x_size; x++) + ; if (shape[coord(x,y,scale)]==1) + ; set_pixel(x, y, process_number); + + sub ecx, eax + sub edx, ebx + inc ecx + inc edx + + push [edi + APPDATA.wnd_shape_scale] ; push scale first -> for loop + + ; get WinMap start -> ebp + push eax + mov eax, [Screen_Max_X] ; screen_sx + inc eax + imul eax, ebx + add eax, [esp] + add eax, [_WinMapAddress] + mov ebp, eax + + mov edi, [edi + APPDATA.wnd_shape] + pop eax + + ; eax = x_start + ; ebx = y_start + ; ecx = x_size + ; edx = y_size + ; esi = process_number + ; edi = &shape + ; [scale] + push edx ecx ; for loop - x,y size + + mov ecx, esi + shl ecx, 5 + mov edx, [window_data + ecx + WDATA.box.top] + push [window_data + ecx + WDATA.box.width] ; for loop - width + mov ecx, [window_data + ecx + WDATA.box.left] + sub ebx, edx + sub eax, ecx + push ebx eax ; for loop - x,y + + add [ff_xsz], eax + add [ff_ysz], ebx + + mov ebx, [ff_y] + + .ff_new_y: + mov edx, [ff_x] + + .ff_new_x: + ; -- body -- + mov ecx, [ff_scale] + mov eax, [ff_width] + inc eax + shr eax, cl + push ebx edx + shr ebx, cl + shr edx, cl + imul eax, ebx + add eax, edx + pop edx ebx + add eax, edi + call .read_byte + test al,al + jz @f + mov eax, esi + mov [ebp], al + ; -- end body -- + @@: inc ebp + inc edx + cmp edx, [ff_xsz] + jb .ff_new_x + + sub ebp, [ff_xsz] + add ebp, [ff_x] + add ebp, [Screen_Max_X] ; screen.x + inc ebp + inc ebx + cmp ebx, [ff_ysz] + jb .ff_new_y + + add esp, 24 + + .exit: + popad + ret + + .read_byte: + ; eax - address + ; esi - slot + push eax ecx edx esi + xchg eax, esi + lea ecx, [esp + 12] + mov edx, 1 + call read_process_memory + pop esi edx ecx eax + ret + +align 4 +;------------------------------------------------------------------------------ +window._.window_activate: ;//////////////////////////////////////////////////// +;------------------------------------------------------------------------------ +;? Activate window +;------------------------------------------------------------------------------ +;> esi = pointer to WIN_POS+ window data +;------------------------------------------------------------------------------ + push eax ebx + + ; if type of current active window is 3 or 4, it must be redrawn + mov ebx, [TASK_COUNT] + movzx ebx, word[WIN_POS + ebx * 2] + shl ebx, 5 + add eax, window_data + mov al, [window_data + ebx + WDATA.fl_wstyle] + and al, 0x0f + cmp al, 0x03 + je .set_window_redraw_flag + cmp al, 0x04 + jne .move_others_down + + .set_window_redraw_flag: + mov [window_data + ebx + WDATA.fl_redraw], 1 + + .move_others_down: + ; ax <- process no + movzx ebx, word[esi] + ; ax <- position in window stack + movzx ebx, word[WIN_STACK + ebx * 2] + + ; drop others + xor eax, eax + + .next_stack_window: + cmp eax, [TASK_COUNT] + jae .move_self_up + inc eax + cmp [WIN_STACK + eax * 2], bx + jbe .next_stack_window + dec word[WIN_STACK + eax * 2] + jmp .next_stack_window + + .move_self_up: + movzx ebx, word[esi] + ; number of processes + mov ax, [TASK_COUNT] + ; this is the last (and the upper) + mov [WIN_STACK + ebx * 2], ax + + ; update on screen - window stack + xor eax, eax + + .next_window_pos: + cmp eax, [TASK_COUNT] + jae .reset_vars + inc eax + movzx ebx, word[WIN_STACK + eax * 2] + mov [WIN_POS + ebx * 2], ax + jmp .next_window_pos + + .reset_vars: + mov byte[KEY_COUNT], 0 + mov byte[BTN_COUNT], 0 + mov word[MOUSE_SCROLL_H], 0 + mov word[MOUSE_SCROLL_V], 0 + + pop ebx eax + ret + +align 4 +;------------------------------------------------------------------------------ +window._.check_window_draw: ;////////////////////////////////////////////////// +;------------------------------------------------------------------------------ +;? Check if window is necessary to draw +;------------------------------------------------------------------------------ +;> edi = pointer to WDATA +;------------------------------------------------------------------------------ + mov cl, [edi + WDATA.fl_wstyle] + and cl, 0x0f + cmp cl, 0x03 + je .exit.redraw ; window type 3 + cmp cl, 0x04 + je .exit.redraw ; window type 4 + + push eax ebx edx esi + + mov eax, edi + sub eax, window_data + shr eax, 5 + + ; esi = process number + + movzx eax, word[WIN_STACK + eax * 2] ; get value of the curr process + lea esi, [WIN_POS + eax * 2] ; get address of this process at 0xC400 + + .next_window: + add esi, 2 + + mov eax, [TASK_COUNT] + lea eax, word[WIN_POS + eax * 2] ; number of the upper window + + cmp esi, eax + ja .exit.no_redraw + + movzx edx, word[esi] + shl edx, 5 + cmp [CURRENT_TASK + edx + TASKDATA.state], TSTATE_FREE + je .next_window + + mov eax, [edi + WDATA.box.top] + mov ebx, [edi + WDATA.box.height] + add ebx, eax + + mov ecx, [window_data + edx + WDATA.box.top] + cmp ecx, ebx + jge .next_window + add ecx, [window_data + edx + WDATA.box.height] + cmp eax, ecx + jge .next_window + + mov eax, [edi + WDATA.box.left] + mov ebx, [edi + WDATA.box.width] + add ebx, eax + + mov ecx, [window_data + edx + WDATA.box.left] + cmp ecx, ebx + jge .next_window + add ecx, [window_data + edx + WDATA.box.width] + cmp eax, ecx + jge .next_window + + pop esi edx ebx eax + + .exit.redraw: + xor ecx, ecx + inc ecx + ret + + .exit.no_redraw: + pop esi edx ebx eax + xor ecx, ecx + ret + +align 4 +;------------------------------------------------------------------------------ +window._.draw_window_frames: ;///////////////////////////////////////////////// +;------------------------------------------------------------------------------ +;? Draw negative window frames +;------------------------------------------------------------------------------ +;> edi = pointer to WDATA +;------------------------------------------------------------------------------ + push eax + cli + + test [edi + WDATA.fl_wstate], WSTATE_MAXIMIZED + jnz .exit + mov eax, [new_window_pos.left] + cmp eax, [edi + WDATA.box.left] + jnz .draw + mov eax, [new_window_pos.width] + cmp eax, [edi + WDATA.box.width] + jnz .draw + mov eax, [new_window_pos.top] + cmp eax, [edi + WDATA.box.top] + jnz .draw + mov eax, [new_window_pos.height] + cmp eax, [edi + WDATA.box.height] + jnz .draw + xor [edi + WDATA.fl_wdrawn], 2 + + .draw: + push ebx esi + mov eax, [new_window_pos.left - 2] + mov ax, word[new_window_pos.left] + add ax, word[new_window_pos.width] + mov ebx, [new_window_pos.top - 2] + mov bx, word[new_window_pos.top] + add bx, word[new_window_pos.height] + mov esi, 0x01000000 + call draw_rectangle.forced + pop esi ebx + + .exit: + sti + pop eax + ret + + .forced: + push eax + cli + jmp .draw diff --git a/kernel/branches/net/hid/mousedrv.inc b/kernel/branches/net/hid/mousedrv.inc index 430600664a..e6de7c5af6 100644 --- a/kernel/branches/net/hid/mousedrv.inc +++ b/kernel/branches/net/hid/mousedrv.inc @@ -51,12 +51,13 @@ endg draw_mouse_under: ; return old picture - cmp [set_hw_cursor], 0 - jz @F + cmp [_display.restore_cursor], 0 + je @F + pushad movzx eax,word [X_UNDER] movzx ebx,word [Y_UNDER] - stdcall [hw_restore], eax, ebx + stdcall [_display.restore_cursor], eax, ebx popad ret @@: @@ -97,7 +98,7 @@ mres: save_draw_mouse: - cmp [set_hw_cursor], 0 + cmp [_display.move_cursor], 0 je .no_hw_cursor pushad @@ -111,28 +112,25 @@ save_draw_mouse: mov ecx, [Screen_Max_X] inc ecx mul ecx - - movzx edx, byte [display_data+ebx+eax] + add eax, [_WinMapAddress] + movzx edx, byte [ebx+eax] shl edx, 8 mov esi, [edx+SLOT_BASE+APPDATA.cursor] cmp esi, [current_cursor] je .draw - ; cmp [esi+CURSOR.magic], 'CURS' - ; jne .fail - push esi - call [select_hw_cursor] + call [_display.select_cursor] mov [current_cursor], esi .draw: - stdcall [set_hw_cursor], esi + stdcall [_display.move_cursor], esi popad ret .fail: mov ecx, [def_cursor] mov [edx+SLOT_BASE+APPDATA.cursor], ecx - stdcall [set_hw_cursor], ecx ; stdcall: [esp]=ebx,eax + stdcall [_display.move_cursor], ecx ; stdcall: [esp]=ebx,eax popad ret @@ -292,7 +290,7 @@ __sys_disable_mouse: inc ecx imul ecx,ebx add ecx,eax - add ecx, display_data + add ecx, [_WinMapAddress] mov eax, [CURRENT_TASK] movzx ebx, byte [ecx] cmp eax,ebx diff --git a/kernel/branches/net/hid/set_dtc.inc b/kernel/branches/net/hid/set_dtc.inc index 53539700eb..abaa3eddf1 100644 --- a/kernel/branches/net/hid/set_dtc.inc +++ b/kernel/branches/net/hid/set_dtc.inc @@ -1,6 +1,6 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; -;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;; +;; Copyright (C) KolibriOS team 2004-2009. All rights reserved. ;; ;; Distributed under terms of the GNU General Public License ;; ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -17,157 +17,159 @@ $Revision$ ; ebx =3 - set alarm-clock ecx - 00SSMMHH ; out: 0 -Ok 1 -wrong format 2 -battery low sys_settime: - mov ecx,eax + cli mov al,0x0d out 0x70,al in al,0x71 bt ax,7 jnc bat_low - cmp ecx,2 ;day of week + cmp ebx,2 ;day of week jne nosetweek - test ebx,ebx ;test day of week + test ecx,ecx ;test day of week je wrongtime - cmp ebx,7 + cmp ecx,7 ja wrongtime - mov dx,0x70 + mov edx,0x70 call startstopclk dec edx mov al,6 out dx,al inc edx - mov al,bl + mov al,cl out dx,al jmp endsettime nosetweek: ;set date - cmp ecx,1 + cmp ebx,1 jne nosetdate - cmp bl,0x99 ;test year + cmp cl,0x99 ;test year ja wrongtime - shl ebx,4 - cmp bl,0x90 + shl ecx,4 + cmp cl,0x90 ja wrongtime - cmp bh,0x99 ;test month + cmp ch,0x99 ;test month ja wrongtime - shr ebx,4 - test bh,bh + shr ecx,4 + test ch,ch je wrongtime - cmp bh,0x12 + cmp ch,0x12 ja wrongtime - shl ebx,8 - bswap ebx ;ebx=00YYMMDD - test bl,bl ;test day + shl ecx,8 + bswap ecx ;ebx=00YYMMDD + test cl,cl ;test day je wrongtime - shl ebx,4 - cmp bl,0x90 + shl ecx,4 + cmp cl,0x90 ja wrongtime - shr ebx,4 - cmp bh,2 ;February + shr ecx,4 + cmp ch,2 ;February jne testday - cmp bl,0x29 + cmp cl,0x29 ja wrongtime jmp setdate testday: - cmp bh,8 + cmp ch,8 jb testday1 ;Aug-Dec - bt bx,8 + bt cx,8 jnc days31 jmp days30 testday1: - bt bx,8 ;Jan-Jul ex.Feb + bt cx,8 ;Jan-Jul ex.Feb jnc days30 days31: - cmp bl,0x31 + cmp cl,0x31 ja wrongtime jmp setdate days30: - cmp bl,0x30 + cmp cl,0x30 ja wrongtime setdate: - mov dx,0x70 + mov edx,0x70 call startstopclk dec edx mov al,7 ;set days out dx,al inc edx - mov al,bl + mov al,cl out dx,al dec edx mov al,8 ;set months out dx,al inc edx - mov al,bh + mov al,ch out dx,al dec edx mov al,9 ;set years out dx,al inc edx - shr ebx,8 - mov al,bh + shr ecx,8 + mov al,ch out dx,al jmp endsettime nosetdate: ;set time or alarm-clock - cmp ecx,3 + cmp ebx,3 ja wrongtime - cmp bl,0x23 + cmp cl,0x23 ja wrongtime - cmp bh,0x59 + cmp ch,0x59 ja wrongtime - shl ebx,4 - cmp bl,0x90 + shl ecx,4 + cmp cl,0x90 ja wrongtime - cmp bh,0x92 + cmp ch,0x92 ja wrongtime - shl ebx,4 - bswap ebx ;00HHMMSS - cmp bl,0x59 + shl ecx,4 + bswap ecx ;00HHMMSS + cmp cl,0x59 ja wrongtime - shl ebx,4 - cmp bl,0x90 + shl ecx,4 + cmp cl,0x90 ja wrongtime - shr ebx,4 - mov dx,0x70 + shr ecx,4 + + mov edx,0x70 call startstopclk dec edx - cmp ecx,3 - je setalarm + cmp ebx,3 + + je setalarm xor eax,eax ;al=0-set seconds out dx,al inc edx - mov al,bl + mov al,cl out dx,al dec edx mov al,2 ;set minutes out dx,al inc edx - mov al,bh + mov al,ch out dx,al dec edx mov al,4 ;set hours out dx,al inc edx - shr ebx,8 - mov al,bh + shr ecx,8 + mov al,ch out dx,al jmp endsettime setalarm: mov al,1 ;set seconds for al. out dx,al inc edx - mov al,bl + mov al,cl out dx,al dec edx mov al,3 ;set minutes for al. out dx,al inc edx - mov al,bh + mov al,ch out dx,al dec edx mov al,5 ;set hours for al. out dx,al inc edx - shr ebx,8 - mov al,bh + shr ecx,8 + mov al,ch out dx,al dec edx mov al,0x0b ;enable irq's @@ -180,15 +182,15 @@ sys_settime: dec edx call startstopclk sti - mov [esp+36],dword 0 + and [esp+36-4],dword 0 ret bat_low: sti - mov [esp+36],dword 2 + mov [esp+36-4],dword 2 ret wrongtime: sti - mov [esp+36],dword 1 + mov [esp+36-4],dword 1 ret startstopclk: diff --git a/kernel/branches/net/init.inc b/kernel/branches/net/init.inc index 54aa7b5978..5c91ea00cb 100644 --- a/kernel/branches/net/init.inc +++ b/kernel/branches/net/init.inc @@ -114,9 +114,9 @@ proc init_mem mov edx, (OS_BASE/4096) jmp .set @@: - cmp edx, (HEAP_BASE+HEAP_MIN_SIZE)/4096 + cmp edx, (HEAP_BASE-OS_BASE+HEAP_MIN_SIZE)/4096 jae .set - mov edx, (HEAP_BASE+HEAP_MIN_SIZE)/4096 + mov edx, (HEAP_BASE-OS_BASE+HEAP_MIN_SIZE)/4096 .set: mov [pg_data.kernel_pages-OS_BASE], edx shr edx, 10 @@ -205,19 +205,18 @@ proc init_page_map mov edi, [ebx] shr edi, 12 ; edi = first page mov eax, edi - neg eax shr edi, 5 + shl edi, 2 add edi, sys_pgmap-OS_BASE and eax, 31 jz .startok - sub ecx, eax + add ecx, eax + sub ecx, 32 jbe .onedword push ecx mov ecx, eax - xor eax, eax - inc eax + or eax, -1 shl eax, cl - dec eax or [edi], eax add edi, 4 pop ecx @@ -228,15 +227,17 @@ proc init_page_map rep stosd pop ecx and ecx, 31 - not eax + neg eax shl eax, cl + dec eax or [edi], eax jmp .next .onedword: - add ecx, eax + add ecx, 32 + sub ecx, eax @@: - dec eax bts [edi], eax + inc eax loop @b .next: add ebx, 20 diff --git a/kernel/branches/net/kernel.asm b/kernel/branches/net/kernel.asm index f441867fe1..fbfdda5862 100644 --- a/kernel/branches/net/kernel.asm +++ b/kernel/branches/net/kernel.asm @@ -17,7 +17,8 @@ ;; Sergey Semyonov (Serge) ;; Johnny_B ;; SPraid (simba) -;; hidnplayr +;; Hidnplayr +;; Alexey Teplov () ;; ;; Data in this file was originally part of MenuetOS project which is ;; distributed under the terms of GNU GPL. It is modified and redistributed as @@ -59,26 +60,27 @@ include 'macros.inc' $Revision$ -USE_COM_IRQ equ 1 ; make irq 3 and irq 4 available for PCI devices +USE_COM_IRQ equ 1 ; make irq 3 and irq 4 available for PCI devices ; Enabling the next line will enable serial output console -debug_com_base equ 0x3f8 ; 0x3f8 is com1, 0x2f8 is com2, 0x3e8 is com3, 0x2e8 is com4, no irq's are used +debug_com_base equ 0x3f8 ; 0x3f8 is com1, 0x2f8 is com2, 0x3e8 is com3, 0x2e8 is com4, no irq's are used include "proc32.inc" include "kglobals.inc" lang fix en include "const.inc" -max_processes equ 255 -tss_step equ (128+8192) ; tss & i/o - 65535 ports, * 256=557056*4 +max_processes equ 255 +tss_step equ (128+8192) ; tss & i/o - 65535 ports, * 256=557056*4 -os_stack equ (os_data_l-gdts) ; GDTs +os_stack equ (os_data_l-gdts) ; GDTs os_code equ (os_code_l-gdts) graph_data equ (3+graph_data_l-gdts) -tss0 equ (tss0_l-gdts) +tss0 equ (tss0_l-gdts) app_code equ (3+app_code_l-gdts) app_data equ (3+app_data_l-gdts) +app_tls equ (3+tls_data_l-gdts) pci_code_sel equ (pci_code_32-gdts) pci_data_sel equ (pci_data_32-gdts) @@ -114,10 +116,10 @@ pci_data_sel equ (pci_data_32-gdts) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; use16 - org 0x0 - jmp start_of_code + org 0x0 + jmp start_of_code -version db 'Kolibri OS version 0.7.5.0 ',13,10,13,10,0 +version db 'Kolibri OS version 0.7.7.0+ ',13,10,13,10,0 include "boot/bootstr.inc" ; language-independent boot messages include "boot/preboot.inc" @@ -126,10 +128,10 @@ if lang eq en include "boot/booteng.inc" ; english system boot messages else if lang eq ru include "boot/bootru.inc" ; russian system boot messages -include "boot/ru.inc" ; Russian font +include "boot/ru.inc" ; Russian font else if lang eq et include "boot/bootet.inc" ; estonian system boot messages -include "boot/et.inc" ; Estonian font +include "boot/et.inc" ; Estonian font else include "boot/bootge.inc" ; german system boot messages end if @@ -147,58 +149,58 @@ include "detect/biosdisk.inc" ; CR0 Flags - Protected mode and Paging - mov ecx, CR0_PE + mov ecx, CR0_PE ; Enabling 32 bit protected mode - sidt [cs:old_ints_h] + sidt [cs:old_ints_h] - cli ; disable all irqs - cld - mov al,255 ; mask all irqs - out 0xa1,al - out 0x21,al - l.5: in al, 0x64 ; Enable A20 - test al, 2 - jnz l.5 - mov al, 0xD1 - out 0x64, al - l.6: in al, 0x64 - test al, 2 - jnz l.6 - mov al, 0xDF - out 0x60, al - l.7: in al, 0x64 - test al, 2 - jnz l.7 - mov al, 0xFF - out 0x64, al + cli ; disable all irqs + cld + mov al,255 ; mask all irqs + out 0xa1,al + out 0x21,al + l.5: in al, 0x64 ; Enable A20 + test al, 2 + jnz l.5 + mov al, 0xD1 + out 0x64, al + l.6: in al, 0x64 + test al, 2 + jnz l.6 + mov al, 0xDF + out 0x60, al + l.7: in al, 0x64 + test al, 2 + jnz l.7 + mov al, 0xFF + out 0x64, al - lgdt [cs:tmp_gdt] ; Load GDT - mov eax, cr0 ; protected mode - or eax, ecx - and eax, 10011111b *65536*256 + 0xffffff ; caching enabled - mov cr0, eax - jmp pword os_code:B32 ; jmp to enable 32 bit mode + lgdt [cs:tmp_gdt] ; Load GDT + mov eax, cr0 ; protected mode + or eax, ecx + and eax, 10011111b *65536*256 + 0xffffff ; caching enabled + mov cr0, eax + jmp pword os_code:B32 ; jmp to enable 32 bit mode align 8 tmp_gdt: - dw 23 - dd tmp_gdt+0x10000 - dw 0 + dw 23 + dd tmp_gdt+0x10000 + dw 0 - dw 0xffff - dw 0x0000 - db 0x00 - dw 11011111b *256 +10011010b - db 0x00 + dw 0xffff + dw 0x0000 + db 0x00 + dw 11011111b *256 +10011010b + db 0x00 - dw 0xffff - dw 0x0000 - db 0x00 - dw 11011111b *256 +10010010b - db 0x00 + dw 0xffff + dw 0x0000 + db 0x00 + dw 11011111b *256 +10010010b + db 0x00 include "data16.inc" @@ -207,65 +209,65 @@ org $+0x10000 align 4 B32: - mov ax,os_stack ; Selector for os - mov ds,ax - mov es,ax - mov fs,ax - mov gs,ax - mov ss,ax - mov esp,0x3ec00 ; Set stack + mov ax,os_stack ; Selector for os + mov ds,ax + mov es,ax + mov fs,ax + mov gs,ax + mov ss,ax + mov esp,0x3ec00 ; Set stack ; CLEAR 0x280000 - HEAP_BASE - xor eax,eax - mov edi,0x280000 - mov ecx,(HEAP_BASE-OS_BASE-0x280000) / 4 - cld - rep stosd + xor eax,eax + mov edi,0x280000 + mov ecx,(HEAP_BASE-OS_BASE-0x280000) / 4 + cld + rep stosd - mov edi,0x40000 - mov ecx,(0x90000-0x40000)/4 - rep stosd + mov edi,0x40000 + mov ecx,(0x90000-0x40000)/4 + rep stosd ; CLEAR KERNEL UNDEFINED GLOBALS - mov edi, endofcode-OS_BASE - mov ecx, (uglobals_size/4)+4 - rep stosd + mov edi, endofcode-OS_BASE + mov ecx, (uglobals_size/4)+4 + rep stosd ; SAVE & CLEAR 0-0xffff - xor esi, esi - mov edi,0x2F0000 - mov ecx,0x10000 / 4 - rep movsd - mov edi,0x1000 - mov ecx,0xf000 / 4 - rep stosd + xor esi, esi + mov edi,0x2F0000 + mov ecx,0x10000 / 4 + rep movsd + mov edi,0x1000 + mov ecx,0xf000 / 4 + rep stosd - call test_cpu - bts [cpu_caps-OS_BASE], CAPS_TSC ;force use rdtsc + call test_cpu + bts [cpu_caps-OS_BASE], CAPS_TSC ;force use rdtsc - call init_BIOS32 + call init_BIOS32 ; MEMORY MODEL - call mem_test - call init_mem - call init_page_map + call mem_test + call init_mem + call init_page_map ; ENABLE PAGING - mov eax, sys_pgdir-OS_BASE - mov cr3, eax + mov eax, sys_pgdir-OS_BASE + mov cr3, eax - mov eax,cr0 - or eax,CR0_PG+CR0_WP - mov cr0,eax + mov eax,cr0 + or eax,CR0_PG+CR0_WP + mov cr0,eax - lgdt [gdts] - jmp pword os_code:high_code + lgdt [gdts] + jmp pword os_code:high_code align 4 -bios32_entry dd ? -tmp_page_tabs dd ? +bios32_entry dd ? +tmp_page_tabs dd ? use16 org $-0x10000 @@ -281,45 +283,46 @@ org OS_BASE+$ align 4 high_code: - mov ax,os_stack - mov bx,app_data - mov ss,ax - add esp, OS_BASE + mov ax, os_stack + mov bx, app_data + mov cx, app_tls + mov ss, ax + add esp, OS_BASE - mov ds,bx - mov es,bx - mov fs,bx - mov gs,bx + mov ds, bx + mov es, bx + mov fs, cx + mov gs, bx - bt [cpu_caps], CAPS_PGE - jnc @F + bt [cpu_caps], CAPS_PGE + jnc @F - or dword [sys_pgdir+(OS_BASE shr 20)], PG_GLOBAL + or dword [sys_pgdir+(OS_BASE shr 20)], PG_GLOBAL - mov ebx, cr4 - or ebx, CR4_PGE - mov cr4, ebx + mov ebx, cr4 + or ebx, CR4_PGE + mov cr4, ebx @@: - xor eax, eax - mov dword [sys_pgdir], eax - mov dword [sys_pgdir+4], eax + xor eax, eax + mov dword [sys_pgdir], eax + mov dword [sys_pgdir+4], eax - mov eax, cr3 - mov cr3, eax ; flush TLB + mov eax, cr3 + mov cr3, eax ; flush TLB ; SAVE REAL MODE VARIABLES - mov ax, [BOOT_VAR + 0x9031] - mov [IDEContrRegsBaseAddr], ax + mov ax, [BOOT_VAR + 0x9031] + mov [IDEContrRegsBaseAddr], ax ; --------------- APM --------------------- ; init selectors - mov ebx, [BOOT_VAR+0x9040] ; offset of APM entry point - movzx eax, word [BOOT_VAR+0x9050] ; real-mode segment base address of - ; protected-mode 32-bit code segment - movzx ecx, word [BOOT_VAR+0x9052] ; real-mode segment base address of - ; protected-mode 16-bit code segment - movzx edx, word [BOOT_VAR+0x9054] ; real-mode segment base address of - ; protected-mode 16-bit data segment + mov ebx,[BOOT_VAR+0x9040] ; offset of APM entry point + movzx eax,word [BOOT_VAR+0x9050] ; real-mode segment base address of + ; protected-mode 32-bit code segment + movzx ecx,word [BOOT_VAR+0x9052] ; real-mode segment base address of + ; protected-mode 16-bit code segment + movzx edx,word [BOOT_VAR+0x9054] ; real-mode segment base address of + ; protected-mode 16-bit data segment shl eax, 4 mov [dword apm_code_32 + 2], ax @@ -342,242 +345,267 @@ high_code: mov eax, [BOOT_VAR + 0x9044] ; version & flags mov [apm_vf], eax ; ----------------------------------------- -; movzx eax,byte [BOOT_VAR+0x9010] ; mouse port +; movzx eax,byte [BOOT_VAR+0x9010] ; mouse port ; mov [0xF604],byte 1 ;al - mov al, [BOOT_VAR+0x901F] ; DMA access - mov [allow_dma_access], al - mov al,[BOOT_VAR+0x9000] ; bpp - mov [ScreenBPP],al + mov al, [BOOT_VAR+0x901F] ; DMA access + mov [allow_dma_access], al + movzx eax, byte [BOOT_VAR+0x9000] ; bpp + mov [ScreenBPP],al - movzx eax,word [BOOT_VAR+0x900A] ; X max - dec eax - mov [Screen_Max_X],eax - mov [screen_workarea.right],eax - movzx eax,word [BOOT_VAR+0x900C] ; Y max - dec eax - mov [Screen_Max_Y],eax - mov [screen_workarea.bottom],eax - movzx eax,word [BOOT_VAR+0x9008] ; screen mode - mov [SCR_MODE],eax - mov eax,[BOOT_VAR+0x9014] ; Vesa 1.2 bnk sw add - mov [BANK_SWITCH],eax - mov [BytesPerScanLine],word 640*4 ; Bytes PerScanLine - cmp [SCR_MODE],word 0x13 ; 320x200 - je @f - cmp [SCR_MODE],word 0x12 ; VGA 640x480 - je @f - mov ax,[BOOT_VAR+0x9001] ; for other modes - mov [BytesPerScanLine],ax + mov [_display.bpp], eax + mov [_display.vrefresh], 60 + mov [_display.disable_mouse], __sys_disable_mouse + + movzx eax,word [BOOT_VAR+0x900A] ; X max + mov [_display.width], eax + dec eax + mov [Screen_Max_X],eax + mov [screen_workarea.right],eax + movzx eax,word [BOOT_VAR+0x900C] ; Y max + mov [_display.height], eax + dec eax + mov [Screen_Max_Y],eax + mov [screen_workarea.bottom],eax + movzx eax,word [BOOT_VAR+0x9008] ; screen mode + mov [SCR_MODE],eax + mov eax,[BOOT_VAR+0x9014] ; Vesa 1.2 bnk sw add + mov [BANK_SWITCH],eax + mov [BytesPerScanLine],word 640*4 ; Bytes PerScanLine + cmp [SCR_MODE],word 0x13 ; 320x200 + je @f + cmp [SCR_MODE],word 0x12 ; VGA 640x480 + je @f + movzx eax, word[BOOT_VAR+0x9001] ; for other modes + mov [BytesPerScanLine],ax + mov [_display.pitch], eax @@: - mov esi, BOOT_VAR+0x9080 - movzx ecx, byte [esi-1] - mov [NumBiosDisks], ecx - mov edi, BiosDisksData - rep movsd + mov eax, [_display.width] + mul [_display.height] + mov [_WinMapSize], eax + + mov esi, BOOT_VAR+0x9080 + movzx ecx, byte [esi-1] + mov [NumBiosDisks], ecx + mov edi, BiosDisksData + rep movsd ; GRAPHICS ADDRESSES - mov byte [BOOT_VAR+0x901e],0x0 - mov eax,[BOOT_VAR+0x9018] - mov [LFBAddress],eax + and byte [BOOT_VAR+0x901e],0x0 + mov eax,[BOOT_VAR+0x9018] + mov [LFBAddress],eax - cmp [SCR_MODE],word 0100000000000000b - jge setvesa20 - cmp [SCR_MODE],word 0x13 - je v20ga32 - mov [PUTPIXEL],dword Vesa12_putpixel24 ; Vesa 1.2 - mov [GETPIXEL],dword Vesa12_getpixel24 - cmp [ScreenBPP],byte 24 - jz ga24 - mov [PUTPIXEL],dword Vesa12_putpixel32 - mov [GETPIXEL],dword Vesa12_getpixel32 + cmp [SCR_MODE],word 0100000000000000b + jge setvesa20 + cmp [SCR_MODE],word 0x13 + je v20ga32 + mov [PUTPIXEL],dword Vesa12_putpixel24 ; Vesa 1.2 + mov [GETPIXEL],dword Vesa12_getpixel24 + cmp [ScreenBPP],byte 24 + jz ga24 + mov [PUTPIXEL],dword Vesa12_putpixel32 + mov [GETPIXEL],dword Vesa12_getpixel32 ga24: - jmp v20ga24 + jmp v20ga24 setvesa20: - mov [PUTPIXEL],dword Vesa20_putpixel24 ; Vesa 2.0 - mov [GETPIXEL],dword Vesa20_getpixel24 - cmp [ScreenBPP],byte 24 - jz v20ga24 + mov [PUTPIXEL],dword Vesa20_putpixel24 ; Vesa 2.0 + mov [GETPIXEL],dword Vesa20_getpixel24 + cmp [ScreenBPP],byte 24 + jz v20ga24 v20ga32: - mov [PUTPIXEL],dword Vesa20_putpixel32 - mov [GETPIXEL],dword Vesa20_getpixel32 + mov [PUTPIXEL],dword Vesa20_putpixel32 + mov [GETPIXEL],dword Vesa20_getpixel32 v20ga24: - cmp [SCR_MODE],word 0x12 ; 16 C VGA 640x480 - jne no_mode_0x12 - mov [PUTPIXEL],dword VGA_putpixel - mov [GETPIXEL],dword Vesa20_getpixel32 + cmp [SCR_MODE],word 0x12 ; 16 C VGA 640x480 + jne no_mode_0x12 + mov [PUTPIXEL],dword VGA_putpixel + mov [GETPIXEL],dword Vesa20_getpixel32 no_mode_0x12: ; -------- Fast System Call init ---------- ; Intel SYSENTER/SYSEXIT (AMD CPU support it too) - bt [cpu_caps], CAPS_SEP - jnc .SEnP ; SysEnter not Present - xor edx, edx - mov ecx, MSR_SYSENTER_CS - mov eax, os_code - wrmsr - mov ecx, MSR_SYSENTER_ESP + bt [cpu_caps], CAPS_SEP + jnc .SEnP ; SysEnter not Present + xor edx, edx + mov ecx, MSR_SYSENTER_CS + mov eax, os_code + wrmsr + mov ecx, MSR_SYSENTER_ESP ; mov eax, sysenter_stack ; Check it - xor eax, eax - wrmsr - mov ecx, MSR_SYSENTER_EIP - mov eax, sysenter_entry - wrmsr + xor eax, eax + wrmsr + mov ecx, MSR_SYSENTER_EIP + mov eax, sysenter_entry + wrmsr .SEnP: ; AMD SYSCALL/SYSRET - cmp byte[cpu_vendor], 'A' - jne .noSYSCALL - mov eax, 0x80000001 - cpuid - test edx, 0x800 ; bit_11 - SYSCALL/SYSRET support - jz .noSYSCALL - mov ecx, MSR_AMD_EFER - rdmsr - or eax, 1 ; bit_0 - System Call Extension (SCE) - wrmsr + cmp byte[cpu_vendor], 'A' + jne .noSYSCALL + mov eax, 0x80000001 + cpuid + test edx, 0x800 ; bit_11 - SYSCALL/SYSRET support + jz .noSYSCALL + mov ecx, MSR_AMD_EFER + rdmsr + or eax, 1 ; bit_0 - System Call Extension (SCE) + wrmsr - ; !!!! It`s dirty hack, fix it !!! - ; Bits of EDX : - ; Bit 31–16 During the SYSRET instruction, this field is copied into the CS register - ; and the contents of this field, plus 8, are copied into the SS register. - ; Bit 15–0 During the SYSCALL instruction, this field is copied into the CS register - ; and the contents of this field, plus 8, are copied into the SS register. + ; !!!! It`s dirty hack, fix it !!! + ; Bits of EDX : + ; Bit 31–16 During the SYSRET instruction, this field is copied into the CS register + ; and the contents of this field, plus 8, are copied into the SS register. + ; Bit 15–0 During the SYSCALL instruction, this field is copied into the CS register + ; and the contents of this field, plus 8, are copied into the SS register. - ; mov edx, (os_code + 16) * 65536 + os_code - mov edx, 0x1B0008 + ; mov edx, (os_code + 16) * 65536 + os_code + mov edx, 0x1B0008 - mov eax, syscall_entry - mov ecx, MSR_AMD_STAR - wrmsr + mov eax, syscall_entry + mov ecx, MSR_AMD_STAR + wrmsr .noSYSCALL: ; ----------------------------------------- + stdcall alloc_page + stdcall map_page, tss-0xF80, eax, PG_SW + stdcall alloc_page + inc eax + mov [SLOT_BASE+256+APPDATA.io_map], eax + stdcall map_page, tss+0x80, eax, PG_SW + stdcall alloc_page + inc eax + mov dword [SLOT_BASE+256+APPDATA.io_map+4], eax + stdcall map_page, tss+0x1080, eax, PG_SW ; LOAD IDT - call build_interrupt_table ;lidt is executed - ;lidt [idtreg] + call build_interrupt_table ;lidt is executed + ;lidt [idtreg] - call init_kernel_heap - stdcall kernel_alloc, RING0_STACK_SIZE+512 - mov [os_stack_seg], eax + call init_kernel_heap + stdcall kernel_alloc, RING0_STACK_SIZE+512 + mov [os_stack_seg], eax - lea esp, [eax+RING0_STACK_SIZE] + lea esp, [eax+RING0_STACK_SIZE] - mov [tss._ss0], os_stack - mov [tss._esp0], esp - mov [tss._esp], esp - mov [tss._cs],os_code - mov [tss._ss],os_stack - mov [tss._ds],app_data - mov [tss._es],app_data - mov [tss._fs],app_data - mov [tss._gs],app_data - mov [tss._io],128 + mov [tss._ss0], os_stack + mov [tss._esp0], esp + mov [tss._esp], esp + mov [tss._cs],os_code + mov [tss._ss],os_stack + mov [tss._ds],app_data + mov [tss._es],app_data + mov [tss._fs],app_data + mov [tss._gs],app_data + mov [tss._io],128 ;Add IO access table - bit array of permitted ports - mov edi, tss._io_map_0 - xor eax, eax - not eax - mov ecx, 8192/4 - rep stosd ; access to 4096*8=65536 ports + mov edi, tss._io_map_0 + xor eax, eax + not eax + mov ecx, 8192/4 + rep stosd ; access to 4096*8=65536 ports - mov ax,tss0 - ltr ax + mov ax,tss0 + ltr ax - mov [LFBSize], 0x800000 - call init_LFB - call init_fpu - call init_malloc + mov [LFBSize], 0x800000 + call init_LFB + call init_fpu + call init_malloc - stdcall alloc_kernel_space, 0x51000 - mov [default_io_map], eax + stdcall alloc_kernel_space, 0x51000 + mov [default_io_map], eax - add eax, 0x2000 - mov [ipc_tmp], eax - mov ebx, 0x1000 + add eax, 0x2000 + mov [ipc_tmp], eax + mov ebx, 0x1000 - add eax, 0x40000 - mov [proc_mem_map], eax + add eax, 0x40000 + mov [proc_mem_map], eax - add eax, 0x8000 - mov [proc_mem_pdir], eax + add eax, 0x8000 + mov [proc_mem_pdir], eax - add eax, ebx - mov [proc_mem_tab], eax + add eax, ebx + mov [proc_mem_tab], eax - add eax, ebx - mov [tmp_task_pdir], eax + add eax, ebx + mov [tmp_task_pdir], eax - add eax, ebx - mov [tmp_task_ptab], eax + add eax, ebx + mov [tmp_task_ptab], eax - add eax, ebx - mov [ipc_pdir], eax + add eax, ebx + mov [ipc_pdir], eax - add eax, ebx - mov [ipc_ptab], eax + add eax, ebx + mov [ipc_ptab], eax - stdcall kernel_alloc, (unpack.LZMA_BASE_SIZE+(unpack.LZMA_LIT_SIZE shl \ - (unpack.lc+unpack.lp)))*4 + stdcall kernel_alloc, (unpack.LZMA_BASE_SIZE+(unpack.LZMA_LIT_SIZE shl \ + (unpack.lc+unpack.lp)))*4 - mov [unpack.p], eax + mov [unpack.p], eax - call init_events - mov eax, srv.fd-SRV_FD_OFFSET - mov [srv.fd], eax - mov [srv.bk], eax + call init_events + mov eax, srv.fd-SRV_FD_OFFSET + mov [srv.fd], eax + mov [srv.bk], eax - mov edi, irq_tab - xor eax, eax - mov ecx, 16 - rep stosd + mov edi, irq_tab + xor eax, eax + mov ecx, 16 + rep stosd ;Set base of graphic segment to linear address of LFB - mov eax,[LFBAddress] ; set for gs - mov [graph_data_l+2],ax - shr eax,16 - mov [graph_data_l+4],al - mov [graph_data_l+7],ah + mov eax,[LFBAddress] ; set for gs + mov [graph_data_l+2],ax + shr eax,16 + mov [graph_data_l+4],al + mov [graph_data_l+7],ah - mov [CURRENT_TASK],dword 1 - mov [TASK_COUNT],dword 1 - mov [TASK_BASE],dword TASK_DATA - mov [current_slot], SLOT_BASE+256 + stdcall kernel_alloc, [_WinMapSize] + mov [_WinMapAddress], eax + + xor eax,eax + inc eax + mov [CURRENT_TASK],eax ;dword 1 + mov [TASK_COUNT],eax ;dword 1 + mov [TASK_BASE],dword TASK_DATA + mov [current_slot], SLOT_BASE+256 ; set background - xor eax,eax - inc eax - mov [BgrDrawMode],eax - mov [BgrDataWidth],eax - mov [BgrDataHeight],eax - mov [mem_BACKGROUND], 4 - mov [img_background], static_background_data - mov [SLOT_BASE + 256 + APPDATA.dir_table], sys_pgdir - OS_BASE + mov [BgrDrawMode],eax + mov [BgrDataWidth],eax + mov [BgrDataHeight],eax + mov [mem_BACKGROUND], 4 + mov [img_background], static_background_data + + mov [SLOT_BASE + 256 + APPDATA.dir_table], sys_pgdir - OS_BASE ; REDIRECT ALL IRQ'S TO INT'S 0x20-0x2f - call rerouteirqs + call rerouteirqs ; Initialize system V86 machine - call init_sys_v86 + call init_sys_v86 ; TIMER SET TO 1/100 S - mov al,0x34 ; set to 100Hz - out 0x43,al - mov al,0x9b ; lsb 1193180 / 1193 - out 0x40,al - mov al,0x2e ; msb - out 0x40,al + mov al,0x34 ; set to 100Hz + out 0x43,al + mov al,0x9b ; lsb 1193180 / 1193 + out 0x40,al + mov al,0x2e ; msb + out 0x40,al ; Enable timer IRQ (IRQ0) and hard drives IRQs (IRQ14, IRQ15) ; they are used: when partitions are scanned, hd_read relies on timer ; Also enable IRQ2, because in some configurations ; IRQs from slave controller are not delivered until IRQ2 on master is enabled - mov al, 0xFA - out 0x21, al - mov al, 0x3F - out 0xA1, al + mov al, 0xFA + out 0x21, al + mov al, 0x3F + out 0xA1, al ;!!!!!!!!!!!!!!!!!!!!!!!!!! include 'detect/disks.inc' @@ -593,7 +621,7 @@ include 'boot/rdload.inc' ; mov [dma_hdd],1 ; CALCULATE FAT CHAIN FOR RAMDISK - call calculatefatchain + call calculatefatchain ; LOAD VMODE DRIVER @@ -601,255 +629,260 @@ include 'boot/rdload.inc' include 'vmodeld.inc' ;!!!!!!!!!!!!!!!!!!!!!!! +if 0 mov ax,[OS_BASE+0x10000+bx_from_load] - cmp ax,'r1' ; if using not ram disk, then load librares and parameters {SPraid.simba} + cmp ax,'r1' ; if using not ram disk, then load librares and parameters {SPraid.simba} je no_lib_load ; LOADING LIBRARES - stdcall dll.Load,@IMPORT ; loading librares for kernel (.obj files) - call load_file_parse_table ; prepare file parse table - call set_kernel_conf ; configure devices and gui + stdcall dll.Load,@IMPORT ; loading librares for kernel (.obj files) + call load_file_parse_table ; prepare file parse table + call set_kernel_conf ; configure devices and gui no_lib_load: +end if ; LOAD FONTS I and II - stdcall read_file, char, FONT_I, 0, 2304 - stdcall read_file, char2, FONT_II, 0, 2560 + stdcall read_file, char, FONT_I, 0, 2304 + stdcall read_file, char2, FONT_II, 0, 2560 - mov esi,boot_fonts - call boot_log + mov esi,boot_fonts + call boot_log ; PRINT AMOUNT OF MEMORY - mov esi, boot_memdetect - call boot_log + mov esi, boot_memdetect + call boot_log - movzx ecx, word [boot_y] - or ecx, (10+29*6) shl 16 ; "Determining amount of memory" - sub ecx, 10 - mov edx, 0xFFFFFF - mov ebx, [MEM_AMOUNT] - shr ebx, 20 - mov edi, 1 - mov eax, 0x00040000 - call display_number_force + movzx ecx, word [boot_y] + or ecx, (10+29*6) shl 16 ; "Determining amount of memory" + sub ecx, 10 + mov edx, 0xFFFFFF + mov ebx, [MEM_AMOUNT] + shr ebx, 20 + xor edi,edi + mov eax, 0x00040000 + inc edi + call display_number_force ; BUILD SCHEDULER - call build_scheduler ; sys32.inc + call build_scheduler ; sys32.inc - mov esi,boot_devices - call boot_log + mov esi,boot_devices + call boot_log - mov [pci_access_enabled],1 + mov [pci_access_enabled],1 ; SET PRELIMINARY WINDOW STACK AND POSITIONS - mov esi,boot_windefs - call boot_log - call setwindowdefaults + mov esi,boot_windefs + call boot_log + call set_window_defaults ; SET BACKGROUND DEFAULTS - mov esi,boot_bgr - call boot_log - call init_background - call calculatebackground + mov esi,boot_bgr + call boot_log + call init_background + call calculatebackground ; RESERVE SYSTEM IRQ'S JA PORT'S - mov esi,boot_resirqports - call boot_log - call reserve_irqs_ports + mov esi,boot_resirqports + call boot_log + call reserve_irqs_ports ; SET PORTS FOR IRQ HANDLERS - mov esi,boot_setrports - call boot_log - ;call setirqreadports + mov esi,boot_setrports + call boot_log + ;call setirqreadports ; SET UP OS TASK - mov esi,boot_setostask - call boot_log + mov esi,boot_setostask + call boot_log - xor eax, eax - mov dword [SLOT_BASE+APPDATA.fpu_state], fpu_data - mov dword [SLOT_BASE+APPDATA.exc_handler], eax - mov dword [SLOT_BASE+APPDATA.except_mask], eax + xor eax, eax + mov dword [SLOT_BASE+APPDATA.fpu_state], fpu_data + mov dword [SLOT_BASE+APPDATA.exc_handler], eax + mov dword [SLOT_BASE+APPDATA.except_mask], eax - ; name for OS/IDLE process + ; name for OS/IDLE process - mov dword [SLOT_BASE+256+APPDATA.app_name], dword 'OS/I' - mov dword [SLOT_BASE+256+APPDATA.app_name+4], dword 'DLE ' - mov edi, [os_stack_seg] - mov dword [SLOT_BASE+256+APPDATA.pl0_stack], edi - add edi, 0x2000-512 - mov dword [SLOT_BASE+256+APPDATA.fpu_state], edi - mov dword [SLOT_BASE+256+APPDATA.saved_esp0], edi ; just for case - mov dword [SLOT_BASE+256+APPDATA.io_map],\ - (tss._io_map_0-OS_BASE+PG_MAP) - mov dword [SLOT_BASE+256+APPDATA.io_map+4],\ - (tss._io_map_1-OS_BASE+PG_MAP) + mov dword [SLOT_BASE+256+APPDATA.app_name], dword 'OS/I' + mov dword [SLOT_BASE+256+APPDATA.app_name+4], dword 'DLE ' + mov edi, [os_stack_seg] + mov dword [SLOT_BASE+256+APPDATA.pl0_stack], edi + add edi, 0x2000-512 + mov dword [SLOT_BASE+256+APPDATA.fpu_state], edi + mov dword [SLOT_BASE+256+APPDATA.saved_esp0], edi ; just for case + ; [SLOT_BASE+256+APPDATA.io_map] was set earlier - mov esi, fpu_data - mov ecx, 512/4 - cld - rep movsd + mov esi, fpu_data + mov ecx, 512/4 + cld + rep movsd - mov dword [SLOT_BASE+256+APPDATA.exc_handler], eax - mov dword [SLOT_BASE+256+APPDATA.except_mask], eax + mov dword [SLOT_BASE+256+APPDATA.exc_handler], eax + mov dword [SLOT_BASE+256+APPDATA.except_mask], eax - mov ebx, SLOT_BASE+256+APP_OBJ_OFFSET - mov dword [SLOT_BASE+256+APPDATA.fd_obj], ebx - mov dword [SLOT_BASE+256+APPDATA.bk_obj], ebx + mov ebx, SLOT_BASE+256+APP_OBJ_OFFSET + mov dword [SLOT_BASE+256+APPDATA.fd_obj], ebx + mov dword [SLOT_BASE+256+APPDATA.bk_obj], ebx - mov dword [SLOT_BASE+256+APPDATA.cur_dir], sysdir_path + mov dword [SLOT_BASE+256+APPDATA.cur_dir], sysdir_path + mov dword [SLOT_BASE+256+APPDATA.tls_base], eax - ; task list - mov [CURRENT_TASK],dword 1 - mov [TASK_COUNT],dword 1 - mov [current_slot], SLOT_BASE+256 - mov [TASK_BASE],dword TASK_DATA - mov [TASK_DATA+TASKDATA.wnd_number], 1 ; on screen number - mov [TASK_DATA+TASKDATA.pid], 1 ; process id number - mov [TASK_DATA+TASKDATA.mem_start], 0 ; process base address + ; task list + mov dword [TASK_DATA+TASKDATA.mem_start],eax ; process base address + inc eax + mov dword [CURRENT_TASK],eax + mov dword [TASK_COUNT],eax + mov [current_slot], SLOT_BASE+256 + mov [TASK_BASE],dword TASK_DATA + mov byte[TASK_DATA+TASKDATA.wnd_number],al ; on screen number + mov dword [TASK_DATA+TASKDATA.pid], eax ; process id number - call init_cursors - mov eax, [def_cursor] - mov [SLOT_BASE+APPDATA.cursor],eax - mov [SLOT_BASE+APPDATA.cursor+256],eax + call init_display + mov eax, [def_cursor] + mov [SLOT_BASE+APPDATA.cursor],eax + mov [SLOT_BASE+APPDATA.cursor+256],eax ; READ TSC / SECOND - mov esi,boot_tsc - call boot_log - cli - rdtsc ;call _rdtsc - mov ecx,eax - mov esi,250 ; wait 1/4 a second - call delay_ms - rdtsc ;call _rdtsc - sti - sub eax,ecx - shl eax,2 - mov [CPU_FREQ],eax ; save tsc / sec + mov esi,boot_tsc + call boot_log + cli + rdtsc ;call _rdtsc + mov ecx,eax + mov esi,250 ; wait 1/4 a second + call delay_ms + rdtsc ;call _rdtsc + sti + sub eax,ecx + shl eax,2 + mov [CPU_FREQ],eax ; save tsc / sec ; mov ebx, 1000000 ; div ebx ; ў®®ЎйҐ-в® Їа®Ё§ў®¤ЁвҐ«м­®бвм ў ¤ ­­®¬ Є®­ЄаҐв­®¬ ¬Ґб⥠; б®ўҐа襭­® ­ҐЄаЁвЁз­ , ­® зв®Ўл § вЄ­гвм «оЎЁвҐ«Ґ© ; ®ЇвЁ¬Ё§ЁагойЁе Є®¬ЇЁ«пв®а®ў џ‚“... - mov edx, 2251799814 - mul edx - shr edx, 19 - mov [stall_mcs], edx + mov edx, 2251799814 + mul edx + shr edx, 19 + mov [stall_mcs], edx ; PRINT CPU FREQUENCY - mov esi, boot_cpufreq - call boot_log + mov esi, boot_cpufreq + call boot_log - mov ebx, edx - movzx ecx, word [boot_y] - add ecx, (10+17*6) shl 16 - 10 ; 'CPU frequency is ' - mov edx, 0xFFFFFF - mov edi, 1 - mov eax, 0x00040000 - call display_number_force + mov ebx, edx + movzx ecx, word [boot_y] + add ecx, (10+17*6) shl 16 - 10 ; 'CPU frequency is ' + mov edx, 0xFFFFFF + xor edi,edi + mov eax, 0x00040000 + inc edi + call display_number_force ; SET VARIABLES - call set_variables + call set_variables ; SET MOUSE - ;call detect_devices - stdcall load_driver, szPS2MDriver + ;call detect_devices + stdcall load_driver, szPS2MDriver ; stdcall load_driver, szCOM_MDriver - mov esi,boot_setmouse - call boot_log - call setmouse + mov esi,boot_setmouse + call boot_log + call setmouse ; STACK AND FDC - call stack_init - call fdc_init + call stack_init + call fdc_init ; PALETTE FOR 320x200 and 640x480 16 col - cmp [SCR_MODE],word 0x12 - jne no_pal_vga - mov esi,boot_pal_vga - call boot_log - call paletteVGA + cmp [SCR_MODE],word 0x12 + jne no_pal_vga + mov esi,boot_pal_vga + call boot_log + call paletteVGA no_pal_vga: - cmp [SCR_MODE],word 0x13 - jne no_pal_ega - mov esi,boot_pal_ega - call boot_log - call palette320x200 + cmp [SCR_MODE],word 0x13 + jne no_pal_ega + mov esi,boot_pal_ega + call boot_log + call palette320x200 no_pal_ega: ; LOAD DEFAULT SKIN - call load_default_skin + call load_default_skin ;protect io permission map - mov esi, [default_io_map] - stdcall map_page,esi,(tss._io_map_0-OS_BASE), PG_MAP - add esi, 0x1000 - stdcall map_page,esi,(tss._io_map_1-OS_BASE), PG_MAP - - stdcall map_page,tss._io_map_0,\ - (tss._io_map_0-OS_BASE), PG_MAP - stdcall map_page,tss._io_map_1,\ - (tss._io_map_1-OS_BASE), PG_MAP + mov esi, [default_io_map] + stdcall map_page,esi,[SLOT_BASE+256+APPDATA.io_map], PG_MAP + add esi, 0x1000 + stdcall map_page,esi,[SLOT_BASE+256+APPDATA.io_map+4], PG_MAP + stdcall map_page,tss._io_map_0,\ + [SLOT_BASE+256+APPDATA.io_map], PG_MAP + stdcall map_page,tss._io_map_1,\ + [SLOT_BASE+256+APPDATA.io_map+4], PG_MAP ; LOAD FIRST APPLICATION - cli + cli - cmp byte [BOOT_VAR+0x9030],1 - jne no_load_vrr_m + cmp byte [BOOT_VAR+0x9030],1 + jne no_load_vrr_m - mov ebp, vrr_m - call fs_execute_from_sysdir + mov ebp, vrr_m + call fs_execute_from_sysdir - cmp eax,2 ; if vrr_m app found (PID=2) - je first_app_found +; cmp eax,2 ; if vrr_m app found (PID=2) + sub eax,2 + jz first_app_found no_load_vrr_m: - mov ebp, firstapp - call fs_execute_from_sysdir + mov ebp, firstapp + call fs_execute_from_sysdir - cmp eax,2 ; continue if a process has been loaded - je first_app_found +; cmp eax,2 ; continue if a process has been loaded + sub eax,2 + jz first_app_found - mov esi, boot_failed - call boot_log + mov esi, boot_failed + call boot_log - mov eax, 0xDEADBEEF ; otherwise halt - hlt + mov eax, 0xDEADBEEF ; otherwise halt + hlt first_app_found: - cli + cli - ;mov [TASK_COUNT],dword 2 - mov [CURRENT_TASK],dword 1 ; set OS task fisrt + ;mov [TASK_COUNT],dword 2 + push 1 + pop dword [CURRENT_TASK] ; set OS task fisrt ; SET KEYBOARD PARAMETERS - mov al, 0xf6 ; reset keyboard, scan enabled - call kb_write + mov al, 0xf6 ; reset keyboard, scan enabled + call kb_write - ; wait until 8042 is ready - xor ecx,ecx + ; wait until 8042 is ready + xor ecx,ecx @@: - in al,64h - and al,00000010b - loopnz @b + in al,64h + and al,00000010b + loopnz @b ; mov al, 0xED ; svetodiody - only for testing! ; call kb_write @@ -858,14 +891,14 @@ first_app_found: ; call kb_write ; call kb_read - mov al, 0xF3 ; set repeat rate & delay - call kb_write + mov al, 0xF3 ; set repeat rate & delay + call kb_write ; call kb_read - mov al, 0 ; 30 250 ;00100010b ; 24 500 ;00100100b ; 20 500 - call kb_write + mov al, 0 ; 30 250 ;00100010b ; 24 500 ;00100100b ; 20 500 + call kb_write ; call kb_read ;// mike.dld [ - call set_lights + call set_lights ;// mike.dld ] @@ -873,39 +906,39 @@ first_app_found: if defined debug_com_base - ; enable Divisor latch + ; enable Divisor latch - mov dx, debug_com_base+3 - mov al, 1 shl 7 - out dx, al + mov dx, debug_com_base+3 + mov al, 1 shl 7 + out dx, al - ; Set speed to 115200 baud (max speed) + ; Set speed to 115200 baud (max speed) - mov dx, debug_com_base - mov al, 0x01 - out dx, al + mov dx, debug_com_base + mov al, 0x01 + out dx, al - mov dx, debug_com_base+1 - mov al, 0x00 - out dx, al + mov dx, debug_com_base+1 + mov al, 0x00 + out dx, al - ; No parity, 8bits words, one stop bit, dlab bit back to 0 + ; No parity, 8bits words, one stop bit, dlab bit back to 0 - mov dx, debug_com_base+3 - mov al, 3 - out dx, al + mov dx, debug_com_base+3 + mov al, 3 + out dx, al - ; disable interrupts + ; disable interrupts - mov dx, debug_com_base+1 - mov al, 0 - out dx, al + mov dx, debug_com_base+1 + mov al, 0 + out dx, al - ; clear + enable fifo (64 bits) + ; clear + enable fifo (64 bits) - mov dx, debug_com_base+2 - mov al, 0x7 + 1 shl 5 - out dx, al + mov dx, debug_com_base+2 + mov al, 0x7 + 1 shl 5 + out dx, al end if @@ -913,73 +946,73 @@ end if ; START MULTITASKING if preboot_blogesc - mov esi, boot_tasking - call boot_log -.bll1: in al, 0x60 ; wait for ESC key press - cmp al, 129 - jne .bll1 + mov esi, boot_tasking + call boot_log +.bll1: in al, 0x60 ; wait for ESC key press + cmp al, 129 + jne .bll1 end if ; mov [ENABLE_TASKSWITCH],byte 1 ; multitasking enabled ; UNMASK ALL IRQ'S - mov esi,boot_allirqs - call boot_log + mov esi,boot_allirqs + call boot_log - cli ;guarantee forbidance of interrupts. - mov al,0 ; unmask all irq's - out 0xA1,al - out 0x21,al + cli ;guarantee forbidance of interrupts. + mov al,0 ; unmask all irq's + out 0xA1,al + out 0x21,al - mov ecx,32 + mov ecx,32 ready_for_irqs: - mov al,0x20 ; ready for irqs - out 0x20,al - out 0xa0,al + mov al,0x20 ; ready for irqs + out 0x20,al + out 0xa0,al - loop ready_for_irqs ; flush the queue + loop ready_for_irqs ; flush the queue - stdcall attach_int_handler, dword 1, irq1, dword 0 + stdcall attach_int_handler, dword 1, irq1, dword 0 ; mov [dma_hdd],1 - cmp [IDEContrRegsBaseAddr], 0 - setnz [dma_hdd] - mov [timer_ticks_enable],1 ; for cd driver + cmp [IDEContrRegsBaseAddr], 0 + setnz [dma_hdd] + mov [timer_ticks_enable],1 ; for cd driver - sti - call change_task + sti + call change_task - jmp osloop + jmp osloop ; jmp $ ; wait here for timer to take control - ; Fly :) + ; Fly :) include 'unpacker.inc' include 'fdo.inc' align 4 boot_log: - pushad + pushad - mov ebx,10*65536 - mov bx,word [boot_y] - add [boot_y],dword 10 - mov ecx,0x80ffffff ; ASCIIZ string with white color - mov edx,esi - mov edi,1 - call dtext + mov ebx,10*65536 + mov bx,word [boot_y] + add [boot_y],dword 10 + mov ecx,0x80ffffff ; ASCIIZ string with white color + xor edi,edi + mov edx,esi + inc edi + call dtext - mov [novesachecksum],1000 - call checkVga_N13 + mov [novesachecksum],1000 + call checkVga_N13 - popad - - ret + popad + ret ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; @@ -988,17 +1021,17 @@ boot_log: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; align 32 osloop: - call [draw_pointer] - call checkbuttons - call checkwindows + call [draw_pointer] + call check_buttons + call checkwindows ; call check_window_move_request - call checkmisc - call checkVga_N13 - call stack_handler - call checkidle - call check_fdd_motor_status - call check_ATAPI_device_event - jmp osloop + call checkmisc + call checkVga_N13 + call stack_handler + call checkidle + call check_fdd_motor_status + call check_ATAPI_device_event + jmp osloop ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; ; MAIN OS LOOP END ; @@ -1006,33 +1039,33 @@ osloop: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; align 4 checkidle: - pushad - call change_task - jmp idle_loop_entry + pushad + call change_task + jmp idle_loop_entry idle_loop: - cmp eax,[idlemem] ; eax == [timer_ticks] - jne idle_exit - rdtsc ;call _rdtsc - mov ecx,eax - hlt - rdtsc ;call _rdtsc - sub eax,ecx - add [idleuse],eax + cmp eax,[idlemem] ; eax == [timer_ticks] + jne idle_exit + rdtsc ;call _rdtsc + mov ecx,eax + hlt + rdtsc ;call _rdtsc + sub eax,ecx + add [idleuse],eax idle_loop_entry: - mov eax,[timer_ticks] ; eax = [timer_ticks] - cmp [check_idle_semaphore],0 - je idle_loop - dec [check_idle_semaphore] + mov eax,[timer_ticks] ; eax = [timer_ticks] + cmp [check_idle_semaphore],0 + je idle_loop + dec [check_idle_semaphore] idle_exit: - mov [idlemem],eax ; eax == [timer_ticks] - popad - ret + mov [idlemem],eax ; eax == [timer_ticks] + popad + ret uglobal - idlemem dd 0x0 - idleuse dd 0x0 - idleusesec dd 0x0 - check_idle_semaphore dd 0x0 + idlemem dd 0x0 + idleuse dd 0x0 + idleusesec dd 0x0 + check_idle_semaphore dd 0x0 endg @@ -1055,57 +1088,58 @@ include "kernel32.inc" reserve_irqs_ports: - pushad + push eax + xor eax,eax + inc eax + mov byte [irq_owner+4*0],al ;1 ; timer + ;mov [irq_owner+4*1], 1 ; keyboard + mov byte [irq_owner+4*6],al ;1 ; floppy diskette + mov byte [irq_owner+4*13],al ;1 ; math co-pros + mov byte [irq_owner+4*14],al ;1 ; ide I + mov byte [irq_owner+4*15],al ;1 ; ide II + pop eax - mov [irq_owner+4*0], 1 ; timer - ;mov [irq_owner+4*1], 1 ; keyboard - mov [irq_owner+4*6], 1 ; floppy diskette - mov [irq_owner+4*13], 1 ; math co-pros - mov [irq_owner+4*14], 1 ; ide I - mov [irq_owner+4*15], 1 ; ide II +; RESERVE PORTS + push 4 + pop dword [RESERVED_PORTS] ;,edi - ; RESERVE PORTS - mov edi,1 ; 0x00-0x2d - mov [RESERVED_PORTS],edi - shl edi,4 - mov [RESERVED_PORTS+edi+0],dword 1 - mov [RESERVED_PORTS+edi+4],dword 0x0 - mov [RESERVED_PORTS+edi+8],dword 0x2d + push 1 + pop dword [RESERVED_PORTS+16+0] ;,dword 1 + and dword [RESERVED_PORTS+16+4],0 ;,dword 0x0 + mov dword [RESERVED_PORTS+16+8],0x2d ;,dword 0x2d - inc dword [RESERVED_PORTS] ; 0x30-0x4d - mov edi,[RESERVED_PORTS] - shl edi,4 - mov [RESERVED_PORTS+edi+0],dword 1 - mov [RESERVED_PORTS+edi+4],dword 0x30 - mov [RESERVED_PORTS+edi+8],dword 0x4d + push 1 + pop dword [RESERVED_PORTS+32+0] ;,dword 1 + push 0x30 + pop dword [RESERVED_PORTS+32+4] ;,dword 0x30 + push 0x4d + pop dword [RESERVED_PORTS+32+8] ;,dword 0x4d - inc dword [RESERVED_PORTS] ; 0x50-0xdf - mov edi,[RESERVED_PORTS] - shl edi,4 - mov [RESERVED_PORTS+edi+0],dword 1 - mov [RESERVED_PORTS+edi+4],dword 0x50 - mov [RESERVED_PORTS+edi+8],dword 0xdf + push 1 + pop dword [RESERVED_PORTS+48+0] ;,dword 1 + push 0x50 + pop dword [RESERVED_PORTS+48+4] ;,dword 0x50 + mov dword [RESERVED_PORTS+48+8],0xdf ;,dword 0xdf - inc dword [RESERVED_PORTS] ; 0xe5-0xff - mov edi,[RESERVED_PORTS] - shl edi,4 - mov [RESERVED_PORTS+edi+0],dword 1 - mov [RESERVED_PORTS+edi+4],dword 0xe5 - mov [RESERVED_PORTS+edi+8],dword 0xff + push 1 + pop dword [RESERVED_PORTS+64+0] ;,dword 1 - popad - ret + mov dword [RESERVED_PORTS+64+4],0xe5 ;,dword 0xe5 + mov dword [RESERVED_PORTS+64+8],0xff ;,dword 0xff + + ret setirqreadports: - mov [irq12read+0],dword 0x60 + 0x01000000 ; read port 0x60 , byte - mov [irq12read+4],dword 0 ; end of port list - ;mov [irq04read+0],dword 0x3f8 + 0x01000000 ; read port 0x3f8 , byte - ;mov [irq04read+4],dword 0 ; end of port list - ;mov [irq03read+0],dword 0x2f8 + 0x01000000 ; read port 0x2f8 , byte - ;mov [irq03read+4],dword 0 ; end of port list + mov [irq12read+0],dword 0x60 + 0x01000000 ; read port 0x60 , byte + and dword [irq12read+4],0 ; end of port list +; mov [irq12read+4],dword 0 ; end of port list + ;mov [irq04read+0],dword 0x3f8 + 0x01000000 ; read port 0x3f8 , byte + ;mov [irq04read+4],dword 0 ; end of port list + ;mov [irq03read+0],dword 0x2f8 + 0x01000000 ; read port 0x2f8 , byte + ;mov [irq03read+4],dword 0 ; end of port list - ret + ret iglobal process_number dd 0x1 @@ -1113,102 +1147,97 @@ endg set_variables: - mov ecx,0x100 ; flush port 0x60 -.fl60: in al,0x60 - loop .fl60 - mov [MOUSE_BUFF_COUNT],byte 0 ; mouse buffer - mov [KEY_COUNT],byte 0 ; keyboard buffer - mov [BTN_COUNT],byte 0 ; button buffer + mov ecx,0x100 ; flush port 0x60 +.fl60: in al,0x60 + loop .fl60 + push eax + + mov ax,[BOOT_VAR+0x900c] + shr ax,1 + shl eax,16 + mov ax,[BOOT_VAR+0x900A] + shr ax,1 + mov [MOUSE_X],eax + + xor eax,eax + mov [BTN_ADDR],dword BUTTON_INFO ; address of button list + + mov byte [MOUSE_BUFF_COUNT],al ; mouse buffer + mov byte [KEY_COUNT],al ; keyboard buffer + mov byte [BTN_COUNT],al ; button buffer ; mov [MOUSE_X],dword 100*65536+100 ; mouse x/y - push eax - mov ax,[BOOT_VAR+0x900c] - shr ax,1 - shl eax,16 - mov ax,[BOOT_VAR+0x900A] - shr ax,1 - mov [MOUSE_X],eax - pop eax - - mov [BTN_ADDR],dword BUTTON_INFO ; address of button list - ;!! IP 04.02.2005: - mov byte [DONT_SWITCH], 0 ; change task if possible - - ret - -;* mouse centered - start code- Mario79 -mouse_centered: - push eax - mov eax,[Screen_Max_X] - shr eax,1 - mov [MOUSE_X],ax - mov eax,[Screen_Max_Y] - shr eax,1 - mov [MOUSE_Y],ax - pop eax - ret -;* mouse centered - end code- Mario79 + mov byte [DONT_SWITCH],al ; change task if possible + pop eax + ret align 4 - +;input eax=43,bl-byte of output, ecx - number of port sys_outport: - mov edi,ebx ; separate flag for read / write - and ebx,65535 + mov edi,ecx ; separate flag for read / write + and ecx,65535 - mov ecx,[RESERVED_PORTS] - test ecx,ecx - jne sopl8 - mov [esp+36],dword 1 + mov eax,[RESERVED_PORTS] + test eax,eax + jnz .sopl8 + inc eax + mov [esp+32],eax ret - sopl8: + .sopl8: mov edx,[TASK_BASE] mov edx,[edx+0x4] - and ebx,65535 - cld - sopl1: + ;and ecx,65535 + ;cld - set on interrupt 0x40 + .sopl1: - mov esi,ecx + mov esi,eax shl esi,4 add esi,RESERVED_PORTS cmp edx,[esi+0] - jne sopl2 - cmp ebx,[esi+4] - jb sopl2 - cmp ebx,[esi+8] - jg sopl2 - jmp sopl3 - - sopl2: - - dec ecx - jnz sopl1 - mov [esp+36],dword 1 - ret - - sopl3: + jne .sopl2 + cmp ecx,[esi+4] + jb .sopl2 + cmp ecx,[esi+8] + jg .sopl2 +.sopl3: test edi,0x80000000 ; read ? - jnz sopl4 + jnz .sopl4 - mov dx,bx ; write + mov eax,ebx + mov dx,cx ; write out dx,al - mov [esp+36],dword 0 + and [esp+32],dword 0 ret - sopl4: + .sopl2: - mov dx,bx ; read - in al,dx + dec eax + jnz .sopl1 + inc eax + mov [esp+32],eax + ret + + + .sopl4: + + mov dx,cx ; read + in al,dx and eax,0xff - mov [esp+36],dword 0 - mov [esp+24],eax + and [esp+32],dword 0 + mov [esp+20],eax ret display_number: - +;It is not optimization + mov eax, ebx + mov ebx, ecx + mov ecx, edx + mov edx, esi + mov esi, edi ; eax = print type, al=0 -> ebx is number ; al=1 -> ebx is pointer ; ah=0 -> display decimal @@ -1220,18 +1249,18 @@ display_number: ; ebx = number or pointer ; ecx = x shl 16 + y ; edx = color - xor edi, edi + xor edi, edi display_number_force: - push eax - and eax,0x3fffffff - cmp eax,0xffff ; length > 0 ? - pop eax - jge cont_displ - ret + push eax + and eax,0x3fffffff + cmp eax,0xffff ; length > 0 ? + pop eax + jge cont_displ + ret cont_displ: push eax and eax,0x3fffffff - cmp eax,61*0x10000 ; length <= 60 ? + cmp eax,61*0x10000 ; length <= 60 ? pop eax jb cont_displ2 ret @@ -1239,28 +1268,28 @@ display_number_force: pushad - cmp al,1 ; ecx is a pointer ? + cmp al,1 ; ecx is a pointer ? jne displnl1 mov ebp,ebx add ebp,4 mov ebp,[ebp+std_application_base_address] mov ebx,[ebx+std_application_base_address] - displnl1: + displnl1: sub esp,64 - cmp ah,0 ; DECIMAL - jne no_display_desnum - shr eax,16 - and eax,0xC03f + test ah,ah ; DECIMAL + jnz no_display_desnum + shr eax,16 + and eax,0xC03f ; and eax,0x3f - push eax - and eax,0x3f - mov edi,esp - add edi,4+64-1 - mov ecx,eax - mov eax,ebx - mov ebx,10 - d_desnum: + push eax + and eax,0x3f + mov edi,esp + add edi,4+64-1 + mov ecx,eax + mov eax,ebx + mov ebx,10 + d_desnum: xor edx,edx call division_64_bits div ebx @@ -1276,7 +1305,7 @@ display_number_force: ret no_display_desnum: - cmp ah,0x01 ; HEXADECIMAL + cmp ah,0x01 ; HEXADECIMAL jne no_display_hexnum shr eax,16 and eax,0xC03f @@ -1306,7 +1335,7 @@ display_number_force: ret no_display_hexnum: - cmp ah,0x02 ; BINARY + cmp ah,0x02 ; BINARY jne no_display_binnum shr eax,16 and eax,0xC03f @@ -1385,9 +1414,9 @@ draw_num_text: add eax,[edi+SLOT_BASE+APPDATA.wnd_clientbox.top] add ebx,eax mov ecx,[esp+64+32-12+4] - and ecx, not 0x80000000 ; force counted string - mov eax, [esp+64+8] ; background color (if given) - mov edi, [esp+64+4] + and ecx, not 0x80000000 ; force counted string + mov eax, [esp+64+8] ; background color (if given) + mov edi, [esp+64+4] jmp dtext align 4 @@ -1406,146 +1435,155 @@ sys_setup: ; 12 = enable pci access - mov [esp+36],dword 0 - cmp eax,1 ; MIDI - jnz nsyse1 - cmp ebx,0x100 - jb nsyse1 - mov edx,65535 - cmp edx,ebx - jb nsyse1 - mov [midi_base],bx - mov word [mididp],bx - inc bx - mov word [midisp],bx - ret + and [esp+32],dword 0 + dec ebx ; MIDI + jnz nsyse1 + cmp ecx,0x100 + + jb nsyse1 + mov esi,65535 + cmp esi,ecx + + jb nsyse1 + mov [midi_base],cx ;bx + mov word [mididp],cx ;bx + inc cx ;bx + mov word [midisp],cx ;bx + ret iglobal midi_base dw 0 endg nsyse1: + dec ebx ; KEYBOARD + jnz nsyse2 + mov edi,[TASK_BASE] + mov eax,[edi+TASKDATA.mem_start] + add eax,edx - cmp eax,2 ; KEYBOARD - jnz nsyse2 - cmp ebx,1 - jnz kbnobase - mov edi,[TASK_BASE] - add ecx,[edi+TASKDATA.mem_start] - mov eax,ecx - mov ebx,keymap - mov ecx,128 - call memmove - ret + dec ecx + jnz kbnobase + mov ebx,keymap + mov ecx,128 + call memmove + ret kbnobase: - cmp ebx,2 - jnz kbnoshift - mov edi,[TASK_BASE] - add ecx,[edi+TASKDATA.mem_start] - mov eax,ecx - mov ebx,keymap_shift - mov ecx,128 - call memmove - ret - kbnoshift: - cmp ebx,3 - jne kbnoalt - mov edi,[TASK_BASE] - add ecx,[edi+TASKDATA.mem_start] - mov eax,ecx - mov ebx,keymap_alt - mov ecx,128 - call memmove - ret - kbnoalt: - cmp ebx,9 - jnz kbnocountry - mov word [keyboard],cx - ret - kbnocountry: - mov [esp+36],dword 1 - ret - nsyse2: - cmp eax,3 ; CD - jnz nsyse4 - test ebx,ebx - jz nosesl - cmp ebx, 4 - ja nosesl - mov [cd_base],bl - cmp ebx,1 - jnz noprma - mov [cdbase],0x1f0 - mov [cdid],0xa0 - noprma: - cmp ebx,2 - jnz noprsl - mov [cdbase],0x1f0 - mov [cdid],0xb0 - noprsl: - cmp ebx,3 - jnz nosema - mov [cdbase],0x170 - mov [cdid],0xa0 - nosema: - cmp ebx,4 - jnz nosesl - mov [cdbase],0x170 - mov [cdid],0xb0 - nosesl: - ret + dec ecx + jnz kbnoshift + mov ebx,keymap_shift + mov ecx,128 + call memmove + ret + kbnoshift: + dec ecx + jnz kbnoalt + mov ebx,keymap_alt + mov ecx,128 + call memmove + ret + kbnoalt: + sub ecx,6 + jnz kbnocountry + mov word [keyboard],dx + ret + kbnocountry: + mov [esp+32],dword 1 + ret + nsyse2: + dec ebx ; CD + jnz nsyse4 + + test ecx,ecx + jz nosesl + + cmp ecx, 4 + ja nosesl + mov [cd_base],cl + + dec ecx + jnz noprma + mov [cdbase],0x1f0 + mov [cdid],0xa0 + noprma: + + dec ecx + jnz noprsl + mov [cdbase],0x1f0 + mov [cdid],0xb0 + noprsl: + dec ecx + jnz nosema + mov [cdbase],0x170 + mov [cdid],0xa0 + nosema: + dec ecx + jnz nosesl + mov [cdbase],0x170 + mov [cdid],0xb0 + nosesl: + ret + +iglobal cd_base db 0 +endg nsyse4: - - cmp eax,5 ; SYSTEM LANGUAGE - jnz nsyse5 - mov [syslang],ebx - ret + + sub ebx,2 ; SYSTEM LANGUAGE + jnz nsyse5 + mov [syslang],ecx + ret nsyse5: + + sub ebx,2 ; HD BASE + jnz nsyse7 - cmp eax,7 ; HD BASE - jne nsyse7 - test ebx,ebx - jz nosethd - cmp ebx,4 - ja nosethd - mov [hd_base],bl - cmp ebx,1 - jnz noprmahd - mov [hdbase],0x1f0 - mov [hdid],0x0 - mov [hdpos],1 + test ecx,ecx + jz nosethd + + cmp ecx,4 + ja nosethd + mov [hd_base],cl + + cmp ecx,1 + jnz noprmahd + mov [hdbase],0x1f0 + and dword [hdid],0x0 + mov dword [hdpos],ecx ; call set_FAT32_variables noprmahd: - cmp ebx,2 - jnz noprslhd - mov [hdbase],0x1f0 - mov [hdid],0x10 - mov [hdpos],2 + + cmp ecx,2 + jnz noprslhd + mov [hdbase],0x1f0 + mov [hdid],0x10 + mov dword [hdpos],ecx ; call set_FAT32_variables noprslhd: - cmp ebx,3 - jnz nosemahd - mov [hdbase],0x170 - mov [hdid],0x0 - mov [hdpos],3 + + cmp ecx,3 + jnz nosemahd + mov [hdbase],0x170 + and dword [hdid],0x0 + mov dword [hdpos],ecx ; call set_FAT32_variables nosemahd: - cmp ebx,4 - jnz noseslhd - mov [hdbase],0x170 - mov [hdid],0x10 - mov [hdpos],4 + + cmp ecx,4 + jnz noseslhd + mov [hdbase],0x170 + mov [hdid],0x10 + mov dword [hdpos],ecx ; call set_FAT32_variables noseslhd: - call reserve_hd1 - call reserve_hd_channel - call free_hd_channel - mov [hd1_status],0 ; free + call reserve_hd1 + call reserve_hd_channel + call free_hd_channel + and dword [hd1_status],0 ; free nosethd: - ret + ret iglobal hd_base db 0 @@ -1553,41 +1591,43 @@ endg nsyse7: - cmp eax,8 ; HD PARTITION - jne nsyse8 - mov [fat32part],ebx +; cmp eax,8 ; HD PARTITION + dec ebx + jnz nsyse8 + mov [fat32part],ecx ; call set_FAT32_variables - call reserve_hd1 - call reserve_hd_channel - call free_hd_channel - pusha - call choice_necessity_partition_1 - popa - mov [hd1_status],0 ; free - ret + call reserve_hd1 + call reserve_hd_channel + call free_hd_channel +; pusha + call choice_necessity_partition_1 +; popa + and dword [hd1_status],0 ; free + ret nsyse8: - cmp eax,11 ; ENABLE LBA READ - jne no_set_lba_read - and ebx,1 - mov [lba_read_enabled],ebx - ret +; cmp eax,11 ; ENABLE LBA READ + and ecx,1 + sub ebx,3 + jnz no_set_lba_read + mov [lba_read_enabled],ecx + ret no_set_lba_read: - cmp eax,12 ; ENABLE PCI ACCESS - jne no_set_pci_access - and ebx,1 - mov [pci_access_enabled],ebx - ret - no_set_pci_access: +; cmp eax,12 ; ENABLE PCI ACCESS + dec ebx + jnz no_set_pci_access + mov [pci_access_enabled],ecx + ret +no_set_pci_access: ;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! include 'vmodeint.inc' ;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! sys_setup_err: - mov [esp+36],dword -1 - ret + or [esp+32],dword -1 + ret align 4 @@ -1601,108 +1641,120 @@ sys_getsetup: ; 8=fat32 partition in hd ; 9=get hs timer tic - cmp eax,1 - jne ngsyse1 - movzx eax,[midi_base] - mov [esp+36],eax - ret +; cmp eax,1 + dec ebx + jnz ngsyse1 + movzx eax,[midi_base] + mov [esp+32],eax + ret ngsyse1: +; cmp eax,2 + dec ebx + jnz ngsyse2 - cmp eax,2 - jne ngsyse2 - cmp ebx,1 - jnz kbnobaseret - mov edi,[TASK_BASE] - add ecx,[edi+TASKDATA.mem_start] - mov ebx,ecx - mov eax,keymap - mov ecx,128 - call memmove - ret + mov edi,[TASK_BASE] + mov ebx,[edi+TASKDATA.mem_start] + add ebx,edx + +; cmp ebx,1 + dec ecx + jnz kbnobaseret + mov eax,keymap + mov ecx,128 + call memmove + ret kbnobaseret: - cmp ebx,2 - jnz kbnoshiftret - mov edi,[TASK_BASE] - add ecx,[edi+TASKDATA.mem_start] - mov ebx,ecx - mov eax,keymap_shift - mov ecx,128 - call memmove - ret +; cmp ebx,2 + dec ecx + jnz kbnoshiftret + + mov eax,keymap_shift + mov ecx,128 + call memmove + ret kbnoshiftret: - cmp ebx,3 - jne kbnoaltret - mov edi,[TASK_BASE] - add ecx,[edi+TASKDATA.mem_start] - mov ebx,ecx - mov eax,keymap_alt - mov ecx,128 - call memmove - ret +; cmp ebx,3 + dec ecx + jne kbnoaltret + + mov eax,keymap_alt + mov ecx,128 + call memmove + ret kbnoaltret: - cmp ebx,9 - jnz ngsyse2 - movzx eax,word [keyboard] - mov [esp+36],eax - ret +; cmp ebx,9 + sub ecx,6 + jnz ngsyse2 + movzx eax,word [keyboard] + mov [esp+32],eax + ret + + ngsyse2: - - cmp eax,3 - jnz ngsyse3 - movzx eax,[cd_base] - mov [esp+36],eax - ret +; cmp eax,3 + dec ebx + jnz ngsyse3 + movzx eax,[cd_base] + mov [esp+32],eax + ret ngsyse3: - cmp eax,5 - jnz ngsyse5 - mov eax,[syslang] - mov [esp+36],eax - ret +; cmp eax,5 + sub ebx,2 + jnz ngsyse5 + mov eax,[syslang] + mov [esp+32],eax + ret ngsyse5: - cmp eax,7 - jnz ngsyse7 - movzx eax,[hd_base] - mov [esp+36],eax - ret +; cmp eax,7 + sub ebx,2 + jnz ngsyse7 + movzx eax,[hd_base] + mov [esp+32],eax + ret ngsyse7: - cmp eax,8 - jnz ngsyse8 - mov eax,[fat32part] - mov [esp+36],eax - ret +; cmp eax,8 + dec ebx + jnz ngsyse8 + mov eax,[fat32part] + mov [esp+32],eax + ret ngsyse8: - cmp eax,9 - jne ngsyse9 - mov eax,[timer_ticks] ;[0xfdf0] - mov [esp+36],eax - ret +; cmp eax,9 + dec ebx + jnz ngsyse9 + mov eax,[timer_ticks] ;[0xfdf0] + mov [esp+32],eax + ret ngsyse9: - cmp eax,11 - jnz ngsyse11 - mov eax,[lba_read_enabled] - mov [esp+36],eax - ret +; cmp eax,11 + sub ebx,2 + jnz ngsyse11 + mov eax,[lba_read_enabled] + mov [esp+32],eax + ret ngsyse11: - cmp eax,12 - jnz ngsyse12 - mov eax,[pci_access_enabled] - mov [esp+36],eax - ret +; cmp eax,12 + dec ebx + jnz ngsyse12 + mov eax,[pci_access_enabled] + mov [esp+32],eax + ret ngsyse12: - mov [esp+36],dword 1 - ret + mov [esp+32],dword 1 + ret + get_timer_ticks: - mov eax,[timer_ticks] - ret + mov eax,[timer_ticks] + ret iglobal align 4 mousefn dd msscreen, mswin, msbutton, msset - dd app_load_cursor - dd app_set_cursor - dd app_delete_cursor - dd msz + dd app_load_cursor + dd app_set_cursor + dd app_delete_cursor + dd msz endg readmousepos: @@ -1716,171 +1768,159 @@ readmousepos: ; eax=6 delete cursor ; reserved ; eax=7 get mouse_z - cmp eax, 7 - ja msset - jmp [mousefn+eax*4] + cmp ebx, 7 + ja msset + jmp [mousefn+ebx*4] msscreen: - mov eax,[MOUSE_X] - shl eax,16 - mov ax,[MOUSE_Y] - mov [esp+36],eax - ret + mov eax,[MOUSE_X] + shl eax,16 + mov ax,[MOUSE_Y] + mov [esp+36-4],eax + ret mswin: - mov eax,[MOUSE_X] - shl eax,16 - mov ax,[MOUSE_Y] - mov esi,[TASK_BASE] - mov bx, word [esi-twdw+WDATA.box.left] - shl ebx,16 - mov bx, word [esi-twdw+WDATA.box.top] - sub eax,ebx + mov eax,[MOUSE_X] + shl eax,16 + mov ax,[MOUSE_Y] + mov esi,[TASK_BASE] + mov bx, word [esi-twdw+WDATA.box.left] + shl ebx,16 + mov bx, word [esi-twdw+WDATA.box.top] + sub eax,ebx - mov edi,[CURRENT_TASK] - shl edi,8 - sub ax,word[edi+SLOT_BASE+APPDATA.wnd_clientbox.top] - rol eax,16 - sub ax,word[edi+SLOT_BASE+APPDATA.wnd_clientbox.left] - rol eax,16 - mov [esp+36],eax - ret + mov edi,[CURRENT_TASK] + shl edi,8 + sub ax,word[edi+SLOT_BASE+APPDATA.wnd_clientbox.top] + rol eax,16 + sub ax,word[edi+SLOT_BASE+APPDATA.wnd_clientbox.left] + rol eax,16 + mov [esp+36-4],eax + ret msbutton: - movzx eax,byte [BTN_DOWN] - mov [esp+36],eax - ret + movzx eax,byte [BTN_DOWN] + mov [esp+36-4],eax + ret msz: - mov edi, [TASK_COUNT] - movzx edi, word [WIN_POS + edi*2] - cmp edi, [CURRENT_TASK] - jne @f - mov ax,[MOUSE_SCROLL_H] - shl eax,16 - mov ax,[MOUSE_SCROLL_V] - mov [esp+36],eax - mov [MOUSE_SCROLL_H],word 0 - mov [MOUSE_SCROLL_V],word 0 - ret + mov edi, [TASK_COUNT] + movzx edi, word [WIN_POS + edi*2] + cmp edi, [CURRENT_TASK] + jne @f + mov ax,[MOUSE_SCROLL_H] + shl eax,16 + mov ax,[MOUSE_SCROLL_V] + mov [esp+36-4],eax + and [MOUSE_SCROLL_H],word 0 + and [MOUSE_SCROLL_V],word 0 + ret @@: - mov [esp+36],dword 0 - ret + and [esp+36-4],dword 0 +; ret msset: - ret + ret app_load_cursor: - ; add ebx, new_app_base - cmp ebx, OS_BASE - jae msset - stdcall load_cursor, ebx, ecx - mov [esp+36], eax - ret + cmp ecx, OS_BASE + jae msset + stdcall load_cursor, ecx, edx + mov [esp+36-4], eax + ret app_set_cursor: - stdcall set_cursor, ebx - mov [esp+36], eax - ret + stdcall set_cursor, ecx + mov [esp+36-4], eax + ret app_delete_cursor: - stdcall delete_cursor, ebx - mov [esp+36], eax - ret + stdcall delete_cursor, ecx + mov [esp+36-4], eax + ret is_input: push edx - mov dx,word [midisp] - in al,dx - and al,0x80 - pop edx + mov dx,word [midisp] + in al,dx + and al,0x80 + pop edx ret is_output: push edx - mov dx,word [midisp] - in al,dx - and al,0x40 - pop edx + mov dx,word [midisp] + in al,dx + and al,0x40 + pop edx ret get_mpu_in: push edx - mov dx,word [mididp] - in al,dx - pop edx + mov dx,word [mididp] + in al,dx + pop edx ret put_mpu_out: push edx - mov dx,word [mididp] - out dx,al - pop edx + mov dx,word [mididp] + out dx,al + pop edx ret -setuart: - - su1: - call is_output - cmp al,0 - 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 - cmp al,0 - jnz su2 - call get_mpu_in - cmp al,0xfe - jnz su2 - su3: - call is_output - cmp al,0 - jnz su3 - mov dx,word [midisp] - mov al,0x3f - out dx,al - - ret - align 4 sys_midi: - - cmp [mididp],0 - jnz sm0 - mov [esp+36],dword 1 - ret - sm0: - - cmp eax,1 - mov [esp+36],dword 0 - jnz smn1 - call setuart - ret - smn1: - - cmp eax,2 - jnz smn2 - sm10: - call get_mpu_in - call is_output - test al,al - jnz sm10 - mov al,bl - call put_mpu_out - ret - smn2: - - ret - + 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 detect_devices: ;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! @@ -1892,13 +1932,20 @@ detect_devices: ;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ret - sys_end: + mov ecx, [current_slot] + mov eax, [ecx+APPDATA.tls_base] + test eax, eax + jz @F + + stdcall user_free, eax +@@: + mov eax,[TASK_BASE] mov [eax+TASKDATA.state], 3 ; terminate this program - waitterm: ; wait here for termination + waitterm: ; wait here for termination mov ebx,100 call delay_hs jmp waitterm @@ -1906,42 +1953,42 @@ sys_end: iglobal align 4 sys_system_table: - dd exit_for_anyone ; 1 = obsolete - dd sysfn_terminate ; 2 = terminate thread - dd sysfn_activate ; 3 = activate window - dd sysfn_getidletime ; 4 = get idle time - dd sysfn_getcpuclock ; 5 = get cpu clock - dd sysfn_saveramdisk ; 6 = save ramdisk - dd sysfn_getactive ; 7 = get active window - dd sysfn_sound_flag ; 8 = get/set sound_flag - dd sysfn_shutdown ; 9 = shutdown with parameter - dd sysfn_minimize ; 10 = minimize window - dd sysfn_getdiskinfo ; 11 = get disk subsystem info - dd sysfn_lastkey ; 12 = get last pressed key - dd sysfn_getversion ; 13 = get kernel version - dd sysfn_waitretrace ; 14 = wait retrace - dd sysfn_centermouse ; 15 = center mouse cursor - dd sysfn_getfreemem ; 16 = get free memory size - dd sysfn_getallmem ; 17 = get total memory size - dd sysfn_terminate2 ; 18 = terminate thread using PID - ; instead of slot - dd sysfn_mouse_acceleration; 19 = set/get mouse acceleration - dd sysfn_meminfo ; 20 = get extended memory info - dd sysfn_pid_to_slot ; 21 = get slot number for pid - dd sysfn_min_rest_window ; 22 = minimize and restore any window + dd exit_for_anyone ; 1 = obsolete + dd sysfn_terminate ; 2 = terminate thread + dd sysfn_activate ; 3 = activate window + dd sysfn_getidletime ; 4 = get idle time + dd sysfn_getcpuclock ; 5 = get cpu clock + dd sysfn_saveramdisk ; 6 = save ramdisk + dd sysfn_getactive ; 7 = get active window + dd sysfn_sound_flag ; 8 = get/set sound_flag + dd sysfn_shutdown ; 9 = shutdown with parameter + dd sysfn_minimize ; 10 = minimize window + dd sysfn_getdiskinfo ; 11 = get disk subsystem info + dd sysfn_lastkey ; 12 = get last pressed key + dd sysfn_getversion ; 13 = get kernel version + dd sysfn_waitretrace ; 14 = wait retrace + dd sysfn_centermouse ; 15 = center mouse cursor + dd sysfn_getfreemem ; 16 = get free memory size + dd sysfn_getallmem ; 17 = get total memory size + dd sysfn_terminate2 ; 18 = terminate thread using PID + ; instead of slot + dd sysfn_mouse_acceleration; 19 = set/get mouse acceleration + dd sysfn_meminfo ; 20 = get extended memory info + dd sysfn_pid_to_slot ; 21 = get slot number for pid + dd sysfn_min_rest_window ; 22 = minimize and restore any window sysfn_num = ($ - sys_system_table)/4 endg sys_system: - dec ebx - cmp ebx, sysfn_num - jae @f - jmp dword [sys_system_table + ebx*4] + dec ebx + cmp ebx, sysfn_num + jae @f + jmp dword [sys_system_table + ebx*4] @@: - ret + ret -sysfn_shutdown: ; 18.9 = system shutdown +sysfn_shutdown: ; 18.9 = system shutdown cmp ecx,1 jl exit_for_anyone cmp ecx,4 @@ -1958,7 +2005,7 @@ sysfn_shutdown: ; 18.9 = system shutdown shutdown_processes: dd 0x0 endg -sysfn_terminate: ; 18.2 = TERMINATE +sysfn_terminate: ; 18.2 = TERMINATE cmp ecx,2 jb noprocessterminate mov edx,[TASK_COUNT] @@ -1972,12 +2019,12 @@ sysfn_terminate: ; 18.2 = TERMINATE jz noprocessterminate ;call MEM_Heap_Lock ;guarantee that process isn't working with heap - mov [ecx],byte 3 ; clear possible i40's + mov [ecx],byte 3 ; clear possible i40's ;call MEM_Heap_UnLock cmp edx,[application_table_status] ; clear app table stat jne noatsc - mov [application_table_status],0 + and [application_table_status],0 noatsc: noprocessterminate: ret @@ -1987,7 +2034,7 @@ sysfn_terminate2: .table_status: cli cmp [application_table_status],0 - je .stf + je .stf sti call change_task jmp .table_status @@ -1996,20 +2043,20 @@ sysfn_terminate2: mov eax,ecx call pid_to_slot test eax,eax - jz .not_found + jz .not_found mov ecx,eax cli call sysfn_terminate - mov [application_table_status],0 + and [application_table_status],0 sti and dword [esp+32],0 ret .not_found: mov [application_table_status],0 - or dword [esp+32],-1 + or dword [esp+32],-1 ret -sysfn_activate: ; 18.3 = ACTIVATE WINDOW +sysfn_activate: ; 18.3 = ACTIVATE WINDOW cmp ecx,2 jb .nowindowactivate cmp ecx,[TASK_COUNT] @@ -2030,12 +2077,12 @@ sysfn_activate: ; 18.3 = ACTIVATE WINDOW .nowindowactivate: ret -sysfn_getidletime: ; 18.4 = GET IDLETIME +sysfn_getidletime: ; 18.4 = GET IDLETIME mov eax,[idleusesec] mov [esp+32], eax ret -sysfn_getcpuclock: ; 18.5 = GET TSC/SEC +sysfn_getcpuclock: ; 18.5 = GET TSC/SEC mov eax,[CPU_FREQ] mov [esp+32], eax ret @@ -2044,32 +2091,35 @@ sysfn_getcpuclock: ; 18.5 = GET TSC/SEC ;!!!!!!!!!!!!!!!!!!!!!!!! include 'blkdev/rdsave.inc' ;!!!!!!!!!!!!!!!!!!!!!!!! - -sysfn_getactive: ; 18.7 = get active window +align 4 +sysfn_getactive: ; 18.7 = get active window mov eax, [TASK_COUNT] movzx eax, word [WIN_POS + eax*2] mov [esp+32],eax ret -sysfn_sound_flag: ; 18.8 = get/set sound_flag - cmp ecx,1 - jne nogetsoundflag +sysfn_sound_flag: ; 18.8 = get/set sound_flag +; cmp ecx,1 + dec ecx + jnz nogetsoundflag movzx eax,byte [sound_flag] ; get sound_flag mov [esp+32],eax ret nogetsoundflag: - cmp ecx,2 +; cmp ecx,2 + dec ecx jnz nosoundflag xor byte [sound_flag], 1 nosoundflag: ret -sysfn_minimize: ; 18.10 = minimize window +sysfn_minimize: ; 18.10 = minimize window mov [window_minimize],1 ret - -sysfn_getdiskinfo: ; 18.11 = get disk info table - cmp ecx,1 +align 4 +sysfn_getdiskinfo: ; 18.11 = get disk info table +; cmp ecx,1 + dec ecx jnz full_table small_table: call for_all_tables @@ -2082,7 +2132,8 @@ sysfn_getdiskinfo: ; 18.11 = get disk info table mov esi,DRIVE_DATA ret full_table: - cmp ecx,2 +; cmp ecx,2 + dec ecx jnz exit_for_anyone call for_all_tables mov ecx,16384 @@ -2090,11 +2141,11 @@ sysfn_getdiskinfo: ; 18.11 = get disk info table rep movsd ret -sysfn_lastkey: ; 18.12 = return 0 (backward compatibility) - and dword [esp+32], 0 - ret +sysfn_lastkey: ; 18.12 = return 0 (backward compatibility) + and dword [esp+32], 0 + ret -sysfn_getversion: ; 18.13 = get kernel ID and version +sysfn_getversion: ; 18.13 = get kernel ID and version mov edi,ebx mov esi,version_inf mov ecx,version_end-version_inf @@ -2112,36 +2163,56 @@ sysfn_waitretrace: ; 18.14 = sys wait retrace and [esp+32],dword 0 ret -sysfn_centermouse: ; 18.15 = mouse centered - call mouse_centered - and [esp+32],dword 0 - ret +align 4 +sysfn_centermouse: ; 18.15 = mouse centered +; removed here by +; call mouse_centered +;* mouse centered - start code- Mario79 +;mouse_centered: +; push eax + mov eax,[Screen_Max_X] + shr eax,1 + mov [MOUSE_X],ax + mov eax,[Screen_Max_Y] + shr eax,1 + mov [MOUSE_Y],ax +; ret +;* mouse centered - end code- Mario79 + xor eax,eax + and [esp+32],eax +; pop eax + ret +align 4 sysfn_mouse_acceleration: ; 18.19 = set/get mouse features - cmp ecx,0 ; get mouse speed factor + test ecx,ecx ; get mouse speed factor jnz .set_mouse_acceleration xor eax,eax mov ax,[mouse_speed_factor] mov [esp+32],eax ret .set_mouse_acceleration: - cmp ecx,1 ; set mouse speed factor +; cmp ecx,1 ; set mouse speed factor + dec ecx jnz .get_mouse_delay mov [mouse_speed_factor],dx ret .get_mouse_delay: - cmp ecx,2 ; get mouse delay +; cmp ecx,2 ; get mouse delay + dec ecx jnz .set_mouse_delay mov eax,[mouse_delay] mov [esp+32],eax ret .set_mouse_delay: - cmp ecx,3 ; set mouse delay +; cmp ecx,3 ; set mouse delay + dec ecx jnz .set_pointer_position mov [mouse_delay],edx ret .set_pointer_position: - cmp ecx,4 ; set mouse pointer position +; cmp ecx,4 ; set mouse pointer position + dec ecx jnz .set_mouse_button mov [MOUSE_Y],dx ;y ror edx,16 @@ -2149,7 +2220,8 @@ sysfn_mouse_acceleration: ; 18.19 = set/get mouse features rol edx,16 ret .set_mouse_button: - cmp ecx,5 ; set mouse button features +; cmp ecx,5 ; set mouse button features + dec ecx jnz .end mov [BTN_DOWN],dl mov [mouse_active],1 @@ -2177,14 +2249,14 @@ sysfn_pid_to_slot: sysfn_min_rest_window: pushad - mov eax, edx ; ebx - operating + mov eax, edx ; ebx - operating shr ecx, 1 jnc @f call pid_to_slot @@: - or eax, eax ; eax - number of slot + or eax, eax ; eax - number of slot jz .error - cmp eax, 255 ; varify maximal slot number + cmp eax, 255 ; varify maximal slot number ja .error movzx eax, word [WIN_STACK + eax*2] shr ecx, 1 @@ -2212,39 +2284,39 @@ uglobal screen_workarea RECT ;// mike.dld, 2006-29-01 ] window_minimize db 0 -sound_flag db 0 +sound_flag db 0 endg iglobal version_inf: - db 0,7,5,0 ; version 0.7.5.0 + db 0,7,7,0 ; version 0.7.7.0 db UID_KOLIBRI dd __REV__ version_end: endg UID_NONE=0 -UID_MENUETOS=1 ;official -UID_KOLIBRI=2 ;russian +UID_MENUETOS=1 ;official +UID_KOLIBRI=2 ;russian sys_cachetodiskette: - cmp ebx, 1 - jne .no_floppy_a_save - mov [flp_number], 1 - jmp .save_image_on_floppy + cmp ebx, 1 + jne .no_floppy_a_save + mov [flp_number], 1 + jmp .save_image_on_floppy .no_floppy_a_save: - cmp ebx, 2 - jne .no_floppy_b_save - mov [flp_number], 2 + cmp ebx, 2 + jne .no_floppy_b_save + mov [flp_number], 2 .save_image_on_floppy: - call save_image - mov [esp + 32], dword 0 - cmp [FDC_Status], 0 - je .yes_floppy_save + call save_image + mov [esp + 32], dword 0 + cmp [FDC_Status], 0 + je .yes_floppy_save .no_floppy_b_save: - mov [esp + 32], dword 1 + mov [esp + 32], dword 1 .yes_floppy_save: - ret + ret uglobal ; bgrchanged dd 0x0 @@ -2255,18 +2327,20 @@ endg sys_background: - cmp ebx,1 ; BACKGROUND SIZE + cmp ebx,1 ; BACKGROUND SIZE jnz nosb1 - cmp ecx,0 - je sbgrr - cmp edx,0 - je sbgrr + test ecx,ecx +; cmp ecx,0 + jz sbgrr + test edx,edx +; cmp edx,0 + jz sbgrr @@: ;;Maxis use atomic bts for mutexes 4.4.2009 - bts dword [bgrlock], 0 - jnc @f - call change_task - jmp @b + bts dword [bgrlock], 0 + jnc @f + call change_task + jmp @b @@: mov [BgrDataWidth],ecx mov [BgrDataHeight],edx @@ -2274,10 +2348,10 @@ sys_background: pushad ; return memory for old background - mov eax, [img_background] - cmp eax, static_background_data - jz @f - stdcall kernel_free, eax + mov eax, [img_background] + cmp eax, static_background_data + jz @f + stdcall kernel_free, eax @@: ; calculate RAW size xor eax,eax @@ -2302,36 +2376,36 @@ sys_background: jmp .exit .memfailed: ; revert to static monotone data - mov [img_background], static_background_data - xor eax, eax - inc eax - mov [BgrDataWidth], eax - mov [BgrDataHeight], eax - mov [mem_BACKGROUND], 4 + mov [img_background], static_background_data + xor eax, eax + inc eax + mov [BgrDataWidth], eax + mov [BgrDataHeight], eax + mov [mem_BACKGROUND], 4 .exit: popad - mov [bgrlock], 0 + mov [bgrlock], 0 sbgrr: ret nosb1: - cmp ebx,2 ; SET PIXEL + cmp ebx,2 ; SET PIXEL jnz nosb2 mov eax, [img_background] test ecx, ecx - jz @f + jz @f cmp eax, static_background_data - jz .ret + jz .ret @@: mov ebx, [mem_BACKGROUND] add ebx, 4095 and ebx, -4096 sub ebx, 4 cmp ecx, ebx - ja .ret + ja .ret mov ebx,[eax+ecx] and ebx,0xFF000000 ;255*256*256*256 @@ -2342,7 +2416,7 @@ nosb1: ret nosb2: - cmp ebx,3 ; DRAW BACKGROUND + cmp ebx,3 ; DRAW BACKGROUND jnz nosb3 draw_background_temp: ; cmp [bgrchanged],1 ;0 @@ -2356,24 +2430,24 @@ draw_background_temp: ret nosb3: - cmp ebx,4 ; TILED / STRETCHED + cmp ebx,4 ; TILED / STRETCHED jnz nosb4 cmp ecx,[BgrDrawMode] - je nosb41 + je nosb41 mov [BgrDrawMode],ecx ; mov [bgrchanged],1 nosb41: ret nosb4: - cmp ebx,5 ; BLOCK MOVE TO BGR + cmp ebx,5 ; BLOCK MOVE TO BGR jnz nosb5 cmp [img_background], static_background_data jnz @f test edx, edx jnz .fin cmp esi, 4 - ja .fin + ja .fin @@: ; bughere mov eax, ecx @@ -2385,93 +2459,94 @@ draw_background_temp: ret nosb5: - cmp ebx, 6 - jnz nosb6 + cmp ebx, 6 + jnz nosb6 ;;Maxis use atomic bts for mutex 4.4.2009 @@: - bts dword [bgrlock], 0 - jnc @f - call change_task - jmp @b + bts dword [bgrlock], 0 + jnc @f + call change_task + jmp @b @@: - mov eax, [CURRENT_TASK] - mov [bgrlockpid], eax - cmp [img_background], static_background_data - jz .nomem - stdcall user_alloc, [mem_BACKGROUND] - mov [esp+32], eax - test eax, eax - jz .nomem - mov ebx, eax - shr ebx, 12 - or dword [page_tabs+(ebx-1)*4], DONT_FREE_BLOCK - mov esi, [img_background] - shr esi, 12 - mov ecx, [mem_BACKGROUND] - add ecx, 0xFFF - shr ecx, 12 + mov eax, [CURRENT_TASK] + mov [bgrlockpid], eax + cmp [img_background], static_background_data + jz .nomem + stdcall user_alloc, [mem_BACKGROUND] + mov [esp+32], eax + test eax, eax + jz .nomem + mov ebx, eax + shr ebx, 12 + or dword [page_tabs+(ebx-1)*4], DONT_FREE_BLOCK + mov esi, [img_background] + shr esi, 12 + mov ecx, [mem_BACKGROUND] + add ecx, 0xFFF + shr ecx, 12 .z: - mov eax, [page_tabs+ebx*4] - test al, 1 - jz @f - call free_page + mov eax, [page_tabs+ebx*4] + test al, 1 + jz @f + call free_page @@: - mov eax, [page_tabs+esi*4] - or al, PG_UW - mov [page_tabs+ebx*4], eax - mov eax, ebx - shl eax, 12 - invlpg [eax] - inc ebx - inc esi - loop .z - ret + mov eax, [page_tabs+esi*4] + or al, PG_UW + mov [page_tabs+ebx*4], eax + mov eax, ebx + shl eax, 12 + invlpg [eax] + inc ebx + inc esi + loop .z + ret .nomem: - and [bgrlockpid], 0 - mov [bgrlock], 0 + and [bgrlockpid], 0 + mov [bgrlock], 0 nosb6: - cmp ebx, 7 - jnz nosb7 - cmp [bgrlock], 0 - jz .err - mov eax, [CURRENT_TASK] - cmp [bgrlockpid], eax - jnz .err - mov eax, ecx - mov ebx, ecx - shr eax, 12 - mov ecx, [page_tabs+(eax-1)*4] - test cl, USED_BLOCK+DONT_FREE_BLOCK - jz .err - jnp .err - push eax - shr ecx, 12 + cmp ebx, 7 + jnz nosb7 + cmp [bgrlock], 0 + jz .err + mov eax, [CURRENT_TASK] + cmp [bgrlockpid], eax + jnz .err + mov eax, ecx + mov ebx, ecx + shr eax, 12 + mov ecx, [page_tabs+(eax-1)*4] + test cl, USED_BLOCK+DONT_FREE_BLOCK + jz .err + jnp .err + push eax + shr ecx, 12 + dec ecx @@: - and dword [page_tabs+eax*4], 0 - mov edx, eax - shl edx, 12 - push eax - invlpg [edx] - pop eax - inc eax - loop @b - pop eax - and dword [page_tabs+(eax-1)*4], not DONT_FREE_BLOCK - stdcall user_free, ebx - mov [esp+32], eax - and [bgrlockpid], 0 - mov [bgrlock], 0 - ret + and dword [page_tabs+eax*4], 0 + mov edx, eax + shl edx, 12 + push eax + invlpg [edx] + pop eax + inc eax + loop @b + pop eax + and dword [page_tabs+(eax-1)*4], not DONT_FREE_BLOCK + stdcall user_free, ebx + mov [esp+32], eax + and [bgrlockpid], 0 + mov [bgrlock], 0 + ret .err: - and dword [esp+32], 0 - ret + and dword [esp+32], 0 + ret nosb7: ret force_redraw_background: - mov [draw_data+32 + RECT.left],dword 0 - mov [draw_data+32 + RECT.top],dword 0 + and [draw_data+32 + RECT.left],dword 0 + and [draw_data+32 + RECT.top],dword 0 push eax ebx mov eax,[Screen_Max_X] mov ebx,[Screen_Max_Y] @@ -2484,117 +2559,118 @@ force_redraw_background: align 4 sys_getbackground: - - cmp eax,1 ; SIZE +; cmp eax,1 ; SIZE + dec ebx jnz nogb1 mov eax,[BgrDataWidth] shl eax,16 mov ax,[BgrDataHeight] - mov [esp+36],eax + mov [esp+32],eax ret nogb1: - - cmp eax,2 ; PIXEL +; cmp eax,2 ; PIXEL + dec ebx jnz nogb2 - mov eax, [img_background] - test ebx, ebx - jz @f - cmp eax, static_background_data - jz .ret + mov eax, [img_background] + test ecx, ecx + jz @f + cmp eax, static_background_data + jz .ret @@: - mov ecx, [mem_BACKGROUND] - add ecx, 4095 - and ecx, -4096 - sub ecx, 4 - cmp ebx, ecx - ja .ret + mov ebx, [mem_BACKGROUND] + add ebx, 4095 + and ebx, -4096 + sub ebx, 4 + cmp ecx, ebx + ja .ret - mov eax,[ebx+eax] + mov eax,[ecx+eax] and eax, 0xFFFFFF - mov [esp+36],eax + mov [esp+32],eax .ret: ret nogb2: - cmp eax,4 ; TILED / STRETCHED +; cmp eax,4 ; TILED / STRETCHED + dec ebx + dec ebx jnz nogb4 mov eax,[BgrDrawMode] nogb4: - mov [esp+36],eax + mov [esp+32],eax ret - align 4 sys_getkey: - mov [esp + 32],dword 1 - ; test main buffer - mov ebx, [CURRENT_TASK] ; TOP OF WINDOW STACK - movzx ecx, word [WIN_STACK + ebx * 2] - mov edx, [TASK_COUNT] - cmp ecx, edx - jne .finish - cmp [KEY_COUNT], byte 0 - je .finish - movzx eax, 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 - pop eax + mov [esp + 32],dword 1 + ; test main buffer + mov ebx, [CURRENT_TASK] ; TOP OF WINDOW STACK + movzx ecx, word [WIN_STACK + ebx * 2] + mov edx, [TASK_COUNT] + cmp ecx, edx + jne .finish + cmp [KEY_COUNT], byte 0 + je .finish + movzx eax, 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 + pop eax .ret_eax: - mov [esp + 32], eax - ret + mov [esp + 32], eax + ret .finish: ; test hotkeys buffer - mov ecx, hotkey_buffer + mov ecx, hotkey_buffer @@: - cmp [ecx], ebx - jz .found - add ecx, 8 - cmp ecx, hotkey_buffer + 120 * 8 - jb @b - ret + cmp [ecx], ebx + jz .found + add ecx, 8 + cmp ecx, hotkey_buffer + 120 * 8 + jb @b + ret .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 + 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_TASK] ; TOP OF WINDOW STACK - mov [esp + 32], dword 1 - movzx ecx, word [WIN_STACK + ebx * 2] - mov edx, [TASK_COUNT] ; less than 256 processes - cmp ecx, edx - jne .exit - movzx eax, byte [BTN_COUNT] - test eax, eax - jz .exit - mov eax, [BTN_BUFF] - shl eax, 8 + mov ebx, [CURRENT_TASK] ; TOP OF WINDOW STACK + mov [esp + 32], dword 1 + movzx ecx, word [WIN_STACK + ebx * 2] + mov edx, [TASK_COUNT] ; less than 256 processes + cmp ecx, edx + jne .exit + movzx eax, byte [BTN_COUNT] + test eax, eax + jz .exit + mov eax, [BTN_BUFF] + shl eax, 8 ; // Alver 22.06.2008 // { - mov al, byte [btn_down_determ] - and al,0xFE ; delete left button bit + mov al, byte [btn_down_determ] + and al,0xFE ; delete left button bit ; } \\ Alver \\ - mov [BTN_COUNT], byte 0 - mov [esp + 32], eax + mov [BTN_COUNT], byte 0 + mov [esp + 32], eax .exit: - ret + ret align 4 @@ -2612,78 +2688,78 @@ sys_cpuusage: ; +30 dword PID , process idenfification number ; - cmp ecx,-1 ; who am I ? + cmp ecx,-1 ; who am I ? jne .no_who_am_i mov ecx,[CURRENT_TASK] .no_who_am_i: - cmp ecx, max_processes - ja .nofillbuf + cmp ecx, max_processes + ja .nofillbuf ; +4: word: position of the window of thread in the window stack - mov ax, [WIN_STACK + ecx * 2] - mov [ebx+4], ax + mov ax, [WIN_STACK + ecx * 2] + mov [ebx+4], ax ; +6: word: number of the thread slot, which window has in the window stack ; position ecx (has no relation to the specific thread) - mov ax, [WIN_POS + ecx * 2] - mov [ebx+6], ax + mov ax, [WIN_POS + ecx * 2] + mov [ebx+6], ax - shl ecx, 5 + shl ecx, 5 ; +0: dword: memory usage - mov eax, [ecx+CURRENT_TASK+TASKDATA.cpu_usage] - mov [ebx], eax + mov eax, [ecx+CURRENT_TASK+TASKDATA.cpu_usage] + mov [ebx], eax ; +10: 11 bytes: name of the process - push ecx - lea eax, [ecx*8+SLOT_BASE+APPDATA.app_name] - add ebx, 10 - mov ecx, 11 - call memmove - pop ecx + push ecx + lea eax, [ecx*8+SLOT_BASE+APPDATA.app_name] + add ebx, 10 + mov ecx, 11 + call memmove + pop ecx ; +22: address of the process in memory ; +26: size of used memory - 1 - push edi - lea edi, [ebx+12] - xor eax, eax - mov edx, 0x100000*16 - cmp ecx, 1 shl 5 - je .os_mem - mov edx, [SLOT_BASE+ecx*8+APPDATA.mem_size] - mov eax, std_application_base_address + push edi + lea edi, [ebx+12] + xor eax, eax + mov edx, 0x100000*16 + cmp ecx, 1 shl 5 + je .os_mem + mov edx, [SLOT_BASE+ecx*8+APPDATA.mem_size] + mov eax, std_application_base_address .os_mem: - stosd - lea eax, [edx-1] - stosd + stosd + lea eax, [edx-1] + stosd ; +30: PID/TID - mov eax, [ecx+CURRENT_TASK+TASKDATA.pid] - stosd + mov eax, [ecx+CURRENT_TASK+TASKDATA.pid] + stosd ; window position and size - push esi - lea esi, [ecx + window_data + WDATA.box] - movsd - movsd - movsd - movsd + push esi + lea esi, [ecx + window_data + WDATA.box] + movsd + movsd + movsd + movsd ; Process state (+50) - mov eax, dword [ecx+CURRENT_TASK+TASKDATA.state] - stosd + mov eax, dword [ecx+CURRENT_TASK+TASKDATA.state] + stosd ; Window client area box - lea esi, [ecx*8 + SLOT_BASE + APPDATA.wnd_clientbox] - movsd - movsd - movsd - movsd + lea esi, [ecx*8 + SLOT_BASE + APPDATA.wnd_clientbox] + movsd + movsd + movsd + movsd ; Window state - mov al, [ecx+window_data+WDATA.fl_wstate] - stosb + mov al, [ecx+window_data+WDATA.fl_wstate] + stosb - pop esi - pop edi + pop esi + pop edi .nofillbuf: ; return number of processes @@ -2694,133 +2770,133 @@ sys_cpuusage: align 4 sys_clock: - cli + cli ; Mikhail Lisovin xx Jan 2005 - @@: mov al, 10 - out 0x70, al - in al, 0x71 - test al, al - jns @f - mov esi, 1 - call delay_ms - jmp @b + @@: mov al, 10 + out 0x70, al + in al, 0x71 + test al, al + jns @f + mov esi, 1 + call delay_ms + jmp @b @@: ; end Lisovin's fix - xor al,al ; seconds - out 0x70,al - in al,0x71 - movzx ecx,al - mov al,02 ; minutes - shl ecx,16 - out 0x70,al - in al,0x71 - movzx edx,al - mov al,04 ; hours - shl edx,8 - out 0x70,al - in al,0x71 - add ecx,edx - movzx edx,al - add ecx,edx - sti - mov [esp + 32], ecx - ret + xor al,al ; seconds + out 0x70,al + in al,0x71 + movzx ecx,al + mov al,02 ; minutes + shl ecx,16 + out 0x70,al + in al,0x71 + movzx edx,al + mov al,04 ; hours + shl edx,8 + out 0x70,al + in al,0x71 + add ecx,edx + movzx edx,al + add ecx,edx + sti + mov [esp + 32], ecx + ret align 4 sys_date: - cli - @@: mov al, 10 - out 0x70, al - in al, 0x71 - test al, al - jns @f - mov esi, 1 - call delay_ms - jmp @b + cli + @@: mov al, 10 + out 0x70, al + in al, 0x71 + test al, al + jns @f + mov esi, 1 + call delay_ms + jmp @b @@: - mov ch,0 - mov al,7 ; date - out 0x70,al - in al,0x71 - mov cl,al - mov al,8 ; month - shl ecx,16 - out 0x70,al - in al,0x71 - mov ch,al - mov al,9 ; year - out 0x70,al - in al,0x71 - mov cl,al - sti - mov [esp+32], ecx - ret + mov ch,0 + mov al,7 ; date + out 0x70,al + in al,0x71 + mov cl,al + mov al,8 ; month + shl ecx,16 + out 0x70,al + in al,0x71 + mov ch,al + mov al,9 ; year + out 0x70,al + in al,0x71 + mov cl,al + sti + mov [esp+32], ecx + ret ; redraw status sys_redrawstat: - cmp ebx, 1 - jne no_widgets_away - ; buttons away - mov ecx,[CURRENT_TASK] + cmp ebx, 1 + jne no_widgets_away + ; buttons away + mov ecx,[CURRENT_TASK] sys_newba2: - mov edi,[BTN_ADDR] - cmp [edi], dword 0 ; empty button list ? - je end_of_buttons_away - movzx ebx, word [edi] - inc ebx - mov eax,edi + mov edi,[BTN_ADDR] + cmp [edi], dword 0 ; empty button list ? + je end_of_buttons_away + movzx ebx, word [edi] + inc ebx + mov eax,edi sys_newba: - dec ebx - jz end_of_buttons_away + dec ebx + jz end_of_buttons_away - add eax, 0x10 - cmp cx, [eax] - jnz sys_newba + add eax, 0x10 + cmp cx, [eax] + jnz sys_newba - push eax ebx ecx - mov ecx,ebx - inc ecx - shl ecx, 4 - mov ebx, eax - add eax, 0x10 - call memmove - dec dword [edi] - pop ecx ebx eax + push eax ebx ecx + mov ecx,ebx + inc ecx + shl ecx, 4 + mov ebx, eax + add eax, 0x10 + call memmove + dec dword [edi] + pop ecx ebx eax - jmp sys_newba2 + jmp sys_newba2 end_of_buttons_away: - ret + ret no_widgets_away: - cmp ebx, 2 - jnz srl1 + cmp ebx, 2 + jnz srl1 - mov edx, [TASK_BASE] ; return whole screen draw area for this app - add edx, draw_data - CURRENT_TASK - mov [edx + RECT.left], 0 - mov [edx + RECT.top], 0 - mov eax, [Screen_Max_X] - mov [edx + RECT.right], eax - mov eax, [Screen_Max_Y] - mov [edx + RECT.bottom], eax + mov edx, [TASK_BASE] ; return whole screen draw area for this app + add edx, draw_data - CURRENT_TASK + mov [edx + RECT.left], 0 + mov [edx + RECT.top], 0 + mov eax, [Screen_Max_X] + mov [edx + RECT.right], eax + mov eax, [Screen_Max_Y] + mov [edx + RECT.bottom], eax - mov edi, [TASK_BASE] - or [edi - twdw + WDATA.fl_wdrawn], 1 ; no new position & buttons from app - call sys_window_mouse - ret + mov edi, [TASK_BASE] + or [edi - twdw + WDATA.fl_wdrawn], 1 ; no new position & buttons from app + call sys_window_mouse + ret srl1: - ret + ret sys_drawwindow: @@ -2832,9 +2908,9 @@ sys_drawwindow: ; cmp eax,0 ; type I - original style jne nosyswI inc [mouse_pause] - call [disable_mouse] + call [_display.disable_mouse] call sys_set_window - call [disable_mouse] + call [_display.disable_mouse] call drawwindow_I ;dec [mouse_pause] ;call [draw_pointer] @@ -2842,24 +2918,24 @@ sys_drawwindow: jmp draw_window_caption.2 nosyswI: - cmp al,1 ; type II - only reserve area, no draw + cmp al,1 ; type II - only reserve area, no draw jne nosyswII inc [mouse_pause] - call [disable_mouse] + call [_display.disable_mouse] call sys_set_window - call [disable_mouse] + call [_display.disable_mouse] call sys_window_mouse dec [mouse_pause] call [draw_pointer] ret nosyswII: - cmp al,2 ; type III - new style + cmp al,2 ; type III - new style jne nosyswIII inc [mouse_pause] - call [disable_mouse] + call [_display.disable_mouse] call sys_set_window - call [disable_mouse] + call [_display.disable_mouse] call drawwindow_III ;dec [mouse_pause] ;call [draw_pointer] @@ -2867,16 +2943,16 @@ sys_drawwindow: jmp draw_window_caption.2 nosyswIII: - cmp al,3 ; type IV - skinned window - je draw_skin_window - cmp al,4 ; type V - skinned window not sized! {not_sized_skin_window} + cmp al,3 ; type IV - skinned window + je draw_skin_window + cmp al,4 ; type V - skinned window not sized! {not_sized_skin_window} jne nosyswV draw_skin_window: inc [mouse_pause] - call [disable_mouse] + call [_display.disable_mouse] call sys_set_window - call [disable_mouse] + call [_display.disable_mouse] mov eax, [TASK_COUNT] movzx eax, word [WIN_POS + eax*2] cmp eax, [CURRENT_TASK] @@ -2894,180 +2970,180 @@ sys_drawwindow: draw_window_caption: - inc [mouse_pause] - call [disable_mouse] + inc [mouse_pause] + call [_display.disable_mouse] - xor eax,eax - mov edx,[TASK_COUNT] - movzx edx,word[WIN_POS+edx*2] - cmp edx,[CURRENT_TASK] - jne @f - inc eax - @@: mov edx,[CURRENT_TASK] - shl edx,5 - add edx,window_data - movzx ebx,[edx+WDATA.fl_wstyle] - and bl,0x0F - cmp bl,3 - je .draw_caption_style_3 ;{for 3 and 4 style write caption} - cmp bl,4 - je .draw_caption_style_3 + xor eax,eax + mov edx,[TASK_COUNT] + movzx edx,word[WIN_POS+edx*2] + cmp edx,[CURRENT_TASK] + jne @f + inc eax + @@: mov edx,[CURRENT_TASK] + shl edx,5 + add edx,window_data + movzx ebx,[edx+WDATA.fl_wstyle] + and bl,0x0F + cmp bl,3 + je .draw_caption_style_3 ;{for 3 and 4 style write caption} + cmp bl,4 + je .draw_caption_style_3 - jmp .not_style_3 + jmp .not_style_3 .draw_caption_style_3: - push edx - call drawwindow_IV_caption - add esp,4 - jmp .2 + push edx + call drawwindow_IV_caption + add esp,4 + jmp .2 .not_style_3: - cmp bl,2 - jne .not_style_2 + cmp bl,2 + jne .not_style_2 - call drawwindow_III_caption - jmp .2 + call drawwindow_III_caption + jmp .2 .not_style_2: - cmp bl,0 - jne .2 + cmp bl,0 + jne .2 - call drawwindow_I_caption + call drawwindow_I_caption ;-------------------------------------------------------------- - .2: ;jmp @f - mov edi,[CURRENT_TASK] - shl edi,5 - test [edi+window_data+WDATA.fl_wstyle],WSTYLE_HASCAPTION - jz @f - mov edx,[edi*8+SLOT_BASE+APPDATA.wnd_caption] - or edx,edx - jz @f + .2: ;jmp @f + mov edi,[CURRENT_TASK] + shl edi,5 + test [edi+window_data+WDATA.fl_wstyle],WSTYLE_HASCAPTION + jz @f + mov edx,[edi*8+SLOT_BASE+APPDATA.wnd_caption] + or edx,edx + jz @f - movzx eax,[edi+window_data+WDATA.fl_wstyle] - and al,0x0F - cmp al,3 - je .skinned - cmp al,4 - je .skinned + movzx eax,[edi+window_data+WDATA.fl_wstyle] + and al,0x0F + cmp al,3 + je .skinned + cmp al,4 + je .skinned - jmp .not_skinned + jmp .not_skinned .skinned: - mov ebp,[edi+window_data+WDATA.box.left-2] - mov bp,word[edi+window_data+WDATA.box.top] - movzx eax,word[edi+window_data+WDATA.box.width] - sub ax,[_skinmargins.left] - sub ax,[_skinmargins.right] - push edx - cwde - cdq - mov ebx,6 - idiv ebx - pop edx - or eax,eax - js @f - mov esi,eax - mov ebx,dword[_skinmargins.left-2] - mov bx,word[_skinh] - sub bx,[_skinmargins.bottom] - sub bx,[_skinmargins.top] - sar bx,1 - adc bx,0 - add bx,[_skinmargins.top] - add bx,-3 - add ebx,ebp - jmp .dodraw + mov ebp,[edi+window_data+WDATA.box.left-2] + mov bp,word[edi+window_data+WDATA.box.top] + movzx eax,word[edi+window_data+WDATA.box.width] + sub ax,[_skinmargins.left] + sub ax,[_skinmargins.right] + push edx + cwde + cdq + mov ebx,6 + idiv ebx + pop edx + or eax,eax + js @f + mov esi,eax + mov ebx,dword[_skinmargins.left-2] + mov bx,word[_skinh] + sub bx,[_skinmargins.bottom] + sub bx,[_skinmargins.top] + sar bx,1 + adc bx,0 + add bx,[_skinmargins.top] + add bx,-3 + add ebx,ebp + jmp .dodraw .not_skinned: - cmp al,1 - je @f + cmp al,1 + je @f - mov ebp,[edi+window_data+WDATA.box.left-2] - mov bp,word[edi+window_data+WDATA.box.top] - movzx eax,word[edi+window_data+WDATA.box.width] - sub eax,16 - push edx - cwde - cdq - mov ebx,6 - idiv ebx - pop edx - or eax,eax - js @f - mov esi,eax - mov ebx,0x00080007 - add ebx,ebp + mov ebp,[edi+window_data+WDATA.box.left-2] + mov bp,word[edi+window_data+WDATA.box.top] + movzx eax,word[edi+window_data+WDATA.box.width] + sub eax,16 + push edx + cwde + cdq + mov ebx,6 + idiv ebx + pop edx + or eax,eax + js @f + mov esi,eax + mov ebx,0x00080007 + add ebx,ebp .dodraw: - mov ecx,[common_colours+16];0x00FFFFFF - or ecx, 0x80000000 - xor edi,edi + mov ecx,[common_colours+16];0x00FFFFFF + or ecx, 0x80000000 + xor edi,edi ; // Alver 22.06.2008 // { ; call dtext - call dtext_asciiz_esi + call dtext_asciiz_esi ; } \\ Alver \\ @@: ;-------------------------------------------------------------- - dec [mouse_pause] - call [draw_pointer] - ret + dec [mouse_pause] + call [draw_pointer] + ret iglobal align 4 window_topleft dd \ - 1, 21,\ ;type 0 - 0, 0,\ ;type 1 - 5, 20,\ ;type 2 - 5, ?,\ ;type 3 {set by skin} - 5, ? ;type 4 {set by skin} + 1, 21,\ ;type 0 + 0, 0,\ ;type 1 + 5, 20,\ ;type 2 + 5, ?,\ ;type 3 {set by skin} + 5, ? ;type 4 {set by skin} endg set_window_clientbox: - push eax ecx edi + push eax ecx edi - mov eax,[_skinh] - mov [window_topleft+4*7],eax - mov [window_topleft+4*9],eax + mov eax,[_skinh] + mov [window_topleft+4*7],eax + mov [window_topleft+4*9],eax - mov ecx,edi - sub edi,window_data - shl edi,3 - test [ecx+WDATA.fl_wstyle],WSTYLE_CLIENTRELATIVE - jz @f + mov ecx,edi + sub edi,window_data + shl edi,3 + test [ecx+WDATA.fl_wstyle],WSTYLE_CLIENTRELATIVE + jz @f - movzx eax,[ecx+WDATA.fl_wstyle] - and eax,0x0F - mov eax,[eax*8+window_topleft+0] - mov [edi+SLOT_BASE+APPDATA.wnd_clientbox.left],eax - shl eax,1 - neg eax - add eax,[ecx+WDATA.box.width] - mov [edi+SLOT_BASE+APPDATA.wnd_clientbox.width],eax + movzx eax,[ecx+WDATA.fl_wstyle] + and eax,0x0F + mov eax,[eax*8+window_topleft+0] + mov [edi+SLOT_BASE+APPDATA.wnd_clientbox.left],eax + shl eax,1 + neg eax + add eax,[ecx+WDATA.box.width] + mov [edi+SLOT_BASE+APPDATA.wnd_clientbox.width],eax - movzx eax,[ecx+WDATA.fl_wstyle] - and eax,0x0F - push [eax*8+window_topleft+0] - mov eax,[eax*8+window_topleft+4] - mov [edi+SLOT_BASE+APPDATA.wnd_clientbox.top],eax - neg eax - sub eax,[esp] - add eax,[ecx+WDATA.box.height] - mov [edi+SLOT_BASE+APPDATA.wnd_clientbox.height],eax - add esp,4 + movzx eax,[ecx+WDATA.fl_wstyle] + and eax,0x0F + push [eax*8+window_topleft+0] + mov eax,[eax*8+window_topleft+4] + mov [edi+SLOT_BASE+APPDATA.wnd_clientbox.top],eax + neg eax + sub eax,[esp] + add eax,[ecx+WDATA.box.height] + mov [edi+SLOT_BASE+APPDATA.wnd_clientbox.height],eax + add esp,4 - pop edi ecx eax - ret + pop edi ecx eax + ret @@: - xor eax,eax - mov [edi+SLOT_BASE+APPDATA.wnd_clientbox.left],eax - mov [edi+SLOT_BASE+APPDATA.wnd_clientbox.top],eax - mov eax,[ecx+WDATA.box.width] - mov [edi+SLOT_BASE+APPDATA.wnd_clientbox.width],eax - mov eax,[ecx+WDATA.box.height] - mov [edi+SLOT_BASE+APPDATA.wnd_clientbox.height],eax + xor eax,eax + mov [edi+SLOT_BASE+APPDATA.wnd_clientbox.left],eax + mov [edi+SLOT_BASE+APPDATA.wnd_clientbox.top],eax + mov eax,[ecx+WDATA.box.width] + mov [edi+SLOT_BASE+APPDATA.wnd_clientbox.width],eax + mov eax,[ecx+WDATA.box.height] + mov [edi+SLOT_BASE+APPDATA.wnd_clientbox.height],eax - pop edi ecx eax - ret + pop edi ecx eax + ret sys_set_window: @@ -3101,39 +3177,39 @@ sys_set_window: call check_window_position - push ecx esi edi ; save for window fullscreen/resize + push ecx esi edi ; save for window fullscreen/resize ;mov esi,edi - mov cl, [edi+WDATA.fl_wstyle] - mov eax, [edi+WDATA.cl_frames] + mov cl, [edi+WDATA.fl_wstyle] + mov eax, [edi+WDATA.cl_frames] sub edi,window_data shl edi,3 add edi,SLOT_BASE - and cl,0x0F - mov [edi+APPDATA.wnd_caption],0 - cmp cl,3 - je set_APPDATA_wnd_caption - cmp cl,4 ; {SPraid.simba} - je set_APPDATA_wnd_caption + and cl,0x0F + mov [edi+APPDATA.wnd_caption],0 + cmp cl,3 + je set_APPDATA_wnd_caption + cmp cl,4 ; {SPraid.simba} + je set_APPDATA_wnd_caption - jmp @f + jmp @f set_APPDATA_wnd_caption: - mov [edi+APPDATA.wnd_caption],eax - @@: mov esi,[esp+0] + mov [edi+APPDATA.wnd_caption],eax + @@: mov esi,[esp+0] add edi, APPDATA.saved_box - movsd - movsd - movsd - movsd + movsd + movsd + movsd + movsd pop edi esi ecx - mov esi, [CURRENT_TASK] - movzx esi, word [WIN_STACK+esi*2] - lea esi, [WIN_POS+esi*2] - call waredraw + mov esi, [CURRENT_TASK] + movzx esi, word [WIN_STACK+esi*2] + lea esi, [WIN_POS+esi*2] + call waredraw ;;; mov ebx, 1 ;;; call delay_hs @@ -3145,13 +3221,13 @@ sys_set_window: add edx, ebx call calculatescreen - mov [KEY_COUNT],byte 0 ; empty keyboard buffer - mov [BTN_COUNT],byte 0 ; empty button buffer + mov [KEY_COUNT],byte 0 ; empty keyboard buffer + mov [BTN_COUNT],byte 0 ; empty button buffer newd: call set_window_clientbox - mov [edi+WDATA.fl_redraw],byte 0 ; no redraw + mov [edi+WDATA.fl_redraw],byte 0 ; no redraw mov edx,edi ret @@ -3159,18 +3235,18 @@ sys_set_window: syscall_windowsettings: .set_window_caption: - dec eax ; subfunction #1 - set window caption - jnz .get_window_caption + dec ebx ; subfunction #1 - set window caption + jnz .exit_fail - ; NOTE: only window owner thread can set its caption, - ; so there's no parameter for PID/TID + ; NOTE: only window owner thread can set its caption, + ; so there's no parameter for PID/TID - mov edi,[CURRENT_TASK] - shl edi,5 + mov edi,[CURRENT_TASK] + shl edi,5 - ; have to check if caption is within application memory limit - ; check is trivial, and if application resizes its memory, - ; caption still can become over bounds + ; have to check if caption is within application memory limit + ; check is trivial, and if application resizes its memory, + ; caption still can become over bounds ; diamond, 31.10.2006: check removed because with new memory manager ; there can be valid data after APPDATA.mem_size bound ; mov ecx,[edi*8+SLOT_BASE+APPDATA.mem_size] @@ -3178,115 +3254,115 @@ syscall_windowsettings: ; cmp ebx,ecx ; ja .exit_fail - mov [edi*8+SLOT_BASE+APPDATA.wnd_caption],ebx - or [edi+window_data+WDATA.fl_wstyle],WSTYLE_HASCAPTION + mov [edi*8+SLOT_BASE+APPDATA.wnd_caption],ecx + or [edi+window_data+WDATA.fl_wstyle],WSTYLE_HASCAPTION - call draw_window_caption + call draw_window_caption - xor eax,eax ; eax = 0 (success) - ret + xor eax,eax ; eax = 0 (success) + ret - .get_window_caption: - dec eax ; subfunction #2 - get window caption - jnz .exit_fail +; .get_window_caption: +; dec eax ; subfunction #2 - get window caption +; jnz .exit_fail - ; not implemented yet + ; not implemented yet .exit_fail: - xor eax,eax - inc eax ; eax = 1 (fail) - ret + xor eax,eax + inc eax ; eax = 1 (fail) + ret sys_window_move: - mov edi,[CURRENT_TASK] - shl edi,5 - add edi,window_data + mov edi,[CURRENT_TASK] + shl edi,5 + add edi,window_data - test [edi+WDATA.fl_wstate],WSTATE_MAXIMIZED - jnz .window_move_return + test [edi+WDATA.fl_wstate],WSTATE_MAXIMIZED + jnz .window_move_return - push dword [edi + WDATA.box.left] ; save old coordinates - push dword [edi + WDATA.box.top] - push dword [edi + WDATA.box.width] - push dword [edi + WDATA.box.height] + push dword [edi + WDATA.box.left] ; save old coordinates + push dword [edi + WDATA.box.top] + push dword [edi + WDATA.box.width] + push dword [edi + WDATA.box.height] - cmp eax,-1 ; set new position and size - je .no_x_reposition - mov [edi + WDATA.box.left], eax + cmp eax,-1 ; set new position and size + je .no_x_reposition + mov [edi + WDATA.box.left], eax .no_x_reposition: - cmp ebx,-1 - je .no_y_reposition - mov [edi + WDATA.box.top], ebx + cmp ebx,-1 + je .no_y_reposition + mov [edi + WDATA.box.top], ebx .no_y_reposition: - test [edi+WDATA.fl_wstate],WSTATE_ROLLEDUP - jnz .no_y_resizing + test [edi+WDATA.fl_wstate],WSTATE_ROLLEDUP + jnz .no_y_resizing - cmp ecx,-1 - je .no_x_resizing - mov [edi + WDATA.box.width], ecx + cmp ecx,-1 + je .no_x_resizing + mov [edi + WDATA.box.width], ecx .no_x_resizing: - cmp edx,-1 - je .no_y_resizing - mov [edi + WDATA.box.height], edx + cmp edx,-1 + je .no_y_resizing + mov [edi + WDATA.box.height], edx .no_y_resizing: - call check_window_position - call set_window_clientbox + call check_window_position + call set_window_clientbox - pushad ; save for window fullscreen/resize - mov esi,edi - sub edi,window_data - shr edi,5 - shl edi,8 - add edi, SLOT_BASE + APPDATA.saved_box - mov ecx,4 - cld - rep movsd - popad + pushad ; save for window fullscreen/resize + mov esi,edi + sub edi,window_data + shr edi,5 + shl edi,8 + add edi, SLOT_BASE + APPDATA.saved_box + mov ecx,4 + cld + rep movsd + popad - pushad ; calculcate screen at new position - mov eax, [edi + WDATA.box.left] - mov ebx, [edi + WDATA.box.top] - mov ecx, [edi + WDATA.box.width] - mov edx, [edi + WDATA.box.height] - add ecx,eax - add edx,ebx + pushad ; calculcate screen at new position + mov eax, [edi + WDATA.box.left] + mov ebx, [edi + WDATA.box.top] + mov ecx, [edi + WDATA.box.width] + mov edx, [edi + WDATA.box.height] + add ecx,eax + add edx,ebx - call calculatescreen - popad + call calculatescreen + popad - pop edx ; calculcate screen at old position - pop ecx - pop ebx - pop eax - add ecx,eax - add edx,ebx - mov [dlx],eax ; save for drawlimits - mov [dly],ebx - mov [dlxe],ecx - mov [dlye],edx - call calculatescreen + pop edx ; calculcate screen at old position + pop ecx + pop ebx + pop eax + add ecx,eax + add edx,ebx + mov [draw_limits.left],eax ; save for drawlimits + mov [draw_limits.top],ebx + mov [draw_limits.right],ecx + mov [draw_limits.bottom],edx + call calculatescreen - mov [edi + WDATA.fl_redraw], 1 ; flag the process as redraw + mov [edi + WDATA.fl_redraw], 1 ; flag the process as redraw - mov eax,edi ; redraw screen at old position - xor esi,esi - call redrawscreen + mov eax,edi ; redraw screen at old position + xor esi,esi + call redrawscreen - mov [DONT_DRAW_MOUSE],byte 0 ; mouse pointer - mov [MOUSE_BACKGROUND],byte 0 ; no mouse under - mov [MOUSE_DOWN],byte 0 ; react to mouse up/down + mov [DONT_DRAW_MOUSE],byte 0 ; mouse pointer + mov [MOUSE_BACKGROUND],byte 0 ; no mouse under + mov [MOUSE_DOWN],byte 0 ; react to mouse up/down - call [draw_pointer] + call [draw_pointer] - mov [window_move_pr],0 + mov [window_move_pr],0 .window_move_return: - ret + ret uglobal window_move_pr dd 0x0 @@ -3313,69 +3389,78 @@ endg ;3 - rdmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok. ;4 - wrmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok. ;--------------------------------------------------------------------------------------------- -sys_sheduler: ;noname & halyavin - cmp eax,0 - je shed_counter - cmp eax,2 - je perf_control - cmp eax,3 - je rdmsr_instr - cmp eax,4 - je wrmsr_instr - cmp eax,1 - jne not_supported - call change_task ;delay,0 -ret -shed_counter: - mov eax,[context_counter] - mov [esp+36],eax -not_supported: -ret -perf_control: - inc eax ;now eax=3 - cmp ebx,eax - je cache_disable - dec eax - cmp ebx,eax - je cache_enable - dec eax - cmp ebx,eax - je is_cache_enabled - dec eax - cmp ebx,eax - je modify_pce -ret +iglobal +align 4 +sheduler: + dd sys_sheduler.00 + dd change_task + dd sys_sheduler.02 + dd sys_sheduler.03 + dd sys_sheduler.04 +endg +sys_sheduler: +;rewritten by 29.12.2009 + jmp dword [sheduler+ebx*4] +;.shed_counter: +.00: + mov eax,[context_counter] + mov [esp+32],eax + ret -rdmsr_instr: +.02: +;.perf_control: + inc ebx ;before ebx=2, ebx=3 + cmp ebx,ecx ;if ecx=3, ebx=3 + jz cache_disable + + dec ebx ;ebx=2 + cmp ebx,ecx ; + jz cache_enable ;if ecx=2 and ebx=2 + + dec ebx ;ebx=1 + cmp ebx,ecx + jz is_cache_enabled ;if ecx=1 and ebx=1 + + dec ebx + test ebx,ecx ;ebx=0 and ecx=0 + jz modify_pce ;if ecx=0 + + ret + +.03: +;.rdmsr_instr: ;now counter in ecx ;(edx:eax) esi:edi => edx:esi -mov eax,esi -rdmsr -mov [esp+36],eax -mov [esp+24],edx ;ret in ebx? -ret + mov eax,esi + mov ecx,edx + rdmsr + mov [esp+32],eax + mov [esp+20],edx ;ret in ebx? + ret -wrmsr_instr: +.04: +;.wrmsr_instr: ;now counter in ecx ;(edx:eax) esi:edi => edx:esi - ; Fast Call MSR can't be destroy - ; Но MSR_AMD_EFER можно изменять, т.к. в этом регистре лиш - ; включаются/выключаются расширенные возможности - cmp ecx, MSR_SYSENTER_CS - je @f - cmp ecx, MSR_SYSENTER_ESP - je @f - cmp ecx, MSR_SYSENTER_EIP - je @f - cmp ecx, MSR_AMD_STAR - je @f + ; Fast Call MSR can't be destroy + ; Ќ® MSR_AMD_EFER ¬®¦­® Ё§¬Ґ­пвм, в.Є. ў н⮬ ॣЁбвॠ«Ёи + ; ўЄ«оз овбп/ўлЄ«оз овбп а биЁаҐ­­лҐ ў®§¬®¦­®бвЁ + cmp edx,MSR_SYSENTER_CS + je @f + cmp edx,MSR_SYSENTER_ESP + je @f + cmp edx,MSR_SYSENTER_EIP + je @f + cmp edx,MSR_AMD_STAR + je @f - mov eax, esi - wrmsr - ; mov [esp + 36], eax - ; mov [esp + 24], edx ;ret in ebx? + mov eax,esi + mov ecx,edx + wrmsr + ; mov [esp + 32], eax + ; mov [esp + 20], edx ;ret in ebx? @@: -ret + ret cache_disable: mov eax,cr0 @@ -3395,9 +3480,9 @@ is_cache_enabled: mov ebx,eax and eax,01100000000000000000000000000000b jz cache_disabled - mov [esp+36],ebx + mov [esp+32],ebx cache_disabled: - mov dword [esp+36],eax ;0 + mov dword [esp+32],eax ;0 ret modify_pce: @@ -3407,7 +3492,7 @@ modify_pce: ; xor eax,ebx ;invert pce bts eax,8 ;pce=cr4[8] mov cr4,eax - mov [esp+36],eax + mov [esp+32],eax ret ;--------------------------------------------------------------------------------------------- @@ -3415,27 +3500,28 @@ ret ; check if pixel is allowed to be drawn checkpixel: - push eax edx + push eax edx - mov edx,[Screen_Max_X] ; screen x size - inc edx - imul edx, ebx - mov dl, [eax+edx+display_data] ; lea eax, [...] + mov edx,[Screen_Max_X] ; screen x size + inc edx + imul edx, ebx + add eax, [_WinMapAddress] + mov dl, [eax+edx] ; lea eax, [...] - xor ecx, ecx - mov eax, [CURRENT_TASK] - cmp al, dl - setne cl + xor ecx, ecx + mov eax, [CURRENT_TASK] + cmp al, dl + setne cl - pop edx eax - ret + pop edx eax + ret iglobal cpustring db 'CPU',0 endg uglobal -background_defined db 0 ; diamond, 11.04.2006 +background_defined db 0 ; diamond, 11.04.2006 endg align 4 @@ -3446,8 +3532,8 @@ checkmisc: cmp [ctrl_alt_del], 1 jne nocpustart - mov ebp, cpustring - call fs_execute_from_sysdir + mov ebp, cpustring + call fs_execute_from_sysdir mov [ctrl_alt_del], 0 @@ -3456,24 +3542,24 @@ nocpustart: jne mouse_not_active mov [mouse_active], 0 xor edi, edi - mov ecx, [TASK_COUNT] + mov ecx, [TASK_COUNT] set_mouse_event: add edi, 256 - or [edi+SLOT_BASE+APPDATA.event_mask], dword 100000b + or [edi+SLOT_BASE+APPDATA.event_mask], dword 100000b loop set_mouse_event mouse_not_active: - cmp [REDRAW_BACKGROUND],byte 0 ; background update ? - jz nobackgr + cmp [REDRAW_BACKGROUND],byte 0 ; background update ? + jz nobackgr cmp [background_defined], 0 - jz nobackgr + jz nobackgr cmp [REDRAW_BACKGROUND], byte 2 jnz no_set_bgr_event xor edi, edi - mov ecx, [TASK_COUNT] + mov ecx, [TASK_COUNT] set_bgr_event: add edi, 256 - or [edi+SLOT_BASE+APPDATA.event_mask], 16 + or [edi+SLOT_BASE+APPDATA.event_mask], 16 loop set_bgr_event no_set_bgr_event: ; mov [draw_data+32 + RECT.left],dword 0 @@ -3491,7 +3577,7 @@ nobackgr: ; system shutdown request cmp [SYS_SHUTDOWN],byte 0 - je noshutdown + je noshutdown mov edx,[shutdown_processes] @@ -3509,24 +3595,24 @@ markz: no_mark_system_shutdown: - call [disable_mouse] + call [_display.disable_mouse] dec byte [SYS_SHUTDOWN] - je system_shutdown + je system_shutdown noshutdown: - mov eax,[TASK_COUNT] ; termination + mov eax,[TASK_COUNT] ; termination mov ebx,TASK_DATA+TASKDATA.state mov esi,1 newct: mov cl,[ebx] cmp cl,byte 3 - jz terminate + jz terminate cmp cl,byte 4 - jz terminate + jz terminate add ebx,0x20 inc esi @@ -3540,144 +3626,145 @@ redrawscreen: ; eax , if process window_data base is eax, do not set flag/limits - pushad - push eax + pushad + push eax ;;; mov ebx,2 ;;; call delay_hs - ;mov ecx,0 ; redraw flags for apps - xor ecx,ecx + ;mov ecx,0 ; redraw flags for apps + xor ecx,ecx newdw2: - inc ecx - push ecx + inc ecx + push ecx - mov eax,ecx - shl eax,5 - add eax,window_data + mov eax,ecx + shl eax,5 + add eax,window_data - cmp eax,[esp+4] - je not_this_task - ; check if window in redraw area - mov edi,eax + cmp eax,[esp+4] + je not_this_task + ; check if window in redraw area + mov edi,eax - cmp ecx,1 ; limit for background - jz bgli + cmp ecx,1 ; limit for background + jz bgli - mov eax, [edi + WDATA.box.left] - mov ebx, [edi + WDATA.box.top] - mov ecx, [edi + WDATA.box.width] - mov edx, [edi + WDATA.box.height] - add ecx,eax - add edx,ebx + mov eax, [edi + WDATA.box.left] + mov ebx, [edi + WDATA.box.top] + mov ecx, [edi + WDATA.box.width] + mov edx, [edi + WDATA.box.height] + add ecx,eax + add edx,ebx - mov ecx,[dlye] ; ecx = area y end ebx = window y start - cmp ecx,ebx - jb ricino + mov ecx,[draw_limits.bottom] ; ecx = area y end ebx = window y start + cmp ecx,ebx + jb ricino - mov ecx,[dlxe] ; ecx = area x end eax = window x start - cmp ecx,eax - jb ricino + mov ecx,[draw_limits.right] ; ecx = area x end eax = window x start + cmp ecx,eax + jb ricino - mov eax, [edi + WDATA.box.left] - mov ebx, [edi + WDATA.box.top] - mov ecx, [edi + WDATA.box.width] - mov edx, [edi + WDATA.box.height] - add ecx, eax - add edx, ebx + mov eax, [edi + WDATA.box.left] + mov ebx, [edi + WDATA.box.top] + mov ecx, [edi + WDATA.box.width] + mov edx, [edi + WDATA.box.height] + add ecx, eax + add edx, ebx - mov eax,[dly] ; eax = area y start edx = window y end - cmp edx,eax - jb ricino + mov eax,[draw_limits.top] ; eax = area y start edx = window y end + cmp edx,eax + jb ricino - mov eax,[dlx] ; eax = area x start ecx = window x end - cmp ecx,eax - jb ricino + mov eax,[draw_limits.left] ; eax = area x start ecx = window x end + cmp ecx,eax + jb ricino - bgli: + bgli: - cmp ecx,1 - jnz .az - mov al,[REDRAW_BACKGROUND] - cmp al,2 - jz newdw8 - test al,al - jz .az - lea eax,[edi+draw_data-window_data] - mov ebx,[dlx] - cmp ebx,[eax+RECT.left] - jae @f - mov [eax+RECT.left],ebx - @@: - mov ebx,[dly] - cmp ebx,[eax+RECT.top] - jae @f - mov [eax+RECT.top],ebx - @@: - mov ebx,[dlxe] - cmp ebx,[eax+RECT.right] - jbe @f - mov [eax+RECT.right],ebx - @@: - mov ebx,[dlye] - cmp ebx,[eax+RECT.bottom] - jbe @f - mov [eax+RECT.bottom],ebx - @@: - jmp newdw8 - .az: + cmp ecx,1 + jnz .az + mov al,[REDRAW_BACKGROUND] + cmp al,2 + jz newdw8 + test al,al + jz .az + lea eax,[edi+draw_data-window_data] + mov ebx,[draw_limits.left] + cmp ebx,[eax+RECT.left] + jae @f + mov [eax+RECT.left],ebx + @@: + mov ebx,[draw_limits.top] + cmp ebx,[eax+RECT.top] + jae @f + mov [eax+RECT.top],ebx + @@: + mov ebx,[draw_limits.right] + cmp ebx,[eax+RECT.right] + jbe @f + mov [eax+RECT.right],ebx + @@: + mov ebx,[draw_limits.bottom] + cmp ebx,[eax+RECT.bottom] + jbe @f + mov [eax+RECT.bottom],ebx + @@: + jmp newdw8 + .az: - mov eax,edi - add eax,draw_data-window_data + mov eax,edi + add eax,draw_data-window_data - mov ebx,[dlx] ; set limits - mov [eax + RECT.left], ebx - mov ebx,[dly] - mov [eax + RECT.top], ebx - mov ebx,[dlxe] - mov [eax + RECT.right], ebx - mov ebx,[dlye] - mov [eax + RECT.bottom], ebx + mov ebx,[draw_limits.left] ; set limits + mov [eax + RECT.left], ebx + mov ebx,[draw_limits.top] + mov [eax + RECT.top], ebx + mov ebx,[draw_limits.right] + mov [eax + RECT.right], ebx + mov ebx,[draw_limits.bottom] + mov [eax + RECT.bottom], ebx - sub eax,draw_data-window_data + sub eax,draw_data-window_data - cmp dword [esp],1 - jne nobgrd - mov byte [REDRAW_BACKGROUND], 1 + cmp dword [esp],1 + jne nobgrd + mov byte [REDRAW_BACKGROUND], 1 newdw8: nobgrd: - mov [eax + WDATA.fl_redraw],byte 1 ; mark as redraw + mov [eax + WDATA.fl_redraw],byte 1 ; mark as redraw ricino: not_this_task: - pop ecx + pop ecx - cmp ecx,[TASK_COUNT] - jle newdw2 + cmp ecx,[TASK_COUNT] + jle newdw2 - pop eax - popad + pop eax + popad - ret + ret calculatebackground: ; background - mov edi,display_data ; set os to use all pixels - mov eax,0x01010101 - mov ecx,1280*1024 / 4 - rep stosd + mov edi, [_WinMapAddress] ; set os to use all pixels + mov eax,0x01010101 + mov ecx, [_WinMapSize] + shr ecx, 2 + rep stosd - mov byte [REDRAW_BACKGROUND], 0 ; do not draw background! + mov byte [REDRAW_BACKGROUND], 0 ; do not draw background! - ret + ret uglobal - imax dd 0x0 + imax dd 0x0 endg @@ -3685,67 +3772,67 @@ endg delay_ms: ; delay in 1/1000 sec - push eax - push ecx + push eax + push ecx - mov ecx,esi - ; - imul ecx, 33941 - shr ecx, 9 - ; + mov ecx,esi + ; + imul ecx, 33941 + shr ecx, 9 + ; - in al,0x61 - and al,0x10 - mov ah,al - cld + in al,0x61 + and al,0x10 + mov ah,al + cld - cnt1: in al,0x61 - and al,0x10 - cmp al,ah - jz cnt1 + cnt1: in al,0x61 + and al,0x10 + cmp al,ah + jz cnt1 - mov ah,al - loop cnt1 + mov ah,al + loop cnt1 - pop ecx - pop eax + pop ecx + pop eax - ret + ret set_app_param: - mov edi, [TASK_BASE] - mov eax, [edi + TASKDATA.event_mask] - mov [edi + TASKDATA.event_mask], ebx - mov [esp+32], eax - ret + mov edi, [TASK_BASE] + mov eax, [edi + TASKDATA.event_mask] + mov [edi + TASKDATA.event_mask], ebx + mov [esp+32], eax + ret delay_hs: ; delay in 1/100 secs ; ebx = delay time - push ecx - push edx + push ecx + push edx - mov edx,[timer_ticks] + mov edx,[timer_ticks] newtic: - mov ecx,[timer_ticks] - sub ecx,edx - cmp ecx,ebx - jae zerodelay + mov ecx,[timer_ticks] + sub ecx,edx + cmp ecx,ebx + jae zerodelay - call change_task + call change_task - jmp newtic + jmp newtic zerodelay: - pop edx - pop ecx - - ret + pop edx + pop ecx + ret +align 16 ;very often call this subrutine memmove: ; memory move in bytes ; eax = from @@ -3754,21 +3841,20 @@ memmove: ; memory move in bytes test ecx, ecx jle .ret - push esi edi ecx mov edi, ebx mov esi, eax test ecx, not 11b - jz @f + jz @f push ecx shr ecx, 2 rep movsd pop ecx and ecx, 11b - jz .finish + jz .finish @@: rep movsb @@ -3837,7 +3923,7 @@ sys_programirq: jae .not_owner mov edi, [eax + TASKDATA.pid] cmp edi, [irq_owner + 4 * ecx] - je .spril1 + je .spril1 .not_owner: xor ecx, ecx inc ecx @@ -3860,11 +3946,11 @@ sys_programirq: align 4 get_irq_data: - movzx esi, bh ; save number of subfunction, if bh = 1, return data size, otherwise, read data + movzx esi, bh ; save number of subfunction, if bh = 1, return data size, otherwise, read data xor bh, bh cmp ebx, 16 jae .not_owner - mov edx, [4 * ebx + irq_owner] ; check for irq owner + mov edx, [4 * ebx + irq_owner] ; check for irq owner mov eax,[TASK_BASE] @@ -3878,28 +3964,28 @@ get_irq_data: gidril1: shl ebx, 12 - lea eax, [ebx + IRQ_SAVE] ; calculate address of the beginning of buffer + 0x0 - data size - mov edx, [eax] ; + 0x4 - data offset + lea eax, [ebx + IRQ_SAVE] ; calculate address of the beginning of buffer + 0x0 - data size + mov edx, [eax] ; + 0x4 - data offset dec esi jz gid1 - test edx, edx ; check if buffer is empty + test edx, edx ; check if buffer is empty jz gid1 mov ebx, [eax + 0x4] mov edi, ecx - mov ecx, 4000 ; buffer size, used frequently + mov ecx, 4000 ; buffer size, used frequently - cmp ebx, ecx ; check for the end of buffer, if end of buffer, begin cycle again + cmp ebx, ecx ; check for the end of buffer, if end of buffer, begin cycle again jb @f xor ebx, ebx @@: - lea esi, [ebx + edx] ; calculate data size and offset + lea esi, [ebx + edx] ; calculate data size and offset cld - cmp esi, ecx ; if greater than the buffer size, begin cycle again + cmp esi, ecx ; if greater than the buffer size, begin cycle again jbe @f sub ecx, ebx @@ -3916,201 +4002,182 @@ get_irq_data: rep movsb mov edx, [eax] - mov [eax], ecx ; set data size to zero - mov [eax + 0x4], ebx ; set data offset + mov [eax], ecx ; set data size to zero + mov [eax + 0x4], ebx ; set data offset gid1: - mov [esp+32], edx ; eax + mov [esp+32], edx ; eax ret set_io_access_rights: - - pushad - - mov edi, tss._io_map_0 - + push edi eax + mov edi, tss._io_map_0 ; mov ecx,eax ; and ecx,7 ; offset in byte - ; shr eax,3 ; number of byte ; add edi,eax - ; mov ebx,1 ; shl ebx,cl - - cmp ebp,0 ; enable access - ebp = 0 - jne siar1 - + test ebp,ebp +; cmp ebp,0 ; enable access - ebp = 0 + jnz siar1 ; not ebx ; and [edi],byte bl btr [edi], eax - - popad - + pop eax edi ret - siar1: - bts [edi], eax ; or [edi],byte bl ; disable access - ebp = 1 - - popad - + pop eax edi ret - +;reserve/free group of ports +; * eax = 46 - number function +; * ebx = 0 - reserve, 1 - free +; * ecx = number start arrea of ports +; * edx = number end arrea of ports (include last number of port) +;Return value: +; * eax = 0 - succesful +; * eax = 1 - error +; * The system has reserve this ports: +; 0..0x2d, 0x30..0x4d, 0x50..0xdf, 0xe5..0xff (include last number of port). +;destroys eax,ebx, ebp r_f_port_area: - test eax, eax + test ebx, ebx jnz free_port_area ; je r_port_area ; jmp free_port_area ; r_port_area: - pushad +; pushad - cmp ebx,ecx ; beginning > end ? + cmp ecx,edx ; beginning > end ? ja rpal1 - cmp ecx,65536 + cmp edx,65536 jae rpal1 - mov esi,[RESERVED_PORTS] - test esi,esi ; no reserved areas ? + mov eax,[RESERVED_PORTS] + test eax,eax ; no reserved areas ? je rpal2 - cmp esi,255 ; max reserved + cmp eax,255 ; max reserved jae rpal1 rpal3: - mov edi,esi - shl edi,4 - add edi,RESERVED_PORTS - cmp ebx,[edi+8] + mov ebx,eax + shl ebx,4 + add ebx,RESERVED_PORTS + cmp ecx,[ebx+8] ja rpal4 - cmp ecx,[edi+4] + cmp edx,[ebx+4] jae rpal1 ; jb rpal4 ; jmp rpal1 rpal4: - - dec esi + dec eax jnz rpal3 jmp rpal2 rpal1: - popad - mov eax,1 +; popad +; mov eax,1 + xor eax,eax + inc eax ret - rpal2: - popad - - +; popad ; enable port access at port IO map - cli - pushad ; start enable io map - - cmp ecx,65536 ;16384 - jae no_unmask_io ; jge - - mov eax,ebx - - new_port_access: - - pushad - - xor ebp,ebp ; enable - eax = port - call set_io_access_rights - - popad + cli + pushad ; start enable io map + cmp edx,65536 ;16384 + jae no_unmask_io ; jge + mov eax,ecx +; push ebp + xor ebp,ebp ; enable - eax = port +new_port_access: +; pushad + call set_io_access_rights +; popad inc eax - cmp eax,ecx + cmp eax,edx jbe new_port_access - - no_unmask_io: - - popad ; end enable io map +; pop ebp +no_unmask_io: + popad ; end enable io map sti - mov edi,[RESERVED_PORTS] - add edi,1 - mov [RESERVED_PORTS],edi - shl edi,4 - add edi,RESERVED_PORTS - mov esi,[TASK_BASE] - mov esi,[esi+TASKDATA.pid] - mov [edi],esi - mov [edi+4],ebx - mov [edi+8],ecx + mov eax,[RESERVED_PORTS] + add eax,1 + mov [RESERVED_PORTS],eax + shl eax,4 + add eax,RESERVED_PORTS + mov ebx,[TASK_BASE] + mov ebx,[ebx+TASKDATA.pid] + mov [eax],ebx + mov [eax+4],ecx + mov [eax+8],edx xor eax, eax ret free_port_area: - pushad - - mov esi,[RESERVED_PORTS] ; no reserved areas ? - test esi,esi - je frpal2 - mov edx,[TASK_BASE] - mov edx,[edx+TASKDATA.pid] +; pushad + mov eax,[RESERVED_PORTS] ; no reserved areas ? + test eax,eax + jz frpal2 + mov ebx,[TASK_BASE] + mov ebx,[ebx+TASKDATA.pid] frpal3: - mov edi,esi + mov edi,eax shl edi,4 add edi,RESERVED_PORTS - cmp edx,[edi] + cmp ebx,[edi] jne frpal4 - cmp ebx,[edi+4] + cmp ecx,[edi+4] jne frpal4 - cmp ecx,[edi+8] + cmp edx,[edi+8] jne frpal4 jmp frpal1 frpal4: - dec esi + dec eax jnz frpal3 frpal2: - popad - mov eax,1 +; popad + inc eax ret frpal1: - mov ecx,256 - sub ecx,esi - shl ecx,4 - mov esi,edi - add esi,16 - cld - rep movsb + push ecx + mov ecx,256 + sub ecx,eax + shl ecx,4 + mov esi,edi + add esi,16 + cld + rep movsb - dec dword [RESERVED_PORTS] + dec dword [RESERVED_PORTS] +;popad +;disable port access at port IO map - popad - - - ; disable port access at port IO map - - pushad ; start disable io map - - cmp ecx,65536 ;16384 +; pushad ; start disable io map + pop eax ;start port + cmp edx,65536 ;16384 jge no_mask_io - mov eax,ebx - - new_port_access_disable: - - pushad - - mov ebp,1 ; disable - eax = port +; mov eax,ecx + xor ebp,ebp + inc ebp +new_port_access_disable: +; pushad +; mov ebp,1 ; disable - eax = port call set_io_access_rights - - popad - +; popad inc eax - cmp eax,ecx + cmp eax,edx jbe new_port_access_disable - - no_mask_io: - - popad ; end disable io map - +no_mask_io: +; popad ; end disable io map xor eax, eax ret @@ -4203,7 +4270,7 @@ drawbackground: align 4 -syscall_putimage: ; PutImage +syscall_putimage: ; PutImage sys_putimage: test ecx,0x80008000 jnz .exit @@ -4214,40 +4281,40 @@ sys_putimage: .exit: ret @@: - mov edi,[current_slot] - add dx,word[edi+APPDATA.wnd_clientbox.top] - rol edx,16 - add dx,word[edi+APPDATA.wnd_clientbox.left] - rol edx,16 + mov edi,[current_slot] + add dx,word[edi+APPDATA.wnd_clientbox.top] + rol edx,16 + add dx,word[edi+APPDATA.wnd_clientbox.left] + rol edx,16 .forced: - push ebp esi 0 - mov ebp, putimage_get24bpp - mov esi, putimage_init24bpp + push ebp esi 0 + mov ebp, putimage_get24bpp + mov esi, putimage_init24bpp sys_putimage_bpp: ; call [disable_mouse] ; this will be done in xxx_putimage ; mov eax, vga_putimage - cmp [SCR_MODE], word 0x12 - jz @f ;.doit - mov eax, vesa12_putimage - cmp [SCR_MODE], word 0100000000000000b - jae @f - cmp [SCR_MODE], word 0x13 - jnz .doit + cmp [SCR_MODE], word 0x12 + jz @f ;.doit + mov eax, vesa12_putimage + cmp [SCR_MODE], word 0100000000000000b + jae @f + cmp [SCR_MODE], word 0x13 + jnz .doit @@: - mov eax, vesa20_putimage + mov eax, vesa20_putimage .doit: - inc [mouse_pause] - call eax - dec [mouse_pause] - pop ebp esi ebp - jmp [draw_pointer] + inc [mouse_pause] + call eax + dec [mouse_pause] + pop ebp esi ebp + jmp [draw_pointer] syscall_putimage_palette: - mov edi, esi - mov esi, edx - mov edx, ecx - mov ecx, ebx - mov ebx, eax + mov edi, esi + mov esi, edx + mov edx, ecx + mov ecx, ebx + mov ebx, eax sys_putimage_palette: ; ebx = pointer to image ; ecx = [xsize]*65536 + [ysize] @@ -4255,282 +4322,282 @@ sys_putimage_palette: ; esi = number of bits per pixel, must be 8, 24 or 32 ; edi = pointer to palette ; ebp = row delta - mov eax, [CURRENT_TASK] - shl eax, 8 - add dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.top] - rol edx, 16 - add dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.left] - rol edx, 16 + mov eax, [CURRENT_TASK] + shl eax, 8 + add dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.top] + rol edx, 16 + add dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.left] + rol edx, 16 .forced: - cmp esi, 1 - jnz @f - push edi - mov eax, [edi+4] - sub eax, [edi] - push eax - push dword [edi] - push 0ffffff80h - mov edi, esp - call put_mono_image - add esp, 12 - pop edi - ret + cmp esi, 1 + jnz @f + push edi + mov eax, [edi+4] + sub eax, [edi] + push eax + push dword [edi] + push 0ffffff80h + mov edi, esp + call put_mono_image + add esp, 12 + pop edi + ret @@: - cmp esi, 2 - jnz @f - push edi - push 0ffffff80h - mov edi, esp - call put_2bit_image - pop eax - pop edi - ret + cmp esi, 2 + jnz @f + push edi + push 0ffffff80h + mov edi, esp + call put_2bit_image + pop eax + pop edi + ret @@: - cmp esi, 4 - jnz @f - push edi - push 0ffffff80h - mov edi, esp - call put_4bit_image - pop eax - pop edi - ret + cmp esi, 4 + jnz @f + push edi + push 0ffffff80h + mov edi, esp + call put_4bit_image + pop eax + pop edi + ret @@: - push ebp esi ebp - cmp esi, 8 - jnz @f - mov ebp, putimage_get8bpp - mov esi, putimage_init8bpp - jmp sys_putimage_bpp + push ebp esi ebp + cmp esi, 8 + jnz @f + mov ebp, putimage_get8bpp + mov esi, putimage_init8bpp + jmp sys_putimage_bpp @@: - cmp esi, 15 - jnz @f - mov ebp, putimage_get15bpp - mov esi, putimage_init15bpp - jmp sys_putimage_bpp + cmp esi, 15 + jnz @f + mov ebp, putimage_get15bpp + mov esi, putimage_init15bpp + jmp sys_putimage_bpp @@: - cmp esi, 16 - jnz @f - mov ebp, putimage_get16bpp - mov esi, putimage_init16bpp - jmp sys_putimage_bpp + cmp esi, 16 + jnz @f + mov ebp, putimage_get16bpp + mov esi, putimage_init16bpp + jmp sys_putimage_bpp @@: - cmp esi, 24 - jnz @f - mov ebp, putimage_get24bpp - mov esi, putimage_init24bpp - jmp sys_putimage_bpp + cmp esi, 24 + jnz @f + mov ebp, putimage_get24bpp + mov esi, putimage_init24bpp + jmp sys_putimage_bpp @@: - cmp esi, 32 - jnz @f - mov ebp, putimage_get32bpp - mov esi, putimage_init32bpp - jmp sys_putimage_bpp + cmp esi, 32 + jnz @f + mov ebp, putimage_get32bpp + mov esi, putimage_init32bpp + jmp sys_putimage_bpp @@: - pop ebp esi ebp - ret + pop ebp esi ebp + ret put_mono_image: - push ebp esi ebp - mov ebp, putimage_get1bpp - mov esi, putimage_init1bpp - jmp sys_putimage_bpp + push ebp esi ebp + mov ebp, putimage_get1bpp + mov esi, putimage_init1bpp + jmp sys_putimage_bpp put_2bit_image: - push ebp esi ebp - mov ebp, putimage_get2bpp - mov esi, putimage_init2bpp - jmp sys_putimage_bpp + push ebp esi ebp + mov ebp, putimage_get2bpp + mov esi, putimage_init2bpp + jmp sys_putimage_bpp put_4bit_image: - push ebp esi ebp - mov ebp, putimage_get4bpp - mov esi, putimage_init4bpp - jmp sys_putimage_bpp + push ebp esi ebp + mov ebp, putimage_get4bpp + mov esi, putimage_init4bpp + jmp sys_putimage_bpp putimage_init24bpp: - lea eax, [eax*3] + lea eax, [eax*3] putimage_init8bpp: - ret + ret align 16 putimage_get24bpp: - movzx eax, byte [esi+2] - shl eax, 16 - mov ax, [esi] - add esi, 3 - ret 4 + movzx eax, byte [esi+2] + shl eax, 16 + mov ax, [esi] + add esi, 3 + ret 4 align 16 putimage_get8bpp: - movzx eax, byte [esi] - push edx - mov edx, [esp+8] - mov eax, [edx+eax*4] - pop edx - inc esi - ret 4 + movzx eax, byte [esi] + push edx + mov edx, [esp+8] + mov eax, [edx+eax*4] + pop edx + inc esi + ret 4 putimage_init1bpp: - add eax, ecx - push ecx - add eax, 7 - add ecx, 7 - shr eax, 3 - shr ecx, 3 - sub eax, ecx - pop ecx - ret + add eax, ecx + push ecx + add eax, 7 + add ecx, 7 + shr eax, 3 + shr ecx, 3 + sub eax, ecx + pop ecx + ret align 16 putimage_get1bpp: - push edx - mov edx, [esp+8] - mov al, [edx] - add al, al - jnz @f - lodsb - adc al, al + push edx + mov edx, [esp+8] + mov al, [edx] + add al, al + jnz @f + lodsb + adc al, al @@: - mov [edx], al - sbb eax, eax - and eax, [edx+8] - add eax, [edx+4] - pop edx - ret 4 + mov [edx], al + sbb eax, eax + and eax, [edx+8] + add eax, [edx+4] + pop edx + ret 4 putimage_init2bpp: - add eax, ecx - push ecx - add ecx, 3 - add eax, 3 - shr ecx, 2 - shr eax, 2 - sub eax, ecx - pop ecx - ret + add eax, ecx + push ecx + add ecx, 3 + add eax, 3 + shr ecx, 2 + shr eax, 2 + sub eax, ecx + pop ecx + ret align 16 putimage_get2bpp: - push edx - mov edx, [esp+8] - mov al, [edx] - mov ah, al - shr al, 6 - shl ah, 2 - jnz .nonewbyte - lodsb - mov ah, al - shr al, 6 - shl ah, 2 - add ah, 1 + push edx + mov edx, [esp+8] + mov al, [edx] + mov ah, al + shr al, 6 + shl ah, 2 + jnz .nonewbyte + lodsb + mov ah, al + shr al, 6 + shl ah, 2 + add ah, 1 .nonewbyte: - mov [edx], ah - mov edx, [edx+4] - movzx eax, al - mov eax, [edx+eax*4] - pop edx - ret 4 + mov [edx], ah + mov edx, [edx+4] + movzx eax, al + mov eax, [edx+eax*4] + pop edx + ret 4 putimage_init4bpp: - add eax, ecx - push ecx - add ecx, 1 - add eax, 1 - shr ecx, 1 - shr eax, 1 - sub eax, ecx - pop ecx - ret + add eax, ecx + push ecx + add ecx, 1 + add eax, 1 + shr ecx, 1 + shr eax, 1 + sub eax, ecx + pop ecx + ret align 16 putimage_get4bpp: - push edx - mov edx, [esp+8] - add byte [edx], 80h - jc @f - movzx eax, byte [edx+1] - mov edx, [edx+4] - and eax, 0x0F - mov eax, [edx+eax*4] - pop edx - ret 4 + push edx + mov edx, [esp+8] + add byte [edx], 80h + jc @f + movzx eax, byte [edx+1] + mov edx, [edx+4] + and eax, 0x0F + mov eax, [edx+eax*4] + pop edx + ret 4 @@: - movzx eax, byte [esi] - add esi, 1 - mov [edx+1], al - shr eax, 4 - mov edx, [edx+4] - mov eax, [edx+eax*4] - pop edx - ret 4 + movzx eax, byte [esi] + add esi, 1 + mov [edx+1], al + shr eax, 4 + mov edx, [edx+4] + mov eax, [edx+eax*4] + pop edx + ret 4 putimage_init32bpp: - shl eax, 2 - ret + shl eax, 2 + ret align 16 putimage_get32bpp: - lodsd - ret 4 + lodsd + ret 4 putimage_init15bpp: putimage_init16bpp: - add eax, eax - ret + add eax, eax + ret align 16 putimage_get15bpp: ; 0RRRRRGGGGGBBBBB -> 00000000RRRRR000GGGGG000BBBBB000 - push ecx edx - movzx eax, word [esi] - add esi, 2 - mov ecx, eax - mov edx, eax - and eax, 0x1F - and ecx, 0x1F shl 5 - and edx, 0x1F shl 10 - shl eax, 3 - shl ecx, 6 - shl edx, 9 - or eax, ecx - or eax, edx - pop edx ecx - ret 4 + push ecx edx + movzx eax, word [esi] + add esi, 2 + mov ecx, eax + mov edx, eax + and eax, 0x1F + and ecx, 0x1F shl 5 + and edx, 0x1F shl 10 + shl eax, 3 + shl ecx, 6 + shl edx, 9 + or eax, ecx + or eax, edx + pop edx ecx + ret 4 align 16 putimage_get16bpp: ; RRRRRGGGGGGBBBBB -> 00000000RRRRR000GGGGGG00BBBBB000 - push ecx edx - movzx eax, word [esi] - add esi, 2 - mov ecx, eax - mov edx, eax - and eax, 0x1F - and ecx, 0x3F shl 5 - and edx, 0x1F shl 11 - shl eax, 3 - shl ecx, 5 - shl edx, 8 - or eax, ecx - or eax, edx - pop edx ecx - ret 4 + push ecx edx + movzx eax, word [esi] + add esi, 2 + mov ecx, eax + mov edx, eax + and eax, 0x1F + and ecx, 0x3F shl 5 + and edx, 0x1F shl 11 + shl eax, 3 + shl ecx, 5 + shl edx, 8 + or eax, ecx + or eax, edx + pop edx ecx + ret 4 ; eax x beginning ; ebx y beginning ; ecx x end - ; edx y end + ; edx y end ; edi color __sys_drawbar: - mov esi,[current_slot] - add eax,[esi+APPDATA.wnd_clientbox.left] - add ecx,[esi+APPDATA.wnd_clientbox.left] - add ebx,[esi+APPDATA.wnd_clientbox.top] - add edx,[esi+APPDATA.wnd_clientbox.top] + mov esi,[current_slot] + add eax,[esi+APPDATA.wnd_clientbox.left] + add ecx,[esi+APPDATA.wnd_clientbox.left] + add ebx,[esi+APPDATA.wnd_clientbox.top] + add edx,[esi+APPDATA.wnd_clientbox.top] .forced: inc [mouse_pause] ; call [disable_mouse] cmp [SCR_MODE],word 0x12 - je dbv20 + je dbv20 sdbv20: cmp [SCR_MODE],word 0100000000000000b jge dbv20 cmp [SCR_MODE],word 0x13 - je dbv20 + je dbv20 call vesa12_drawbar dec [mouse_pause] call [draw_pointer] @@ -4545,36 +4612,36 @@ __sys_drawbar: kb_read: - push ecx edx + push ecx edx - mov ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's + mov ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's kr_loop: - in al,0x64 - test al,1 - jnz kr_ready - loop kr_loop - mov ah,1 - jmp kr_exit + in al,0x64 + test al,1 + jnz kr_ready + loop kr_loop + mov ah,1 + jmp kr_exit kr_ready: - push ecx - mov ecx,32 + push ecx + mov ecx,32 kr_delay: - loop kr_delay - pop ecx - in al,0x60 - xor ah,ah + loop kr_delay + pop ecx + in al,0x60 + xor ah,ah kr_exit: - pop edx ecx + pop edx ecx - ret + ret kb_write: - push ecx edx + push ecx edx - mov dl,al + mov dl,al ; mov ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's ; kw_loop1: ; in al,0x64 @@ -4584,75 +4651,75 @@ kb_write: ; mov ah,1 ; jmp kw_exit ; kw_ok1: - in al,0x60 - mov ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's + in al,0x60 + mov ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's kw_loop: - in al,0x64 - test al,2 - jz kw_ok - loop kw_loop - mov ah,1 - jmp kw_exit + in al,0x64 + test al,2 + jz kw_ok + loop kw_loop + mov ah,1 + jmp kw_exit kw_ok: - mov al,dl - out 0x60,al - mov ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's + mov al,dl + out 0x60,al + mov ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's kw_loop3: - in al,0x64 - test al,2 - jz kw_ok3 - loop kw_loop3 - mov ah,1 - jmp kw_exit + in al,0x64 + test al,2 + jz kw_ok3 + loop kw_loop3 + mov ah,1 + jmp kw_exit kw_ok3: - mov ah,8 + mov ah,8 kw_loop4: - mov ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's + mov ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's kw_loop5: - in al,0x64 - test al,1 - jnz kw_ok4 - loop kw_loop5 - dec ah - jnz kw_loop4 + in al,0x64 + test al,1 + jnz kw_ok4 + loop kw_loop5 + dec ah + jnz kw_loop4 kw_ok4: - xor ah,ah + xor ah,ah kw_exit: - pop edx ecx + pop edx ecx - ret + ret kb_cmd: - mov ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's + mov ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's c_wait: - in al,0x64 - test al,2 - jz c_send - loop c_wait - jmp c_error + in al,0x64 + test al,2 + jz c_send + loop c_wait + jmp c_error c_send: - mov al,bl - out 0x64,al - mov ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's + mov al,bl + out 0x64,al + mov ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's c_accept: - in al,0x64 - test al,2 - jz c_ok - loop c_accept + in al,0x64 + test al,2 + jz c_ok + loop c_accept c_error: - mov ah,1 - jmp c_exit + mov ah,1 + jmp c_exit c_ok: - xor ah,ah + xor ah,ah c_exit: - ret + ret setmouse: ; set mousepicture -pointer - ; ps2 mouse enable + ; ps2 mouse enable mov [MOUSE_PICTURE],dword mousepointer @@ -4674,60 +4741,60 @@ end if rerouteirqs: - cli + cli - mov al,0x11 ; icw4, edge triggered - out 0x20,al - call pic_delay - out 0xA0,al - call pic_delay + mov al,0x11 ; icw4, edge triggered + out 0x20,al + call pic_delay + out 0xA0,al + call pic_delay - mov al,0x20 ; generate 0x20 + - out 0x21,al - call pic_delay - mov al,0x28 ; generate 0x28 + - out 0xA1,al - call pic_delay + mov al,0x20 ; generate 0x20 + + out 0x21,al + call pic_delay + mov al,0x28 ; generate 0x28 + + out 0xA1,al + call pic_delay - mov al,0x04 ; slave at irq2 - out 0x21,al - call pic_delay - mov al,0x02 ; at irq9 - out 0xA1,al - call pic_delay + mov al,0x04 ; slave at irq2 + out 0x21,al + call pic_delay + mov al,0x02 ; at irq9 + out 0xA1,al + call pic_delay - mov al,0x01 ; 8086 mode - out 0x21,al - call pic_delay - out 0xA1,al - call pic_delay + mov al,0x01 ; 8086 mode + out 0x21,al + call pic_delay + out 0xA1,al + call pic_delay - mov al,255 ; mask all irq's - out 0xA1,al - call pic_delay - out 0x21,al - call pic_delay + mov al,255 ; mask all irq's + out 0xA1,al + call pic_delay + out 0x21,al + call pic_delay - mov ecx,0x1000 - cld -picl1: call pic_delay - loop picl1 + mov ecx,0x1000 + cld +picl1: call pic_delay + loop picl1 - mov al,255 ; mask all irq's - out 0xA1,al - call pic_delay - out 0x21,al - call pic_delay + mov al,255 ; mask all irq's + out 0xA1,al + call pic_delay + out 0x21,al + call pic_delay - cli + cli - ret + ret pic_delay: - jmp pdl1 -pdl1: ret + jmp pdl1 +pdl1: ret sys_msg_board_str: @@ -4749,43 +4816,43 @@ sys_msg_board_byte: ; in: al = byte to display ; out: nothing ; destroys: nothing - pushad - mov ecx, 2 - shl eax, 24 - jmp @f + pushad + mov ecx, 2 + shl eax, 24 + jmp @f sys_msg_board_word: ; in: ax = word to display ; out: nothing ; destroys: nothing - pushad - mov ecx, 4 - shl eax, 16 - jmp @f + pushad + mov ecx, 4 + shl eax, 16 + jmp @f sys_msg_board_dword: ; in: eax = dword to display ; out: nothing ; destroys: nothing - pushad - mov ecx, 8 + pushad + mov ecx, 8 @@: - push ecx - rol eax, 4 - push eax - and al, 0xF - cmp al, 10 - sbb al, 69h - das - mov bl, al - xor eax, eax - inc eax - call sys_msg_board - pop eax - pop ecx - loop @b - popad - ret + push ecx + rol eax, 4 + push eax + and al, 0xF + cmp al, 10 + sbb al, 69h + das + mov bl, al + xor eax, eax + inc eax + call sys_msg_board + pop eax + pop ecx + loop @b + popad + ret uglobal msg_board_data: times 4096 db 0 @@ -4797,60 +4864,59 @@ sys_msg_board: ; eax=1 : write : bl byte to write ; eax=2 : read : ebx=0 -> no data, ebx=1 -> data in al - mov ecx, [msg_board_count] - cmp eax, 1 - jne .smbl1 + mov ecx, [msg_board_count] + cmp eax, 1 + jne .smbl1 if defined debug_com_base - push dx ax + push dx ax - @@: ; wait for empty transmit register - mov dx, debug_com_base+5 - in al, dx - test al, 1 shl 5 - jz @r + @@: ; Wait for empty transmit register (yes, this slows down system..) + mov dx, debug_com_base+5 + in al, dx + test al, 1 shl 5 + jz @r - mov dx, debug_com_base ; TODO: replace this with variable - mov al, bl - out dx, al + mov dx, debug_com_base ; Output the byte + mov al, bl + out dx, al - pop ax dx + pop ax dx end if - - mov [msg_board_data+ecx],bl - inc ecx - and ecx, 4095 - mov [msg_board_count], ecx - mov [check_idle_semaphore], 5 - ret + mov [msg_board_data+ecx],bl + inc ecx + and ecx, 4095 + mov [msg_board_count], ecx + mov [check_idle_semaphore], 5 + ret .smbl1: - cmp eax, 2 - jne .smbl2 - test ecx, ecx - jz .smbl21 - mov eax, msg_board_data+1 - mov ebx, msg_board_data - movzx edx, byte [ebx] - call memmove - dec [msg_board_count] - mov [esp + 36], edx ;eax - mov [esp + 24], dword 1 - ret + cmp eax, 2 + jne .smbl2 + test ecx, ecx + jz .smbl21 + mov eax, msg_board_data+1 + mov ebx, msg_board_data + movzx edx, byte [ebx] + call memmove + dec [msg_board_count] + mov [esp + 36], edx ;eax + mov [esp + 24], dword 1 + ret .smbl21: - mov [esp+36], ecx - mov [esp+24], ecx + mov [esp+36], ecx + mov [esp+24], ecx .smbl2: - ret + ret sys_process_def: - mov edi, [CURRENT_TASK] + mov edi, [CURRENT_TASK] - dec eax ; 1 = set keyboard mode + dec eax ; 1 = set keyboard mode jne no_set_keyboard_setup shl edi,8 @@ -4860,7 +4926,7 @@ sys_process_def: no_set_keyboard_setup: - dec eax ; 2 = get keyboard mode + dec eax ; 2 = get keyboard mode jne no_get_keyboard_setup shl edi,8 @@ -4872,7 +4938,7 @@ sys_process_def: no_get_keyboard_setup: - dec eax ; 3 = get keyboard ctrl, alt, shift + dec eax ; 3 = get keyboard ctrl, alt, shift jne no_get_keyboard_cas ; xor eax,eax @@ -4894,70 +4960,70 @@ sys_process_def: no_get_keyboard_cas: - dec eax - jnz no_add_keyboard_hotkey + dec eax + jnz no_add_keyboard_hotkey - mov eax, hotkey_list + 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+36], 1 - ret + cmp dword [eax+8], 0 + jz .found_free + add eax, 16 + cmp eax, hotkey_list+16*256 + jb @b + mov dword [esp+36], 1 + ret .found_free: - mov [eax+8], edi - mov [eax+4], ecx - movzx ebx, bl - lea ebx, [hotkey_scancodes+ebx*4] - mov ecx, [ebx] - mov [eax], ecx - mov [ebx], eax - mov [eax+12], ebx - jecxz @f - mov [ecx+12], eax + mov [eax+8], edi + mov [eax+4], ecx + movzx ebx, bl + lea ebx, [hotkey_scancodes+ebx*4] + mov ecx, [ebx] + mov [eax], ecx + mov [ebx], eax + mov [eax+12], ebx + jecxz @f + mov [ecx+12], eax @@: - and dword [esp+36], 0 - ret + and dword [esp+36], 0 + ret no_add_keyboard_hotkey: - dec eax - jnz no_del_keyboard_hotkey + dec eax + jnz no_del_keyboard_hotkey - movzx ebx, bl - lea ebx, [hotkey_scancodes+ebx*4] - mov eax, [ebx] + movzx ebx, bl + lea ebx, [hotkey_scancodes+ebx*4] + mov eax, [ebx] .scan: - test eax, eax - jz .notfound - cmp [eax+8], edi - jnz .next - cmp [eax+4], ecx - jz .found + test eax, eax + jz .notfound + cmp [eax+8], edi + jnz .next + cmp [eax+4], ecx + jz .found .next: - mov eax, [eax] - jmp .scan + mov eax, [eax] + jmp .scan .notfound: - mov dword [esp+36], 1 - ret + mov dword [esp+36], 1 + ret .found: - mov ecx, [eax] - jecxz @f - mov edx, [eax+12] - mov [ecx+12], edx + 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+36], edx - ret + 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+36], edx + ret no_del_keyboard_hotkey: ret @@ -4965,9 +5031,9 @@ no_del_keyboard_hotkey: align 4 -sys_gs: ; direct screen access +sys_gs: ; direct screen access - cmp eax,1 ; resolution + cmp eax,1 ; resolution jne no_gs1 mov eax,[Screen_Max_X] shl eax,16 @@ -4977,21 +5043,21 @@ sys_gs: ; direct screen access ret no_gs1: - cmp eax,2 ; bits per pixel + cmp eax,2 ; bits per pixel jne no_gs2 movzx eax,byte [ScreenBPP] mov [esp+36],eax ret no_gs2: - cmp eax,3 ; bytes per scanline + cmp eax,3 ; bytes per scanline jne no_gs3 mov eax,[BytesPerScanLine] mov [esp+36],eax ret no_gs3: - mov [esp+36],dword -1 + or [esp+36],dword -1 ret @@ -5006,150 +5072,152 @@ sys_pci: align 4 ; system functions -syscall_setpixel: ; SetPixel +syscall_setpixel: ; SetPixel - mov eax, ebx - mov ebx, ecx - mov ecx, edx - mov edx, [TASK_BASE] - add eax, [edx-twdw+WDATA.box.left] - add ebx, [edx-twdw+WDATA.box.top] - mov edi, [current_slot] - add eax, [edi+APPDATA.wnd_clientbox.left] - add ebx, [edi+APPDATA.wnd_clientbox.top] - xor edi, edi ; no force + mov eax, ebx + mov ebx, ecx + mov ecx, edx + mov edx, [TASK_BASE] + add eax, [edx-twdw+WDATA.box.left] + add ebx, [edx-twdw+WDATA.box.top] + mov edi, [current_slot] + add eax, [edi+APPDATA.wnd_clientbox.left] + add ebx, [edi+APPDATA.wnd_clientbox.top] + xor edi, edi ; no force ; mov edi, 1 - call [disable_mouse] - jmp [putpixel] + call [_display.disable_mouse] + jmp [putpixel] align 4 -syscall_writetext: ; WriteText +syscall_writetext: ; WriteText - mov eax,[TASK_BASE] - mov ebp,[eax-twdw+WDATA.box.left] - push esi - mov esi,[current_slot] - add ebp,[esi+APPDATA.wnd_clientbox.left] - shl ebp,16 - add ebp,[eax-twdw+WDATA.box.top] - add bp,word[esi+APPDATA.wnd_clientbox.top] - pop esi - add ebx,ebp - mov eax,edi - xor edi,edi - jmp dtext + mov eax,[TASK_BASE] + mov ebp,[eax-twdw+WDATA.box.left] + push esi + mov esi,[current_slot] + add ebp,[esi+APPDATA.wnd_clientbox.left] + shl ebp,16 + add ebp,[eax-twdw+WDATA.box.top] + add bp,word[esi+APPDATA.wnd_clientbox.top] + pop esi + add ebx,ebp + mov eax,edi + xor edi,edi + jmp dtext align 4 -syscall_openramdiskfile: ; OpenRamdiskFile +syscall_openramdiskfile: ; OpenRamdiskFile - mov eax, ebx - mov ebx, ecx - mov ecx, edx - mov edx, esi - mov esi, 12 - call fileread - mov [esp+32], eax - ret + mov eax, ebx + mov ebx, ecx + mov ecx, edx + mov edx, esi + mov esi, 12 + call fileread + mov [esp+32], eax + ret align 4 -syscall_drawrect: ; DrawRect +syscall_drawrect: ; DrawRect - mov edi, edx ; color + gradient - and edi, 0x80FFFFFF - test bx, bx ; x.size - je .drectr - test cx, cx ; y.size - je .drectr + mov edi, edx ; color + gradient + and edi, 0x80FFFFFF + test bx, bx ; x.size + je .drectr + test cx, cx ; y.size + je .drectr - mov eax, ebx ; bad idea - mov ebx, ecx + mov eax, ebx ; bad idea + mov ebx, ecx - movzx ecx, ax ; ecx - x.size - shr eax, 16 ; eax - x.coord - movzx edx, bx ; edx - y.size - shr ebx, 16 ; ebx - y.coord - mov esi, [current_slot] + movzx ecx, ax ; ecx - x.size + shr eax, 16 ; eax - x.coord + movzx edx, bx ; edx - y.size + shr ebx, 16 ; ebx - y.coord + mov esi, [current_slot] - add eax, [esi + APPDATA.wnd_clientbox.left] - add ebx, [esi + APPDATA.wnd_clientbox.top] - add ecx, eax - add edx, ebx - jmp [drawbar] + add eax, [esi + APPDATA.wnd_clientbox.left] + add ebx, [esi + APPDATA.wnd_clientbox.top] + add ecx, eax + add edx, ebx + jmp [drawbar] .drectr: - ret + ret align 4 -syscall_getscreensize: ; GetScreenSize - mov ax, [Screen_Max_X] - shl eax, 16 - mov ax, [Screen_Max_Y] - mov [esp + 32], eax - ret +syscall_getscreensize: ; GetScreenSize + mov ax, [Screen_Max_X] + shl eax, 16 + mov ax, [Screen_Max_Y] + mov [esp + 32], eax + ret align 4 -syscall_cdaudio: ; CD +syscall_cdaudio: ; CD - cmp eax, 4 - jb .audio - jz .eject - cmp eax, 5 - jnz .ret + cmp ebx, 4 + jb .audio + jz .eject + cmp ebx, 5 + jnz .ret .load: - call .reserve - call LoadMedium - call .free - ret + call .reserve + call LoadMedium + ;call .free + jmp .free +; ret .eject: - call .reserve - call clear_CD_cache - call allow_medium_removal - call EjectMedium - call .free - ret + call .reserve + call clear_CD_cache + call allow_medium_removal + call EjectMedium +; call .free + jmp .free +; ret .audio: call sys_cd_audio - mov [esp+36],eax + mov [esp+36-4],eax .ret: ret .reserve: - call reserve_cd - mov eax, ebx - shr eax, 1 - and eax, 1 - inc eax - mov [ChannelNumber], ax - mov eax, ebx - and eax, 1 - mov [DiskNumber], al - call reserve_cd_channel - and ebx, 3 - inc ebx - mov [cdpos], ebx - add ebx, ebx - mov cl, 8 - sub cl, bl - mov al, [DRIVE_DATA+1] - shr al, cl - test al, 2 - jz .err - ret + call reserve_cd + mov eax, ecx + shr eax, 1 + and eax, 1 + inc eax + mov [ChannelNumber], ax + mov eax, ecx + and eax, 1 + mov [DiskNumber], al + call reserve_cd_channel + and ebx, 3 + inc ebx + mov [cdpos], ebx + add ebx, ebx + mov cl, 8 + sub cl, bl + mov al, [DRIVE_DATA+1] + shr al, cl + test al, 2 + jz .free;.err + ret .free: - call free_cd_channel - and [cd_status], 0 - ret + call free_cd_channel + and [cd_status], 0 + ret .err: - call .free - pop eax - ret + call .free +; pop eax + ret align 4 -syscall_getpixel: ; GetPixel +syscall_getpixel: ; GetPixel mov ecx, [Screen_Max_X] inc ecx xor edx, edx @@ -5169,10 +5237,10 @@ syscall_getarea: ;ecx = [size x]*65536 + [size y] ;edx = [start x]*65536 + [start y] pushad - inc [mouse_pause] + inc [mouse_pause] ; Check of use of the hardware cursor. - cmp [disable_mouse],__sys_disable_mouse - jne @f + cmp [_display.disable_mouse],__sys_disable_mouse + jne @f ; Since the test for the coordinates of the mouse should not be used, ; then use the call [disable_mouse] is not possible! cmp dword [MOUSE_VISIBLE],dword 0 @@ -5189,7 +5257,7 @@ syscall_getarea: mov ebx,edx and ebx,0xffff dec eax - dec ebx + dec ebx ; eax - x, ebx - y mov edx,ecx @@ -5197,22 +5265,22 @@ syscall_getarea: and edx,0xffff mov esi,ecx ; ecx - size x, edx - size y - - mov ebp,edx - dec ebp + + mov ebp,edx + dec ebp lea ebp,[ebp*3] - - imul ebp,esi - - mov esi,ecx - dec esi - lea esi,[esi*3] - + + imul ebp,esi + + mov esi,ecx + dec esi + lea esi,[esi*3] + add ebp,esi add ebp,edi add ebx,edx - + .start_y: push ecx edx .start_x: @@ -5229,46 +5297,46 @@ syscall_getarea: sub ebp,3 dec ecx jnz .start_x - pop edx ecx - dec ebx + pop edx ecx + dec ebx dec edx jnz .start_y - dec [mouse_pause] + dec [mouse_pause] ; Check of use of the hardware cursor. - cmp [disable_mouse],__sys_disable_mouse - jne @f - call [draw_pointer] + cmp [_display.disable_mouse],__sys_disable_mouse + jne @f + call [draw_pointer] @@: popad ret align 4 -syscall_drawline: ; DrawLine +syscall_drawline: ; DrawLine - mov edi, [TASK_BASE] - movzx eax, word[edi-twdw+WDATA.box.left] - mov ebp, eax - mov esi, [current_slot] - add ebp, [esi+APPDATA.wnd_clientbox.left] - add ax, word[esi+APPDATA.wnd_clientbox.left] - add ebp,ebx - shl eax, 16 - movzx ebx, word[edi-twdw+WDATA.box.top] - add eax, ebp - mov ebp, ebx - add ebp, [esi+APPDATA.wnd_clientbox.top] - add bx, word[esi+APPDATA.wnd_clientbox.top] - add ebp, ecx - shl ebx, 16 - xor edi, edi - add ebx, ebp - mov ecx, edx - jmp [draw_line] + mov edi, [TASK_BASE] + movzx eax, word[edi-twdw+WDATA.box.left] + mov ebp, eax + mov esi, [current_slot] + add ebp, [esi+APPDATA.wnd_clientbox.left] + add ax, word[esi+APPDATA.wnd_clientbox.left] + add ebp,ebx + shl eax, 16 + movzx ebx, word[edi-twdw+WDATA.box.top] + add eax, ebp + mov ebp, ebx + add ebp, [esi+APPDATA.wnd_clientbox.top] + add bx, word[esi+APPDATA.wnd_clientbox.top] + add ebp, ecx + shl ebx, 16 + xor edi, edi + add ebx, ebp + mov ecx, edx + jmp [draw_line] align 4 -syscall_getirqowner: ; GetIrqOwner +syscall_getirqowner: ; GetIrqOwner cmp ebx,16 jae .err @@ -5286,24 +5354,30 @@ syscall_getirqowner: ; GetIrqOwner align 4 -syscall_reserveportarea: ; ReservePortArea and FreePortArea +syscall_reserveportarea: ; ReservePortArea and FreePortArea call r_f_port_area - mov [esp+36],eax + mov [esp+32],eax ret align 4 -syscall_threads: ; CreateThreads +syscall_threads: ; CreateThreads +; eax=1 create thread +; +; ebx=thread start +; ecx=thread stack value +; +; on return : eax = pid - call sys_threads - mov [esp+36],eax + call new_sys_threads + + mov [esp+32],eax ret - align 4 -read_from_hd: ; Read from hd - fn not in use +read_from_hd: ; Read from hd - fn not in use mov edi,[TASK_BASE] add edi,TASKDATA.mem_start @@ -5318,342 +5392,364 @@ read_from_hd: ; Read from hd - fn not in use ret paleholder: - ret + ret align 4 set_screen: - cmp eax, [Screen_Max_X] - jne .set + cmp eax, [Screen_Max_X] + jne .set - cmp edx, [Screen_Max_Y] - jne .set - ret + cmp edx, [Screen_Max_Y] + jne .set + ret .set: - pushfd - cli + pushfd + cli - mov [Screen_Max_X], eax - mov [Screen_Max_Y], edx + mov [Screen_Max_X], eax + mov [Screen_Max_Y], edx + mov [BytesPerScanLine], ecx - mov [screen_workarea.right],eax - mov [screen_workarea.bottom], edx - inc eax - shl eax, 2 ;32 bpp - mov [BytesPerScanLine], eax - push ebx - push esi - push edi - call repos_windows - mov eax, 0 - mov ebx, 0 - mov ecx, [Screen_Max_X] - mov edx, [Screen_Max_Y] - call calculatescreen - pop edi - pop esi - pop ebx + mov [screen_workarea.right],eax + mov [screen_workarea.bottom], edx - popfd - ret + push ebx + push esi + push edi + + pushad + + stdcall kernel_free, [_WinMapAddress] + + mov eax, [_display.width] + mul [_display.height] + mov [_WinMapSize], eax + + stdcall kernel_alloc, eax + mov [_WinMapAddress], eax + test eax, eax + jz .epic_fail + + popad + + call repos_windows + xor eax, eax + xor ebx, ebx + mov ecx, [Screen_Max_X] + mov edx, [Screen_Max_Y] + call calculatescreen + pop edi + pop esi + pop ebx + + popfd + ret + +.epic_fail: + hlt ; Houston, we've had a problem ; --------------- APM --------------------- -apm_entry dp 0 -apm_vf dd 0 +uglobal +apm_entry dp 0 +apm_vf dd 0 +endg + align 4 sys_apm: - cmp word [apm_vf], 0 ; Check APM BIOS enable - jne @f - or [esp + 48], byte 1 ; error - mov [esp + 36], dword 8 ; 32-bit protected-mode interface not supported - ret + xor eax,eax + cmp word [apm_vf], ax ; Check APM BIOS enable + jne @f + inc eax + or dword [esp + 44], eax ; error + add eax,7 + mov dword [esp + 32], eax ; 32-bit protected-mode interface not supported + ret @@: - xchg eax, ecx - xchg ebx, ecx +; xchg eax, ecx +; xchg ebx, ecx - cmp al, 3 - ja @f - and [esp + 48], byte 0xfe ; emulate func 0..3 as func 0 - mov eax, [apm_vf] - mov [esp + 36], eax - shr eax, 16 - mov [esp + 32], eax - ret + cmp dx, 3 + ja @f + and [esp + 44], byte 0xfe ; emulate func 0..3 as func 0 + mov eax,[apm_vf] + mov [esp + 32], eax + shr eax, 16 + mov [esp + 28], eax + ret @@: - mov esi, [master_tab+(OS_BASE shr 20)] - xchg [master_tab], esi - push esi - mov edi, cr3 - mov cr3, edi ;flush TLB + mov esi,[master_tab+(OS_BASE shr 20)] + xchg [master_tab], esi + push esi + mov edi, cr3 + mov cr3, edi ;flush TLB - call pword [apm_entry] ; call APM BIOS + call pword [apm_entry] ;call APM BIOS - xchg eax, [esp] - mov [master_tab], eax - mov eax, cr3 - mov cr3, eax - pop eax + xchg eax, [esp] + mov [master_tab], eax + mov eax, cr3 + mov cr3, eax + pop eax - mov [esp + 8 ], edi - mov [esp + 12], esi - mov [esp + 24], ebx - mov [esp + 28], edx - mov [esp + 32], ecx - mov [esp + 36], eax - setc al - and [esp + 48], byte 0xfe - or [esp + 48], al - - - ret + mov [esp + 4 ], edi + mov [esp + 8], esi + mov [esp + 20], ebx + mov [esp + 24], edx + mov [esp + 28], ecx + mov [esp + 32], eax + setc al + and [esp + 44], byte 0xfe + or [esp + 44], al + ret ; ----------------------------------------- align 4 -undefined_syscall: ; Undefined system call +undefined_syscall: ; Undefined system call mov [esp + 32], dword -1 ret align 4 -system_shutdown: ; shut down the system +system_shutdown: ; shut down the system - cmp byte [BOOT_VAR+0x9030], 1 - jne @F - ret + cmp byte [BOOT_VAR+0x9030], 1 + jne @F + ret @@: - call stop_all_services - push 3 ; stop playing cd - pop eax - call sys_cd_audio + call stop_all_services + push 3 ; stop playing cd + pop eax + call sys_cd_audio yes_shutdown_param: - cli + cli - mov eax, kernel_file ; load kernel.mnt to 0x7000:0 - push 12 - pop esi - xor ebx,ebx - or ecx,-1 - mov edx, OS_BASE+0x70000 - call fileread + mov eax, kernel_file ; load kernel.mnt to 0x7000:0 + push 12 + pop esi + xor ebx,ebx + or ecx,-1 + mov edx, OS_BASE+0x70000 + call fileread - mov esi, restart_kernel_4000+OS_BASE+0x10000 ; move kernel re-starter to 0x4000:0 - mov edi,OS_BASE+0x40000 - mov ecx,1000 - rep movsb + mov esi, restart_kernel_4000+OS_BASE+0x10000 ; move kernel re-starter to 0x4000:0 + mov edi,OS_BASE+0x40000 + mov ecx,1000 + rep movsb - mov esi,OS_BASE+0x2F0000 ; restore 0x0 - 0xffff - mov edi, OS_BASE - mov ecx,0x10000/4 - cld - rep movsd + mov esi,OS_BASE+0x2F0000 ; restore 0x0 - 0xffff + mov edi, OS_BASE + mov ecx,0x10000/4 + cld + rep movsd - call restorefatchain + call restorefatchain - mov al, 0xFF - out 0x21, al - out 0xA1, al + mov al, 0xFF + out 0x21, al + out 0xA1, al if 0 - mov word [OS_BASE+0x467+0],pr_mode_exit - mov word [OS_BASE+0x467+2],0x1000 + mov word [OS_BASE+0x467+0],pr_mode_exit + mov word [OS_BASE+0x467+2],0x1000 - mov al,0x0F - out 0x70,al - mov al,0x05 - out 0x71,al + mov al,0x0F + out 0x70,al + mov al,0x05 + out 0x71,al - mov al,0xFE - out 0x64,al + mov al,0xFE + out 0x64,al - hlt - jmp $-1 + hlt + jmp $-1 else - cmp byte [OS_BASE + 0x9030], 2 - jnz no_acpi_power_off + cmp byte [OS_BASE + 0x9030], 2 + jnz no_acpi_power_off ; scan for RSDP ; 1) The first 1 Kb of the Extended BIOS Data Area (EBDA). - movzx eax, word [OS_BASE + 0x40E] - shl eax, 4 - jz @f - mov ecx, 1024/16 - call scan_rsdp - jnc .rsdp_found + movzx eax, word [OS_BASE + 0x40E] + shl eax, 4 + jz @f + mov ecx, 1024/16 + call scan_rsdp + jnc .rsdp_found @@: ; 2) The BIOS read-only memory space between 0E0000h and 0FFFFFh. - mov eax, 0xE0000 - mov ecx, 0x2000 - call scan_rsdp - jc no_acpi_power_off + mov eax, 0xE0000 + mov ecx, 0x2000 + call scan_rsdp + jc no_acpi_power_off .rsdp_found: - mov esi, [eax+16] ; esi contains physical address of the RSDT - mov ebp, [ipc_tmp] - stdcall map_page, ebp, esi, PG_MAP - lea eax, [esi+1000h] - lea edx, [ebp+1000h] - stdcall map_page, edx, eax, PG_MAP - and esi, 0xFFF - add esi, ebp - cmp dword [esi], 'RSDT' - jnz no_acpi_power_off - mov ecx, [esi+4] - sub ecx, 24h - jbe no_acpi_power_off - shr ecx, 2 - add esi, 24h + mov esi, [eax+16] ; esi contains physical address of the RSDT + mov ebp, [ipc_tmp] + stdcall map_page, ebp, esi, PG_MAP + lea eax, [esi+1000h] + lea edx, [ebp+1000h] + stdcall map_page, edx, eax, PG_MAP + and esi, 0xFFF + add esi, ebp + cmp dword [esi], 'RSDT' + jnz no_acpi_power_off + mov ecx, [esi+4] + sub ecx, 24h + jbe no_acpi_power_off + shr ecx, 2 + add esi, 24h .scan_fadt: - lodsd - mov ebx, eax - lea eax, [ebp+2000h] - stdcall map_page, eax, ebx, PG_MAP - lea eax, [ebp+3000h] - add ebx, 0x1000 - stdcall map_page, eax, ebx, PG_MAP - and ebx, 0xFFF - lea ebx, [ebx+ebp+2000h] - cmp dword [ebx], 'FACP' - jz .fadt_found - loop .scan_fadt - jmp no_acpi_power_off + lodsd + mov ebx, eax + lea eax, [ebp+2000h] + stdcall map_page, eax, ebx, PG_MAP + lea eax, [ebp+3000h] + add ebx, 0x1000 + stdcall map_page, eax, ebx, PG_MAP + and ebx, 0xFFF + lea ebx, [ebx+ebp+2000h] + cmp dword [ebx], 'FACP' + jz .fadt_found + loop .scan_fadt + jmp no_acpi_power_off .fadt_found: ; ebx is linear address of FADT - mov edi, [ebx+40] ; physical address of the DSDT - lea eax, [ebp+4000h] - stdcall map_page, eax, edi, PG_MAP - lea eax, [ebp+5000h] - lea esi, [edi+0x1000] - stdcall map_page, eax, esi, PG_MAP - and esi, 0xFFF - sub edi, esi - cmp dword [esi+ebp+4000h], 'DSDT' - jnz no_acpi_power_off - mov eax, [esi+ebp+4004h] ; DSDT length - sub eax, 36+4 - jbe no_acpi_power_off - add esi, 36 + mov edi, [ebx+40] ; physical address of the DSDT + lea eax, [ebp+4000h] + stdcall map_page, eax, edi, PG_MAP + lea eax, [ebp+5000h] + lea esi, [edi+0x1000] + stdcall map_page, eax, esi, PG_MAP + and esi, 0xFFF + sub edi, esi + cmp dword [esi+ebp+4000h], 'DSDT' + jnz no_acpi_power_off + mov eax, [esi+ebp+4004h] ; DSDT length + sub eax, 36+4 + jbe no_acpi_power_off + add esi, 36 .scan_dsdt: - cmp dword [esi+ebp+4000h], '_S5_' - jnz .scan_dsdt_cont - cmp byte [esi+ebp+4000h+4], 12h ; DefPackage opcode - jnz .scan_dsdt_cont - mov dl, [esi+ebp+4000h+6] - cmp dl, 4 ; _S5_ package must contain 4 bytes - ; ...in theory; in practice, VirtualBox has 2 bytes - ja .scan_dsdt_cont - cmp dl, 1 - jb .scan_dsdt_cont - lea esi, [esi+ebp+4000h+7] - xor ecx, ecx - cmp byte [esi], 0 ; 0 means zero byte, 0Ah xx means byte xx - jz @f - cmp byte [esi], 0xA - jnz no_acpi_power_off - inc esi - mov cl, [esi] + cmp dword [esi+ebp+4000h], '_S5_' + jnz .scan_dsdt_cont + cmp byte [esi+ebp+4000h+4], 12h ; DefPackage opcode + jnz .scan_dsdt_cont + mov dl, [esi+ebp+4000h+6] + cmp dl, 4 ; _S5_ package must contain 4 bytes + ; ...in theory; in practice, VirtualBox has 2 bytes + ja .scan_dsdt_cont + cmp dl, 1 + jb .scan_dsdt_cont + lea esi, [esi+ebp+4000h+7] + xor ecx, ecx + cmp byte [esi], 0 ; 0 means zero byte, 0Ah xx means byte xx + jz @f + cmp byte [esi], 0xA + jnz no_acpi_power_off + inc esi + mov cl, [esi] @@: - inc esi - cmp dl, 2 - jb @f - cmp byte [esi], 0 - jz @f - cmp byte [esi], 0xA - jnz no_acpi_power_off - inc esi - mov ch, [esi] + inc esi + cmp dl, 2 + jb @f + cmp byte [esi], 0 + jz @f + cmp byte [esi], 0xA + jnz no_acpi_power_off + inc esi + mov ch, [esi] @@: - jmp do_acpi_power_off + jmp do_acpi_power_off .scan_dsdt_cont: - inc esi - cmp esi, 0x1000 - jb @f - sub esi, 0x1000 - add edi, 0x1000 - push eax - lea eax, [ebp+4000h] - stdcall map_page, eax, edi, PG_MAP - push PG_MAP - lea eax, [edi+1000h] - push eax - lea eax, [ebp+5000h] - push eax - stdcall map_page - pop eax + inc esi + cmp esi, 0x1000 + jb @f + sub esi, 0x1000 + add edi, 0x1000 + push eax + lea eax, [ebp+4000h] + stdcall map_page, eax, edi, PG_MAP + push PG_MAP + lea eax, [edi+1000h] + push eax + lea eax, [ebp+5000h] + push eax + stdcall map_page + pop eax @@: - dec eax - jnz .scan_dsdt - jmp no_acpi_power_off + dec eax + jnz .scan_dsdt + jmp no_acpi_power_off do_acpi_power_off: - mov edx, [ebx+48] - test edx, edx - jz .nosmi - mov al, [ebx+52] - out dx, al - mov edx, [ebx+64] + mov edx, [ebx+48] + test edx, edx + jz .nosmi + mov al, [ebx+52] + out dx, al + mov edx, [ebx+64] @@: - in ax, dx - test al, 1 - jz @b + in ax, dx + test al, 1 + jz @b .nosmi: - and cx, 0x0707 - shl cx, 2 - or cx, 0x2020 - mov edx, [ebx+64] - in ax, dx - and ax, 203h - or ah, cl - out dx, ax - mov edx, [ebx+68] - test edx, edx - jz @f - in ax, dx - and ax, 203h - or ah, ch - out dx, ax + and cx, 0x0707 + shl cx, 2 + or cx, 0x2020 + mov edx, [ebx+64] + in ax, dx + and ax, 203h + or ah, cl + out dx, ax + mov edx, [ebx+68] + test edx, edx + jz @f + in ax, dx + and ax, 203h + or ah, ch + out dx, ax @@: - jmp $ + jmp $ no_acpi_power_off: - mov word [OS_BASE+0x467+0],pr_mode_exit - mov word [OS_BASE+0x467+2],0x1000 + mov word [OS_BASE+0x467+0],pr_mode_exit + mov word [OS_BASE+0x467+2],0x1000 - mov al,0x0F - out 0x70,al - mov al,0x05 - out 0x71,al + mov al,0x0F + out 0x70,al + mov al,0x05 + out 0x71,al - mov al,0xFE - out 0x64,al + mov al,0xFE + out 0x64,al - hlt - jmp $-1 + hlt + jmp $-1 scan_rsdp: - add eax, OS_BASE + add eax, OS_BASE .s: - cmp dword [eax], 'RSD ' - jnz .n - cmp dword [eax+4], 'PTR ' - jnz .n - xor edx, edx - xor esi, esi + cmp dword [eax], 'RSD ' + jnz .n + cmp dword [eax+4], 'PTR ' + jnz .n + xor edx, edx + xor esi, esi @@: - add dl, [eax+esi] - inc esi - cmp esi, 20 - jnz @b - test dl, dl - jz .ok + add dl, [eax+esi] + inc esi + cmp esi, 20 + jnz @b + test dl, dl + jz .ok .n: - add eax, 10h - loop .s - stc + add eax, 10h + loop .s + stc .ok: - ret + ret end if include "data32.inc" diff --git a/kernel/branches/net/kernel32.inc b/kernel/branches/net/kernel32.inc index b43b404635..542d0597c0 100644 --- a/kernel/branches/net/kernel32.inc +++ b/kernel/branches/net/kernel32.inc @@ -98,6 +98,14 @@ struc TASKDATA virtual at 0 TASKDATA TASKDATA end virtual + +TSTATE_RUNNING = 0 +TSTATE_RUN_SUSPENDED = 1 +TSTATE_WAIT_SUSPENDED = 2 +TSTATE_ZOMBIE = 3 +TSTATE_TERMINATING = 4 +TSTATE_WAITING = 5 +TSTATE_FREE = 9 ; structures definition struc WDATA { @@ -109,11 +117,12 @@ struc WDATA { .fl_wstate db ? .fl_wdrawn db ? .fl_redraw db ? + .sizeof: } virtual at 0 WDATA WDATA end virtual -label WDATA.fl_wstyle byte at 0x13 +label WDATA.fl_wstyle byte at WDATA.cl_workarea + 3 struc APPDATA { @@ -141,7 +150,9 @@ struc APPDATA .wait_begin dd ? ;+92 +++ .wait_test dd ? ;+96 +++ .wait_param dd ? ;+100 +++ - db 24 dup(?) ;+104 + .tls_base dd ? ;+104 + .dlls_list_ptr dd ? ;+108 + db 16 dup(?) ;+112 .wnd_shape dd ? ;+128 .wnd_shape_scale dd ? ;+132 diff --git a/kernel/branches/net/sound/playnote.inc b/kernel/branches/net/sound/playnote.inc index b4204f1db2..aa3e0f6b16 100644 --- a/kernel/branches/net/sound/playnote.inc +++ b/kernel/branches/net/sound/playnote.inc @@ -143,22 +143,24 @@ ReadNoteByte: ;result: ; al - note push eax - push ebx push ecx push edx + push esi + mov eax,[pidProcessNote] call pid_to_slot test eax,eax jz .failed - lea ebx,[esp+12] - mov ecx,1 - mov edx,[memAdrNote] + lea ecx,[esp+12] + mov edx,1 + mov esi,[memAdrNote] inc [memAdrNote] + call read_process_memory .failed: + pop esi pop edx pop ecx - pop ebx pop eax ret ;------------------- END CODE ------------------- diff --git a/kernel/branches/net/video/cursors.inc b/kernel/branches/net/video/cursors.inc index 4acdb1e119..86298f1f3e 100644 --- a/kernel/branches/net/video/cursors.inc +++ b/kernel/branches/net/video/cursors.inc @@ -32,7 +32,7 @@ virtual at 0 end virtual align 4 -proc vesa_init_cursor stdcall, dst:dword, src:dword +proc init_cursor stdcall, dst:dword, src:dword locals rBase dd ? pQuad dd ? @@ -290,7 +290,7 @@ endp ; ebx= src ; ecx= flags -vesa_cursor: +create_cursor: .src equ esp .flags equ esp+4 .hcursor equ esp+8 @@ -300,7 +300,7 @@ vesa_cursor: push ebx mov ebx, eax - mov eax, CURSOR_SIZE + mov eax, CURSOR.sizeof call create_kernel_object test eax, eax jz .fail @@ -330,7 +330,32 @@ vesa_cursor: mov [edi+CURSOR.hot_x], ecx mov [edi+CURSOR.hot_y], edx - stdcall vesa_init_cursor, eax, esi + stdcall init_cursor, eax, esi + + mov eax, [.hcursor] + lea eax, [eax+CURSOR.list_next] + lea edx, [_display.cr_list.next] + + pushfd + cli + mov ecx, [edx] + + mov [eax], ecx + mov [eax+4], edx + + mov [ecx+4], eax + mov [edx], eax + popfd + + mov eax, [.hcursor] +.check_hw: + cmp [_display.init_cursor], 0 + je .fail + + push eax + call [_display.init_cursor] + add esp, 4 + mov eax, [.hcursor] .fail: add esp, 12 @@ -346,8 +371,7 @@ vesa_cursor: mov ecx, 1024 cld rep movsd - add esp, 12 - ret + jmp .check_hw align 4 proc load_cursor stdcall, src:dword, flags:dword @@ -377,7 +401,7 @@ proc load_cursor stdcall, src:dword, flags:dword mov eax, [CURRENT_TASK+eax+4] mov ebx, [src] mov ecx, [flags] - call [create_cursor] ;eax, ebx, ecx + call create_cursor ;eax, ebx, ecx mov [handle], eax cmp word [flags], LOAD_FROM_FILE @@ -407,8 +431,6 @@ proc delete_cursor stdcall, hcursor:dword mov esi, [hcursor] cmp [esi+CURSOR.magic], 'CURS' jne .fail -; cmp [esi+CURSOR.size], CURSOR_SIZE -; jne .fail mov ebx, [CURRENT_TASK] shl ebx, 5 @@ -443,127 +465,78 @@ destroy_cursor: align 4 select_cursor: - + mov eax, [esp+4] + mov [_display.cursor], eax ret 4 -align 4 -proc init_cursors - - cmp [SCR_MODE],word 0x13 - jbe .fail - - test word [SCR_MODE], 0x4000 - jz .fail - - movzx eax, byte [ScreenBPP] - mov ebx, [BytesPerScanLine] - cmp eax, 32 - jne @F - sub ebx, 128 - jmp .init -@@: - cmp eax, 24 - jne .fail - sub ebx, 96 -.init: - mov [cur_def_interl], ebx - - stdcall load_driver, szHwMouse - mov [hw_cursor], eax - test eax, eax - jz .sw_mouse - - stdcall load_cursor, def_arrow, dword LOAD_FROM_MEM - mov [def_cursor], eax - ret -.sw_mouse: - mov [create_cursor], vesa_cursor - - stdcall load_cursor, def_arrow, dword LOAD_FROM_MEM - mov [def_cursor], eax - - mov ecx, [Screen_Max_X] - mov edx, [Screen_Max_Y] - inc ecx - inc edx - mov [scr_width], ecx - mov [scr_height], edx - - movzx ebx, byte [ScreenBPP] - cmp ebx, 32 - jne @F - - - mov dword [select_hw_cursor], select_cursor - mov dword [set_hw_cursor], cursor_32 - mov dword [hw_restore], restore_32 - ret -@@: - mov dword [select_hw_cursor], select_cursor - mov dword [set_hw_cursor], cursor_24 - mov dword [hw_restore], restore_24 - ret -.fail: - xor eax, eax - mov dword [select_hw_cursor], eax - mov dword [set_hw_cursor], eax - mov dword [hw_restore], eax - ret -endp - align 4 proc restore_24 stdcall, x:dword, y:dword - locals - w dd ? - endl - mov edi, [cur_saved_base] - mov edx, [cur_saved_h] - mov ebx, [cur_saved_interl] + push ebx + + mov ebx, [cur_saved_base] + mov edx, [cur.h] test edx, edx jz .ret + push esi + push edi + mov esi, cur_saved_data -@@: - mov ecx, [cur_saved_w] + mov ecx, [cur.w] lea ecx, [ecx+ecx*2] + push ecx +@@: + mov edi, ebx + add ebx, [BytesPerScanLine] + + mov ecx, [esp] rep movsb - add edi, ebx dec edx jnz @B + + pop ecx + pop edi + pop esi .ret: + pop ebx ret endp align 4 proc restore_32 stdcall, x:dword, y:dword - locals - w dd ? - endl - mov edi, [cur_saved_base] - mov edx, [cur_saved_h] - mov ebx, [cur_saved_interl] + push ebx + + mov ebx, [cur_saved_base] + mov edx, [cur.h] test edx, edx jz .ret + push esi + push edi + mov esi, cur_saved_data @@: - mov ecx, [cur_saved_w] + mov edi, ebx + add ebx, [BytesPerScanLine] + + mov ecx, [cur.w] rep movsd - add edi, ebx dec edx jnz @B + + pop edi .ret: + pop esi + pop ebx ret endp align 4 -proc cursor_24 stdcall, hcursor:dword, x:dword, y:dword +proc move_cursor_24 stdcall, hcursor:dword, x:dword, y:dword locals - w dd ? h dd ? - st dd ? _dx dd ? _dy dd ? endl @@ -575,87 +548,84 @@ proc cursor_24 stdcall, hcursor:dword, x:dword, y:dword xor edx, edx sub ecx, [esi+CURSOR.hot_x] + lea ebx, [ecx+32-1] mov [x], ecx sets dl dec edx and ecx, edx ;clip x to 0<=x + mov [cur.left], ecx mov edi, ecx sub edi, [x] mov [_dx], edi xor edx, edx sub eax, [esi+CURSOR.hot_y] + lea edi, [eax+32-1] mov [y], eax sets dl dec edx and eax, edx ;clip y to 0<=y - mov edi, eax - sub edi, [y] - mov [_dy], edi - - mul ebx - lea esi, [ecx+ecx*2] - add esi, [LFBAddress] - add esi, eax - mov [cur_saved_base],esi - - mov edi, [scr_width] - mov edx, [scr_height] - mov eax, 32 - - sub edi, ecx - cmp edi, eax - jng @F - mov edi, eax -@@: - sub edi, [_dx] - - sub edx, [y] - cmp edx, eax - jng @F + mov [cur.top], eax mov edx, eax + sub edx, [y] + mov [_dy], edx + + mul dword [BytesPerScanLine] + lea edx, [LFB_BASE+ecx*3] + add edx, eax + mov [cur_saved_base],edx + + cmp ebx, [Screen_Max_X] + jbe @F + mov ebx, [Screen_Max_X] @@: - sub edx, [_dy] + cmp edi, [Screen_Max_Y] + jbe @F + mov edi, [Screen_Max_Y] +@@: + mov [cur.right], ebx + mov [cur.bottom], edi - mov [w], edi - mov [h], edx - mov [cur_saved_w], edi - mov [cur_saved_h], edx + sub ebx, [x] + sub edi, [y] + inc ebx + inc edi - sub eax, edi - shl eax, 2 ;lea eax, [eax+eax*2] - lea edi, [edi+edi*2] - sub ebx, edi - mov [cur_saved_interl], ebx + mov [cur.w], ebx + mov [cur.h], edi + mov [h], edi + mov eax, edi mov edi, cur_saved_data @@: - mov ecx, [w] + mov esi, edx + add edx, [BytesPerScanLine] + mov ecx, [cur.w] lea ecx, [ecx+ecx*2] rep movsb - add esi, ebx - dec edx + dec eax jnz @B ;draw cursor - mov edx, eax - mov edi, [cur_saved_base] + mov ebx, [cur_saved_base] mov eax, [_dy] shl eax, 5 add eax, [_dx] - shl eax, 2 mov esi, [hcursor] mov esi, [esi+CURSOR.base] - add esi, eax + lea edx, [esi+eax*4] .row: - mov ecx, [w] + mov ecx, [cur.w] + mov esi, edx + mov edi, ebx + add edx, 32*4 + add ebx, [BytesPerScanLine] .pix: lodsd test eax, 0xFF000000 jz @F - - mov word [edi], ax + mov [edi], ax shr eax, 16 mov [edi+2],al @@: @@ -663,19 +633,16 @@ proc cursor_24 stdcall, hcursor:dword, x:dword, y:dword dec ecx jnz .pix - add esi, edx - add edi, ebx dec [h] jnz .row ret endp + align 4 -proc cursor_32 stdcall, hcursor:dword, x:dword, y:dword +proc move_cursor_32 stdcall, hcursor:dword, x:dword, y:dword locals - w dd ? h dd ? - st dd ? _dx dd ? _dy dd ? endl @@ -683,83 +650,80 @@ proc cursor_32 stdcall, hcursor:dword, x:dword, y:dword mov esi, [hcursor] mov ecx, [x] mov eax, [y] - mov ebx, [BytesPerScanLine] xor edx, edx sub ecx, [esi+CURSOR.hot_x] + lea ebx, [ecx+32-1] mov [x], ecx sets dl dec edx and ecx, edx ;clip x to 0<=x + mov [cur.left], ecx mov edi, ecx sub edi, [x] mov [_dx], edi xor edx, edx sub eax, [esi+CURSOR.hot_y] + lea edi, [eax+32-1] mov [y], eax sets dl dec edx and eax, edx ;clip y to 0<=y - mov edi, eax - sub edi, [y] - mov [_dy], edi - - mul ebx - lea esi, [eax+ecx*4] - add esi, [LFBAddress] - mov [cur_saved_base],esi - - mov edi, [scr_width] - mov edx, [scr_height] - mov eax, 32 - - sub edi, ecx - cmp edi, eax - jng @F - mov edi, eax -@@: - sub edi, [_dx] - - sub edx, [y] - cmp edx, eax - jng @F + mov [cur.top], eax mov edx, eax + sub edx, [y] + mov [_dy], edx + + mul dword [BytesPerScanLine] + lea edx, [LFB_BASE+eax+ecx*4] + mov [cur_saved_base],edx + + cmp ebx, [Screen_Max_X] + jbe @F + mov ebx, [Screen_Max_X] @@: - sub edx, [_dy] + cmp edi, [Screen_Max_Y] + jbe @F + mov edi, [Screen_Max_Y] +@@: + mov [cur.right], ebx + mov [cur.bottom], edi - mov [w], edi - mov [h], edx - mov [cur_saved_w], edi - mov [cur_saved_h], edx + sub ebx, [x] + sub edi, [y] + inc ebx + inc edi - sub eax, edi - shl eax, 2 - shl edi, 2 - sub ebx, edi - mov [cur_saved_interl], ebx + mov [cur.w], ebx + mov [cur.h], edi + mov [h], edi + mov eax, edi mov edi, cur_saved_data @@: - mov ecx, [w] + mov esi, edx + add edx, [BytesPerScanLine] + mov ecx, [cur.w] rep movsd - add esi, ebx - dec edx + dec eax jnz @B ;draw cursor - mov edx, eax - mov edi, [cur_saved_base] + mov ebx, [cur_saved_base] mov eax, [_dy] shl eax, 5 add eax, [_dx] - shl eax, 2 mov esi, [hcursor] mov esi, [esi+CURSOR.base] - add esi, eax + lea edx, [esi+eax*4] .row: - mov ecx, [w] + mov ecx, [cur.w] + mov esi, edx + mov edi, ebx + add edx, 32*4 + add ebx, [BytesPerScanLine] .pix: lodsd test eax, 0xFF000000 @@ -769,13 +733,73 @@ proc cursor_32 stdcall, hcursor:dword, x:dword, y:dword add edi, 4 dec ecx jnz .pix - add esi, edx - add edi, ebx + dec [h] jnz .row ret endp + +align 4 +get_display: + mov eax, _display + ret + +align 4 +init_display: + + xor eax, eax + mov edi, _display + + mov [edi+display_t.init_cursor], eax + mov [edi+display_t.select_cursor], eax + mov [edi+display_t.show_cursor], eax + mov [edi+display_t.move_cursor], eax + mov [edi+display_t.restore_cursor], eax + + lea ecx, [edi+display_t.cr_list.next] + mov [edi+display_t.cr_list.next], ecx + mov [edi+display_t.cr_list.prev], ecx + + cmp [SCR_MODE],word 0x13 + jbe .fail + + test word [SCR_MODE], 0x4000 + jz .fail + + mov ebx, restore_32 + mov ecx, move_cursor_32 + movzx eax, byte [ScreenBPP] + cmp eax, 32 + je @F + + mov ebx, restore_24 + mov ecx, move_cursor_24 + cmp eax, 24 + jne .fail +@@: + mov [_display.select_cursor], select_cursor + mov [_display.move_cursor], ecx + mov [_display.restore_cursor], ebx + + stdcall load_cursor, def_arrow, dword LOAD_FROM_MEM + mov [def_cursor], eax + ret +.fail: + xor eax, eax + mov [_display.select_cursor], eax + mov [_display.move_cursor], eax + ret + + + + + + + + + + align 4 def_arrow: file 'arrow.cur' diff --git a/kernel/branches/net/video/vesa12.inc b/kernel/branches/net/video/vesa12.inc index 48d22add80..6034790759 100644 --- a/kernel/branches/net/video/vesa12.inc +++ b/kernel/branches/net/video/vesa12.inc @@ -242,7 +242,7 @@ end if vesa12_drawbackground: - call [disable_mouse] + call [_display.disable_mouse] push eax push ebx @@ -258,7 +258,7 @@ vesa12_drawbackground: mov [imax],eax mov eax,[draw_data+32+RECT.left] mov ebx,[draw_data+32+RECT.top] - mov edi,0 ;no force + xor edi,edi ;no force v12dp3: @@ -327,7 +327,8 @@ vesa12_drawbackground: mov eax,[Screen_Max_X] add eax,1 mul ebx - cmp [eax+esi+WinMapAddress],byte 1 + add eax, [_WinMapAddress] + cmp [eax+esi],byte 1 jnz v12nbgp mov eax,[BytesPerScanLine] mov ebx,edi @@ -386,7 +387,7 @@ vesa12_drawbackground: vesa12_drawbar: - call [disable_mouse] + call [_display.disable_mouse] ;; mov [novesachecksum],dword 0 sub edx,ebx @@ -494,7 +495,7 @@ dbpi24bit12: sub eax,VGABasePtr mov ebx,3 div ebx - add eax,WinMapAddress + add eax, [_WinMapAddress] mov ebx,[CURRENT_TASK] cld @@ -585,7 +586,7 @@ dbpi24bit12: mov eax,edi sub eax,VGABasePtr shr eax,2 - add eax,WinMapAddress + add eax, [_WinMapAddress] mov ebx,[CURRENT_TASK] cld @@ -753,7 +754,7 @@ vesa12_putimage: ; mov ecx,320*65536+240 ; mov edx,20*65536+20 - call [disable_mouse] + call [_display.disable_mouse] mov [novesachecksum],dword 0 push esi @@ -830,7 +831,7 @@ vesa12_putimage: sub edx,VGABasePtr mov ebx,3 div ebx - add edx,WinMapAddress + add edx, [_WinMapAddress] mov ebx,[CURRENT_TASK] mov bh,[esp+4*3] @@ -909,7 +910,7 @@ vesa12_putimage: mov edx,edi sub edx,VGABasePtr shr edx,2 - add edx,WinMapAddress + add edx, [_WinMapAddress] mov ebx,[CURRENT_TASK] mov bh,[esp+4*3] diff --git a/kernel/branches/net/video/vesa20.inc b/kernel/branches/net/video/vesa20.inc index 532168deee..0a2d130fb7 100644 --- a/kernel/branches/net/video/vesa20.inc +++ b/kernel/branches/net/video/vesa20.inc @@ -28,7 +28,6 @@ $Revision$ ;BytesPerScanLine equ 0xfe08 ;LFBAddress equ 0xfe80 ;ScreenBPP equ 0xfbf1 -;WinMapAddress equ 0x460000 @@ -54,16 +53,14 @@ Vesa20_getpixel24: imul ebx, [BytesPerScanLine] ; ebx = y * y multiplier lea edi, [eax+eax*2] ; edi = x*3 add edi, ebx ; edi = x*3+(y*y multiplier) - add edi, [LFBAddress] ; ebx = where pixel is in memory - mov ecx, [edi] + mov ecx, [LFB_BASE+edi] and ecx, 0xffffff ret Vesa20_getpixel32: imul ebx, [BytesPerScanLine] ; ebx = y * y multiplier lea edi, [ebx+eax*4] ; edi = x*4+(y*y multiplier) - add edi, [LFBAddress] ; ebx = where pixel is in memory - mov ecx, [edi] + mov ecx, [LFB_BASE+edi] and ecx, 0xffffff ret @@ -106,7 +103,7 @@ align 16 vesa20_putimage: pushad - call [disable_mouse] + call [_display.disable_mouse] sub esp, putimg.stack_data ; save pointer to image mov [putimg.pti], ebx @@ -194,13 +191,12 @@ vesa20_putimage: shr ebx, 3 imul eax, ebx add edx, eax - add edx, [LFBAddress] ; pointer to pixel map mov eax, [putimg.abs_cy] imul eax, [Screen_Max_X] add eax, [putimg.abs_cy] add eax, [putimg.abs_cx] - add eax, WinMapAddress + add eax, [_WinMapAddress] xchg eax, ebp ; get process number mov ebx, [CURRENT_TASK] @@ -220,9 +216,9 @@ align 4 cmp [ebp], bl jne .skip ; mov eax, [esi] ; eax = RRBBGGRR - mov [edx], ax + mov [LFB_BASE+edx], ax shr eax, 16 - mov [edx+2], al + mov [LFB_BASE+edx+2], al .skip: ; add esi, 3 ;[putimg.source_bpp] add edx, 3 @@ -265,7 +261,7 @@ align 4 cmp [ebp], bl jne .skip ; mov eax, [esi] ; ecx = RRBBGGRR - mov [edx], eax + mov [LFB_BASE+edx], eax .skip: ; add esi, [putimg.source_bpp] add edx, 4 @@ -308,20 +304,25 @@ __sys_putpixel: ;;; mov [novesachecksum], dword 0 pushad - test edi,1 ; force ? - jnz .forced -; not forced: - push ecx ; save 24th bit in case negative pixel wanted - call checkpixel - test ecx,ecx - pop ecx - jnz .exit -.forced: cmp [Screen_Max_X], eax jb .exit cmp [Screen_Max_Y], ebx jb .exit -.ok: + test edi,1 ; force ? + jnz .forced + +; not forced: + + push eax + mov edx,[_display.width] ; screen x size + imul edx, ebx + add eax, [_WinMapAddress] + movzx edx, byte [eax+edx] + cmp edx, [CURRENT_TASK] + pop eax + jne .exit + +.forced: ; check if negation test ecx,0x01000000 jz .noneg @@ -342,11 +343,9 @@ Vesa20_putpixel24: imul ebx, [BytesPerScanLine] ; ebx = y * y multiplier lea edi, [eax+eax*2] ; edi = x*3 mov eax, [esp+32-8+4] - add edi, [LFBAddress] - add edi, ebx ; ebx = where to put pixel in memory - mov [edi], ax + mov [LFB_BASE+ebx+edi], ax shr eax, 16 - mov [edi+2], al + mov [LFB_BASE+ebx+edi+2], al ret @@ -357,8 +356,7 @@ Vesa20_putpixel32: imul ebx, [BytesPerScanLine] ; ebx = y * y multiplier lea edi, [ebx+eax*4] ; edi = x*4+(y*y multiplier) mov eax, [esp+32-8+4] ; eax = color - add edi, [LFBAddress] ; ebx = where to put pixel in memory - mov [edi], eax + mov [LFB_BASE+edi], eax ret ;************************************************* @@ -378,7 +376,7 @@ calculate_edi: align 4 __sys_draw_line: ; inc [mouse_pause] - call [disable_mouse] + call [_display.disable_mouse] ; draw a line ; eax = HIWORD = x1 @@ -568,7 +566,7 @@ align 4 ; edi color vesa20_drawbar: pushad - call [disable_mouse] + call [_display.disable_mouse] sub esp, drbar.stack_data mov [drbar.color], edi sub edx, ebx @@ -643,13 +641,12 @@ vesa20_drawbar: ; shr ebx, 3 imul eax, ebx add edx, eax - add edx, [LFBAddress] ; pointer to pixel map mov eax, [drbar.abs_cy] imul eax, [Screen_Max_X] add eax, [drbar.abs_cy] add eax, [drbar.abs_cx] - add eax, WinMapAddress + add eax, [_WinMapAddress] xchg eax, ebp ; get process number mov ebx, [CURRENT_TASK] @@ -674,8 +671,9 @@ align 4 .new_x: cmp byte [ebp], bl jne .skip - mov [edx], bh - mov [edx + 1], ax + + mov [LFB_BASE+edx], bh + mov [LFB_BASE+edx + 1], ax .skip: ; add pixel add edx, 3 @@ -710,7 +708,8 @@ align 4 .new_x: cmp byte [ebp], bl jne .skip - mov [edx], eax + + mov [LFB_BASE+edx], eax .skip: ; add pixel add edx, 4 @@ -737,62 +736,9 @@ align 4 mov [EGA_counter],1 ret -;voodoodbcplimit: - -; ebp:=(y+Ywin)*(ScreenXSize+1)+(x+Xwin)+AddrBuffer - - -; pusha - -; xor edx,edx -; mov eax,ebp -; mov ebx,[Screen_Max_X] ; Screen_X_size -; inc ebx ; +1 -; sub eax,WinMapAddress ; -AddrBuffer -; div ebx ; -; mov ebx,eax ; ebx:=Y -; mov eax,edx ; eax:=X -; call cplimit - -; test ecx,ecx -; jne dbcpl12 -; popa -; clc -; ret -; dbcpl12: -; popa -; stc -; ret - - - - -;dbcplimit: - -; pusha - -; xor edx,edx -; mov ebx,[Screen_Max_X] -; inc ebx -; sub eax,WinMapAddress -; div ebx -; mov ebx,eax -; mov eax,edx -; call cplimit - -; test ecx,ecx -; jne dbcpl1 -; popa -; clc -; ret -; dbcpl1: -; popa -; stc -; ret - - +align 4 vesa20_drawbackground_tiled: - call [disable_mouse] + call [_display.disable_mouse] pushad ; External loop for all y from start to end mov ebx, [draw_data+32+RECT.top] ; y start @@ -810,10 +756,11 @@ dp2: jz @f add ebp, eax @@: - add ebp, [LFBAddress] + add ebp, LFB_BASE ; ebp:=Y*BytesPerScanLine+X*BytesPerPixel+AddrLFB call calculate_edi xchg edi, ebp + add ebp, [_WinMapAddress] ; Now eax=x, ebx=y, edi->output, ebp=offset in WinMapAddress ; 2) Calculate offset in background memory block push eax @@ -842,7 +789,7 @@ dp2: ; esi -> bgr memory, edi -> output ; ebp = offset in WinMapAddress dp3: - cmp [ebp+WinMapAddress], dl + cmp [ebp], dl jnz nbgp movsb movsb @@ -881,7 +828,7 @@ dp4: vesa20_drawbackground_stretch: - call [disable_mouse] + call [_display.disable_mouse] pushad ; Helper variables ; calculate 2^32*(BgrDataWidth-1) mod (ScreenWidth-1) @@ -917,7 +864,6 @@ vesa20_drawbackground_stretch: jz @f add ebp, eax @@: - add ebp, [LFBAddress] ; ebp:=Y*BytesPerScanLine+X*BytesPerPixel+AddrLFB call calculate_edi xchg edi, ebp @@ -985,7 +931,8 @@ sdp3: ; qword [esp+28] = 2^32*(BgrDataHeight-1)/(ScreenHeight-1) ; qword [esp+36] = 2^32*(BgrDataWidth-1)/(ScreenWidth-1) sdp3a: - cmp [ebp+WinMapAddress], byte 1 + mov eax, [_WinMapAddress] + cmp [ebp+eax], byte 1 jnz snbgp mov eax, [bgr_cur_line+esi] test ecx, ecx @@ -993,9 +940,11 @@ sdp3a: mov ebx, [bgr_next_line+esi] call [overlapping_of_points_ptr] .novert: - mov [edi], ax + + mov [LFB_BASE+edi], ax shr eax, 16 - mov [edi+2], al + + mov [LFB_BASE+edi+2], al snbgp: cmp [ScreenBPP], byte 25 sbb edi, -4 diff --git a/kernel/branches/net/video/vga.inc b/kernel/branches/net/video/vga.inc index 12cc0f7dcd..bd23d1a1c2 100644 --- a/kernel/branches/net/video/vga.inc +++ b/kernel/branches/net/video/vga.inc @@ -175,8 +175,8 @@ checkVga_N13: cld m13pix: lodsd - cmp eax,0 - je .save_pixel + test eax,eax + jz .save_pixel push eax mov ebx,eax and eax,(128+64+32) ; blue @@ -259,8 +259,8 @@ VGA_draw_32_pixels: mov cl,8 .convert_pixels_to_VGA: lodsd ; eax = 24bit colour - cmp eax,0 - je .end + test eax,eax + jz .end rol eax,8 mov al,ch ror eax,8 @@ -335,8 +335,8 @@ VGA_putpixel: pushfd ; edi = address, eax = 24bit colour, ecx = bit no. (modulo 8) xor edx,edx - cmp eax,0 - je .p13cont + test eax,eax + jz .p13cont cmp al,85 jbe .p13green or dl,0x01 diff --git a/kernel/branches/net/vmodeint.inc b/kernel/branches/net/vmodeint.inc index 3cb0a1c56e..80eb1c0430 100644 --- a/kernel/branches/net/vmodeint.inc +++ b/kernel/branches/net/vmodeint.inc @@ -24,15 +24,16 @@ uglobal old_screen_height dd ? endg - cmp eax,13 ; CALL VIDEOMODE DRIVER FUNCTIONS - jne .no_vmode_drv_access +; cmp eax,13 ; CALL VIDEOMODE DRIVER FUNCTIONS + dec ebx + jnz .no_vmode_drv_access pushd [Screen_Max_X] [Screen_Max_Y] popd [old_screen_height] [old_screen_width] or eax,-1 ; If driver is absent then eax does not change call (VMODE_BASE+0x100) ; Entry point of video driver - mov [esp+36],eax - mov [esp+24],ebx - mov [esp+32],ecx + mov [esp+36-4],eax + mov [esp+24-4],ebx + mov [esp+32-4],ecx ; mov [esp+28],edx mov eax,[old_screen_width] mov ebx,[old_screen_height] @@ -46,8 +47,8 @@ endg sub [screen_workarea.bottom],ebx call repos_windows - mov eax, 0 - mov ebx, 0 + xor eax,eax + xor ebx,ebx mov ecx, [Screen_Max_X] mov edx, [Screen_Max_Y] call calculatescreen