diff --git a/kernel/branches/net/blkdev/cd_drv.inc b/kernel/branches/net/blkdev/cd_drv.inc index 422b2dda0b..4eea37212d 100644 --- a/kernel/branches/net/blkdev/cd_drv.inc +++ b/kernel/branches/net/blkdev/cd_drv.inc @@ -33,32 +33,32 @@ NoTickWaitTime equ 0xfffff ;* Данные считывается в массив CDDataBuf. * ;************************************************* ReadCD: - pusha + pusha ; Задать размер сектора - mov [CDBlockSize],2048 ;2352 + mov [CDBlockSize],2048 ;2352 ; Очистить буфер пакетной команды - call clear_packet_buffer + 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 + ; Задать код команды 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+8],byte 1 + ; Задать считывание данных в полном объеме ; mov [PacketCommand+9],byte 0xF8 ; Подать команду - call SendPacketDatCommand - popa - ret + call SendPacketDatCommand + popa + ret ;******************************************** ;* ЧТЕНИЕ СЕКТОРА С ПОВТОРАМИ * @@ -78,14 +78,14 @@ ReadCDWRetr: .hdreadcache: ; cmp dword [esi+4],0 ; empty ; je .nohdcache - cmp [esi],eax ; correct sector - je .yeshdcache + cmp [esi],eax ; correct sector + je .yeshdcache .nohdcache: add esi,8 inc edi dec ecx jnz .hdreadcache - call find_empty_slot_CD_cache ; ret in edi + call find_empty_slot_CD_cache ; ret in edi push edi push eax @@ -103,7 +103,7 @@ ReadCDWRetr: mov [CDDataBuf_pointer],ebx call cd_calculate_cache_1 lea esi,[edi*8+esi] - mov [esi],eax ; sector number + mov [esi],eax ; sector number ; mov dword [esi+4],1 ; hd read - mark as same as in hd .yeshdcache: mov esi,edi @@ -115,35 +115,35 @@ ReadCDWRetr: mov edi,ebx ;[CDDataBuf_pointer] mov ecx,512 ;/4 cld - rep movsd ; move data + rep movsd ; move data .exit: popad ret ReadCDWRetr_1: - pushad + pushad ; Цикл, пока команда не выполнена успешно или не ; исчерпано количество попыток - mov ECX,MaxRetr + mov ECX,MaxRetr @@NextRetr: ; Подать команду - call ReadCD - cmp [DevErrorCode],0 - je @@End_4 + call ReadCD + cmp [DevErrorCode],0 + je @@End_4 - or ecx,ecx ;{SPraid.simba} (for cd load) - jz @@End_4 - dec ecx + or ecx,ecx ;{SPraid.simba} (for cd load) + jz @@End_4 + dec ecx - cmp [timer_ticks_enable],0 - jne @f - mov eax,NoTickWaitTime + cmp [timer_ticks_enable],0 + jne @f + mov eax,NoTickWaitTime .wait: - dec eax - cmp eax,0 - je @@NextRetr - jmp .wait + dec eax + cmp eax,0 + je @@NextRetr + jmp .wait @@: ; Задержка на 2,5 секунды ; mov EAX,[timer_ticks] @@ -152,10 +152,10 @@ ReadCDWRetr_1: ; call change_task ; cmp EAX,[timer_ticks] ; ja @@Wait - loop @@NextRetr + loop @@NextRetr @@End_4: - popad - ret + popad + ret ; Универсальные процедуры, обеспечивающие выполнение @@ -166,11 +166,11 @@ ReadCDWRetr_1: MaxCDWaitTime equ 1000 ;200 ;10 секунд ; Область памяти для формирования пакетной команды -PacketCommand: rb 12 ;DB 12 DUP (?) +PacketCommand: rb 12 ;DB 12 DUP (?) ; Область памяти для приема данных от дисковода ;CDDataBuf DB 4096 DUP (0) ; Размер принимаемого блока данных в байтах -CDBlockSize DW ? +CDBlockSize DW ? ; Адрес считываемого сектора данных CDSectorAddress: DD ? ; Время начала очередной операции с диском @@ -192,123 +192,123 @@ CDDataBuf_pointer dd 0 ;* CDBlockSize - размер принимаемого блока данных. * ;**************************************************** SendPacketDatCommand: - pushad - mov [DevErrorCode],0 + pushad + mov [DevErrorCode],0 ; Задать режим CHS - mov [ATAAddressMode],0 + mov [ATAAddressMode],0 ; Послать ATA-команду передачи пакетной команды - mov [ATAFeatures],0 - mov [ATASectorCount],0 - mov [ATASectorNumber],0 - ; Загрузить размер передаваемого блока - mov AX,[CDBlockSize] - mov [ATACylinder],AX - mov [ATAHead],0 - mov [ATACommand],0A0h - call SendCommandToHDD_1 - cmp [DevErrorCode],0 ;проверить код ошибки - jne @@End_8 ;закончить, сохранив код ошибки + mov [ATAFeatures],0 + mov [ATASectorCount],0 + mov [ATASectorNumber],0 + ; Загрузить размер передаваемого блока + mov AX,[CDBlockSize] + mov [ATACylinder],AX + mov [ATAHead],0 + mov [ATACommand],0A0h + call SendCommandToHDD_1 + cmp [DevErrorCode],0 ;проверить код ошибки + jne @@End_8 ;закончить, сохранив код ошибки ; Ожидание готовности дисковода к приему ; пакетной команды - mov DX,[ATABasePortAddr] - add DX,7 ;порт 1х7h - mov ecx,NoTickWaitTime + mov DX,[ATABasePortAddr] + add DX,7 ;порт 1х7h + mov ecx,NoTickWaitTime @@WaitDevice0: - cmp [timer_ticks_enable],0 - jne @f - dec ecx - cmp ecx,0 - je @@Err1_1 - jmp .test + cmp [timer_ticks_enable],0 + jne @f + dec ecx + cmp ecx,0 + je @@Err1_1 + jmp .test @@: - call change_task - ; Проверить время выполнения команды - mov EAX,[timer_ticks] - sub EAX,[TickCounter_1] - cmp EAX,BSYWaitTime - ja @@Err1_1 ;ошибка тайм-аута - ; Проверить готовность + call change_task + ; Проверить время выполнения команды + mov EAX,[timer_ticks] + sub EAX,[TickCounter_1] + cmp EAX,BSYWaitTime + ja @@Err1_1 ;ошибка тайм-аута + ; Проверить готовность .test: - in AL,DX - test AL,80h ;состояние сигнала BSY - jnz @@WaitDevice0 - test AL,08h ;состояние сигнала DRQ - jz @@WaitDevice0 - test AL,1 ;состояние сигнала ERR - jnz @@Err6 + in AL,DX + test AL,80h ;состояние сигнала BSY + jnz @@WaitDevice0 + test AL,08h ;состояние сигнала DRQ + jz @@WaitDevice0 + test AL,1 ;состояние сигнала ERR + jnz @@Err6 ; Послать пакетную команду - cli - mov DX,[ATABasePortAddr] - mov AX,[PacketCommand] - out DX,AX - mov AX,[PacketCommand+2] - out DX,AX - mov AX,[PacketCommand+4] - out DX,AX - mov AX,[PacketCommand+6] - out DX,AX - mov AX,[PacketCommand+8] - out DX,AX - mov AX,[PacketCommand+10] - out DX,AX - sti + cli + mov DX,[ATABasePortAddr] + mov AX,[PacketCommand] + out DX,AX + mov AX,[PacketCommand+2] + out DX,AX + mov AX,[PacketCommand+4] + out DX,AX + mov AX,[PacketCommand+6] + out DX,AX + mov AX,[PacketCommand+8] + out DX,AX + mov AX,[PacketCommand+10] + out DX,AX + sti ; Ожидание готовности данных - mov DX,[ATABasePortAddr] - add DX,7 ;порт 1х7h - mov ecx,NoTickWaitTime + mov DX,[ATABasePortAddr] + add DX,7 ;порт 1х7h + mov ecx,NoTickWaitTime @@WaitDevice1: - cmp [timer_ticks_enable],0 - jne @f - dec ecx - cmp ecx,0 - je @@Err1_1 - jmp .test_1 + cmp [timer_ticks_enable],0 + jne @f + dec ecx + cmp ecx,0 + je @@Err1_1 + jmp .test_1 @@: - call change_task - ; Проверить время выполнения команды - mov EAX,[timer_ticks] - sub EAX,[TickCounter_1] - cmp EAX,MaxCDWaitTime - ja @@Err1_1 ;ошибка тайм-аута - ; Проверить готовность + call change_task + ; Проверить время выполнения команды + mov EAX,[timer_ticks] + sub EAX,[TickCounter_1] + cmp EAX,MaxCDWaitTime + ja @@Err1_1 ;ошибка тайм-аута + ; Проверить готовность .test_1: - in AL,DX - test AL,80h ;состояние сигнала BSY - jnz @@WaitDevice1 - test AL,08h ;состояние сигнала DRQ - jz @@WaitDevice1 - test AL,1 ;состояние сигнала ERR - jnz @@Err6_temp + in AL,DX + test AL,80h ;состояние сигнала BSY + jnz @@WaitDevice1 + test AL,08h ;состояние сигнала DRQ + jz @@WaitDevice1 + test AL,1 ;состояние сигнала ERR + jnz @@Err6_temp ; Принять блок данных от контроллера - mov EDI,[CDDataBuf_pointer] ;0x7000 ;CDDataBuf - ; Загрузить адрес регистра данных контроллера - mov DX,[ATABasePortAddr] ;порт 1x0h - ; Загрузить в счетчик размер блока в байтах - xor ecx,ecx - mov CX,[CDBlockSize] - ; Вычислить размер блока в 16-разрядных словах - shr CX,1 ;разделить размер блока на 2 - ; Принять блок данных - cli - cld - rep insw - sti - ; Успешное завершение приема данных - jmp @@End_8 + mov EDI,[CDDataBuf_pointer] ;0x7000 ;CDDataBuf + ; Загрузить адрес регистра данных контроллера + mov DX,[ATABasePortAddr] ;порт 1x0h + ; Загрузить в счетчик размер блока в байтах + xor ecx,ecx + mov CX,[CDBlockSize] + ; Вычислить размер блока в 16-разрядных словах + shr CX,1 ;разделить размер блока на 2 + ; Принять блок данных + cli + cld + rep insw + sti + ; Успешное завершение приема данных + jmp @@End_8 ; Записать код ошибки @@Err1_1: - mov [DevErrorCode],1 - jmp @@End_8 + mov [DevErrorCode],1 + jmp @@End_8 @@Err6_temp: - mov [DevErrorCode],7 - jmp @@End_8 + mov [DevErrorCode],7 + jmp @@End_8 @@Err6: - mov [DevErrorCode],6 + mov [DevErrorCode],6 @@End_8: - popad - ret + popad + ret @@ -322,86 +322,86 @@ SendPacketDatCommand: ;* PacketCommand - 12-байтный командный пакет. * ;*********************************************** SendPacketNoDatCommand: - pushad + pushad mov [DevErrorCode],0 ; Задать режим CHS - mov [ATAAddressMode],0 + mov [ATAAddressMode],0 ; Послать ATA-команду передачи пакетной команды - mov [ATAFeatures],0 - mov [ATASectorCount],0 - mov [ATASectorNumber],0 - mov [ATACylinder],0 - mov [ATAHead],0 - mov [ATACommand],0A0h - call SendCommandToHDD_1 - cmp [DevErrorCode],0 ;проверить код ошибки - jne @@End_9 ;закончить, сохранив код ошибки + mov [ATAFeatures],0 + mov [ATASectorCount],0 + mov [ATASectorNumber],0 + mov [ATACylinder],0 + mov [ATAHead],0 + mov [ATACommand],0A0h + call SendCommandToHDD_1 + cmp [DevErrorCode],0 ;проверить код ошибки + jne @@End_9 ;закончить, сохранив код ошибки ; Ожидание готовности дисковода к приему ; пакетной команды - mov DX,[ATABasePortAddr] - add DX,7 ;порт 1х7h + mov DX,[ATABasePortAddr] + add DX,7 ;порт 1х7h @@WaitDevice0_1: - call change_task - ; Проверить время ожидания - mov EAX,[timer_ticks] - sub EAX,[TickCounter_1] - cmp EAX,BSYWaitTime - ja @@Err1_3 ;ошибка тайм-аута - ; Проверить готовность - in AL,DX - test AL,80h ;состояние сигнала BSY - jnz @@WaitDevice0_1 - test AL,1 ;состояние сигнала ERR - jnz @@Err6_1 - test AL,08h ;состояние сигнала DRQ - jz @@WaitDevice0_1 + call change_task + ; Проверить время ожидания + mov EAX,[timer_ticks] + sub EAX,[TickCounter_1] + cmp EAX,BSYWaitTime + ja @@Err1_3 ;ошибка тайм-аута + ; Проверить готовность + in AL,DX + test AL,80h ;состояние сигнала BSY + jnz @@WaitDevice0_1 + test AL,1 ;состояние сигнала ERR + jnz @@Err6_1 + test AL,08h ;состояние сигнала DRQ + jz @@WaitDevice0_1 ; Послать пакетную команду ; cli - mov DX,[ATABasePortAddr] - mov AX,word [PacketCommand] - out DX,AX - mov AX,word [PacketCommand+2] - out DX,AX - mov AX,word [PacketCommand+4] - out DX,AX - mov AX,word [PacketCommand+6] - out DX,AX - mov AX,word [PacketCommand+8] - out DX,AX - mov AX,word [PacketCommand+10] - out DX,AX + mov DX,[ATABasePortAddr] + mov AX,word [PacketCommand] + out DX,AX + mov AX,word [PacketCommand+2] + out DX,AX + mov AX,word [PacketCommand+4] + out DX,AX + mov AX,word [PacketCommand+6] + out DX,AX + mov AX,word [PacketCommand+8] + out DX,AX + mov AX,word [PacketCommand+10] + out DX,AX ; sti cmp [ignore_CD_eject_wait],1 - je @@End_9 + je @@End_9 ; Ожидание подтверждения приема команды - mov DX,[ATABasePortAddr] - add DX,7 ;порт 1х7h + mov DX,[ATABasePortAddr] + add DX,7 ;порт 1х7h @@WaitDevice1_1: - call change_task - ; Проверить время выполнения команды - mov EAX,[timer_ticks] - sub EAX,[TickCounter_1] - cmp EAX,MaxCDWaitTime - ja @@Err1_3 ;ошибка тайм-аута - ; Ожидать освобождения устройства - in AL,DX - test AL,80h ;состояние сигнала BSY - jnz @@WaitDevice1_1 - test AL,1 ;состояние сигнала ERR - jnz @@Err6_1 - test AL,40h ;состояние сигнала DRDY - jz @@WaitDevice1_1 - jmp @@End_9 + call change_task + ; Проверить время выполнения команды + mov EAX,[timer_ticks] + sub EAX,[TickCounter_1] + cmp EAX,MaxCDWaitTime + ja @@Err1_3 ;ошибка тайм-аута + ; Ожидать освобождения устройства + in AL,DX + test AL,80h ;состояние сигнала BSY + jnz @@WaitDevice1_1 + test AL,1 ;состояние сигнала ERR + jnz @@Err6_1 + test AL,40h ;состояние сигнала DRDY + jz @@WaitDevice1_1 + jmp @@End_9 ; Записать код ошибки @@Err1_3: - mov [DevErrorCode],1 - jmp @@End_9 + mov [DevErrorCode],1 + jmp @@End_9 @@Err6_1: - mov [DevErrorCode],6 + mov [DevErrorCode],6 @@End_9: - popad - ret + popad + ret ;**************************************************** ;* ПОСЛАТЬ КОМАНДУ ЗАДАННОМУ ДИСКУ * @@ -423,119 +423,119 @@ SendPacketNoDatCommand: ;* возвращен код ошибки. * ;**************************************************** SendCommandToHDD_1: - pushad + pushad mov [DevErrorCode],0 ; Проверить значение кода режима - cmp [ATAAddressMode],1 - ja @@Err2_4 + cmp [ATAAddressMode],1 + ja @@Err2_4 ; Проверить корректность номера канала - mov BX,[ChannelNumber] - cmp BX,1 - jb @@Err3_4 - cmp BX,2 - ja @@Err3_4 + mov BX,[ChannelNumber] + cmp BX,1 + jb @@Err3_4 + cmp BX,2 + ja @@Err3_4 ; Установить базовый адрес - dec BX - shl BX,1 - movzx ebx,bx - mov AX,[ebx+StandardATABases] - mov [ATABasePortAddr],AX + dec BX + shl BX,1 + movzx ebx,bx + mov AX,[ebx+StandardATABases] + mov [ATABasePortAddr],AX ; Ожидание готовности HDD к приему команды - ; Выбрать нужный диск - mov DX,[ATABasePortAddr] - add DX,6 ;адрес регистра головок - mov AL,[DiskNumber] - cmp AL,1 ;проверить номера диска - ja @@Err4_4 - shl AL,4 - or AL,10100000b - out DX,AL - ; Ожидать, пока диск не будет готов - inc DX - mov eax,[timer_ticks] - mov [TickCounter_1],eax - mov ecx,NoTickWaitTime + ; Выбрать нужный диск + mov DX,[ATABasePortAddr] + add DX,6 ;адрес регистра головок + mov AL,[DiskNumber] + cmp AL,1 ;проверить номера диска + ja @@Err4_4 + shl AL,4 + or AL,10100000b + out DX,AL + ; Ожидать, пока диск не будет готов + inc DX + mov eax,[timer_ticks] + mov [TickCounter_1],eax + mov ecx,NoTickWaitTime @@WaitHDReady_2: - cmp [timer_ticks_enable],0 - jne @f - dec ecx - cmp ecx,0 - je @@Err1_4 - jmp .test + cmp [timer_ticks_enable],0 + jne @f + dec ecx + cmp ecx,0 + je @@Err1_4 + jmp .test @@: - call change_task - ; Проверить время ожидания - mov eax,[timer_ticks] - sub eax,[TickCounter_1] - cmp eax,BSYWaitTime ;300 ;ожидать 3 сек. - ja @@Err1_4 ;ошибка тайм-аута - ; Прочитать регистр состояния + call change_task + ; Проверить время ожидания + mov eax,[timer_ticks] + sub eax,[TickCounter_1] + cmp eax,BSYWaitTime ;300 ;ожидать 3 сек. + ja @@Err1_4 ;ошибка тайм-аута + ; Прочитать регистр состояния .test: - in AL,DX - ; Проверить состояние сигнала BSY - test AL,80h - jnz @@WaitHDReady_2 - ; Проверить состояние сигнала DRQ - test AL,08h - jnz @@WaitHDReady_2 + in AL,DX + ; Проверить состояние сигнала BSY + test AL,80h + jnz @@WaitHDReady_2 + ; Проверить состояние сигнала DRQ + test AL,08h + jnz @@WaitHDReady_2 ; Загрузить команду в регистры контроллера - cli - mov DX,[ATABasePortAddr] - inc DX ;регистр "особенностей" - mov AL,[ATAFeatures] - out DX,AL - inc DX ;счетчик секторов - mov AL,[ATASectorCount] - out DX,AL - inc DX ;регистр номера сектора - mov AL,[ATASectorNumber] - out DX,AL - inc DX ;номер цилиндра (младший байт) - mov AX,[ATACylinder] - out DX,AL - inc DX ;номер цилиндра (старший байт) - mov AL,AH - out DX,AL - inc DX ;номер головки/номер диска - mov AL,[DiskNumber] - shl AL,4 - cmp [ATAHead],0Fh ;проверить номер головки - ja @@Err5_4 - or AL,[ATAHead] - or AL,10100000b - mov AH,[ATAAddressMode] - shl AH,6 - or AL,AH - out DX,AL + cli + mov DX,[ATABasePortAddr] + inc DX ;регистр "особенностей" + mov AL,[ATAFeatures] + out DX,AL + inc DX ;счетчик секторов + mov AL,[ATASectorCount] + out DX,AL + inc DX ;регистр номера сектора + mov AL,[ATASectorNumber] + out DX,AL + inc DX ;номер цилиндра (младший байт) + mov AX,[ATACylinder] + out DX,AL + inc DX ;номер цилиндра (старший байт) + mov AL,AH + out DX,AL + inc DX ;номер головки/номер диска + mov AL,[DiskNumber] + shl AL,4 + cmp [ATAHead],0Fh ;проверить номер головки + ja @@Err5_4 + or AL,[ATAHead] + or AL,10100000b + mov AH,[ATAAddressMode] + shl AH,6 + or AL,AH + out DX,AL ; Послать команду - mov AL,[ATACommand] - inc DX ;регистр команд - out DX,AL - sti + mov AL,[ATACommand] + inc DX ;регистр команд + out DX,AL + sti ; Сбросить признак ошибки - mov [DevErrorCode],0 - jmp @@End_10 + mov [DevErrorCode],0 + jmp @@End_10 ; Записать код ошибки @@Err1_4: - mov [DevErrorCode],1 - jmp @@End_10 + mov [DevErrorCode],1 + jmp @@End_10 @@Err2_4: - mov [DevErrorCode],2 - jmp @@End_10 + mov [DevErrorCode],2 + jmp @@End_10 @@Err3_4: - mov [DevErrorCode],3 - jmp @@End_10 + mov [DevErrorCode],3 + jmp @@End_10 @@Err4_4: - mov [DevErrorCode],4 - jmp @@End_10 + mov [DevErrorCode],4 + jmp @@End_10 @@Err5_4: - mov [DevErrorCode],5 + mov [DevErrorCode],5 ; Завершение работы программы @@End_10: ; sti - popad - ret + popad + ret ;************************************************* ;* ОЖИДАНИЕ ГОТОВНОСТИ УСТРОЙСТВА К РАБОТЕ * @@ -545,43 +545,43 @@ SendCommandToHDD_1: ;* DiskNumber - номер диска на канале. * ;************************************************* WaitUnitReady: - pusha + pusha ; Запомнить время начала операции - mov EAX,[timer_ticks] - mov [WURStartTime],EAX + mov EAX,[timer_ticks] + mov [WURStartTime],EAX ; Очистить буфер пакетной команды - call clear_packet_buffer + call clear_packet_buffer ; Сформировать команду TEST UNIT READY - mov [PacketCommand],word 00h + mov [PacketCommand],word 00h ; ЦИКЛ ОЖИДАНИЯ ГОТОВНОСТИ УСТРОЙСТВА - mov ecx,NoTickWaitTime + mov ecx,NoTickWaitTime @@SendCommand: - ; Подать команду проверки готовности - call SendPacketNoDatCommand - cmp [timer_ticks_enable],0 - jne @f - cmp [DevErrorCode],0 - je @@End_11 - dec ecx - cmp ecx,0 - je .Error - jmp @@SendCommand + ; Подать команду проверки готовности + call SendPacketNoDatCommand + cmp [timer_ticks_enable],0 + jne @f + cmp [DevErrorCode],0 + je @@End_11 + dec ecx + cmp ecx,0 + je .Error + jmp @@SendCommand @@: - call change_task - ; Проверить код ошибки - cmp [DevErrorCode],0 - je @@End_11 - ; Проверить время ожидания готовности - mov EAX,[timer_ticks] - sub EAX,[WURStartTime] - cmp EAX,MaxCDWaitTime - jb @@SendCommand + call change_task + ; Проверить код ошибки + cmp [DevErrorCode],0 + je @@End_11 + ; Проверить время ожидания готовности + mov EAX,[timer_ticks] + sub EAX,[WURStartTime] + cmp EAX,MaxCDWaitTime + jb @@SendCommand .Error: - ; Ошибка тайм-аута - mov [DevErrorCode],1 + ; Ошибка тайм-аута + mov [DevErrorCode],1 @@End_11: - popa - ret + popa + ret ;************************************************* ;* ЗАПРЕТИТЬ СМЕНУ ДИСКА * @@ -591,21 +591,21 @@ WaitUnitReady: ;* DiskNumber - номер диска на канале. * ;************************************************* prevent_medium_removal: - pusha + pusha ; Очистить буфер пакетной команды - call clear_packet_buffer + call clear_packet_buffer ; Задать код команды - mov [PacketCommand],byte 0x1E + mov [PacketCommand],byte 0x1E ; Задать код запрета mov [PacketCommand+4],byte 11b ; Подать команду - call SendPacketNoDatCommand - mov eax,ATAPI_IDE0_lock - add eax,[cdpos] - dec eax - mov [eax],byte 1 - popa - ret + call SendPacketNoDatCommand + mov eax,ATAPI_IDE0_lock + add eax,[cdpos] + dec eax + mov [eax],byte 1 + popa + ret ;************************************************* ;* РАЗРЕШИТЬ СМЕНУ ДИСКА * @@ -615,21 +615,21 @@ prevent_medium_removal: ;* DiskNumber - номер диска на канале. * ;************************************************* allow_medium_removal: - pusha + pusha ; Очистить буфер пакетной команды - call clear_packet_buffer + call clear_packet_buffer ; Задать код команды - mov [PacketCommand],byte 0x1E + mov [PacketCommand],byte 0x1E ; Задать код запрета mov [PacketCommand+4],byte 00b ; Подать команду - call SendPacketNoDatCommand - mov eax,ATAPI_IDE0_lock - add eax,[cdpos] - dec eax - mov [eax],byte 0 - popa - ret + call SendPacketNoDatCommand + mov eax,ATAPI_IDE0_lock + add eax,[cdpos] + dec eax + mov [eax],byte 0 + popa + ret ;************************************************* ;* ЗАГРУЗИТЬ НОСИТЕЛЬ В ДИСКОВОД * @@ -639,18 +639,18 @@ allow_medium_removal: ;* DiskNumber - номер диска на канале. * ;************************************************* LoadMedium: - pusha + pusha ; Очистить буфер пакетной команды - call clear_packet_buffer + call clear_packet_buffer ; Сформировать команду START/STOP UNIT - ; Задать код команды - mov [PacketCommand],word 1Bh - ; Задать операцию загрузки носителя - mov [PacketCommand+4],word 00000011b + ; Задать код команды + mov [PacketCommand],word 1Bh + ; Задать операцию загрузки носителя + mov [PacketCommand+4],word 00000011b ; Подать команду - call SendPacketNoDatCommand - popa - ret + call SendPacketNoDatCommand + popa + ret ;************************************************* ;* ИЗВЛЕЧЬ НОСИТЕЛЬ ИЗ ДИСКОВОДА * @@ -660,18 +660,18 @@ LoadMedium: ;* DiskNumber - номер диска на канале. * ;************************************************* EjectMedium: - pusha + pusha ; Очистить буфер пакетной команды - call clear_packet_buffer + call clear_packet_buffer ; Сформировать команду START/STOP UNIT - ; Задать код команды - mov [PacketCommand],word 1Bh - ; Задать операцию извлечения носителя - mov [PacketCommand+4],word 00000010b + ; Задать код команды + mov [PacketCommand],word 1Bh + ; Задать операцию извлечения носителя + mov [PacketCommand+4],word 00000010b ; Подать команду - call SendPacketNoDatCommand - popa - ret + call SendPacketNoDatCommand + popa + ret ;************************************************* ;* Проверить событие нажатия кнопки извлечения * @@ -681,39 +681,40 @@ EjectMedium: ;* ChannelNumber - номер канала; * ;* DiskNumber - номер диска на канале. * ;************************************************* +align 4 check_ATAPI_device_event: - pusha + pusha mov eax,[timer_ticks] sub eax,[timer_ATAPI_check] cmp eax,100 - jb .end_1 + jb .end_1 mov al,[DRIVE_DATA+1] and al,11b cmp al,10b - jz .ide3 + jz .ide3 .ide2_1: mov al,[DRIVE_DATA+1] and al,1100b cmp al,1000b - jz .ide2 + jz .ide2 .ide1_1: mov al,[DRIVE_DATA+1] and al,110000b cmp al,100000b - jz .ide1 + jz .ide1 .ide0_1: mov al,[DRIVE_DATA+1] and al,11000000b cmp al,10000000b - jz .ide0 + jz .ide0 .end: sti mov eax,[timer_ticks] mov [timer_ATAPI_check],eax .end_1: - popa - ret + popa + ret .ide3: cli @@ -723,19 +724,19 @@ check_ATAPI_device_event: jne .ide1_1 cmp [cd_status],0 jne .end - mov [IDE_Channel_2],1 + mov [IDE_Channel_2],1 call reserve_ok2 - mov [ChannelNumber],2 - mov [DiskNumber],1 - mov [cdpos],4 - call GetEvent_StatusNotification - cmp [CDDataBuf+4],byte 1 - je .eject_ide3 - call syscall_cdaudio.free + mov [ChannelNumber],2 + mov [DiskNumber],1 + mov [cdpos],4 + call GetEvent_StatusNotification + cmp [CDDataBuf+4],byte 1 + je .eject_ide3 + call syscall_cdaudio.free jmp .ide2_1 .eject_ide3: call .eject - call syscall_cdaudio.free + call syscall_cdaudio.free jmp .ide2_1 .ide2: @@ -746,19 +747,19 @@ check_ATAPI_device_event: jne .ide1_1 cmp [cd_status],0 jne .end - mov [IDE_Channel_2],1 + mov [IDE_Channel_2],1 call reserve_ok2 - mov [ChannelNumber],2 - mov [DiskNumber],0 - mov [cdpos],3 - call GetEvent_StatusNotification - cmp [CDDataBuf+4],byte 1 - je .eject_ide2 - call syscall_cdaudio.free + mov [ChannelNumber],2 + mov [DiskNumber],0 + mov [cdpos],3 + call GetEvent_StatusNotification + cmp [CDDataBuf+4],byte 1 + je .eject_ide2 + call syscall_cdaudio.free jmp .ide1_1 .eject_ide2: call .eject - call syscall_cdaudio.free + call syscall_cdaudio.free jmp .ide1_1 .ide1: @@ -769,19 +770,19 @@ check_ATAPI_device_event: jne .end cmp [cd_status],0 jne .end - mov [IDE_Channel_1],1 + mov [IDE_Channel_1],1 call reserve_ok2 - mov [ChannelNumber],1 - mov [DiskNumber],1 - mov [cdpos],2 - call GetEvent_StatusNotification - cmp [CDDataBuf+4],byte 1 - je .eject_ide1 - call syscall_cdaudio.free + mov [ChannelNumber],1 + mov [DiskNumber],1 + mov [cdpos],2 + call GetEvent_StatusNotification + cmp [CDDataBuf+4],byte 1 + je .eject_ide1 + call syscall_cdaudio.free jmp .ide0_1 .eject_ide1: call .eject - call syscall_cdaudio.free + call syscall_cdaudio.free jmp .ide0_1 .ide0: @@ -792,28 +793,28 @@ check_ATAPI_device_event: jne .end cmp [cd_status],0 jne .end - mov [IDE_Channel_1],1 + mov [IDE_Channel_1],1 call reserve_ok2 - mov [ChannelNumber],1 - mov [DiskNumber],0 - mov [cdpos],1 - call GetEvent_StatusNotification - cmp [CDDataBuf+4],byte 1 - je .eject_ide0 - call syscall_cdaudio.free + mov [ChannelNumber],1 + mov [DiskNumber],0 + mov [cdpos],1 + call GetEvent_StatusNotification + cmp [CDDataBuf+4],byte 1 + je .eject_ide0 + call syscall_cdaudio.free jmp .end .eject_ide0: call .eject - call syscall_cdaudio.free + call syscall_cdaudio.free jmp .end .eject: - call clear_CD_cache - call allow_medium_removal - mov [ignore_CD_eject_wait],1 - call EjectMedium - mov [ignore_CD_eject_wait],0 - ret + call clear_CD_cache + call allow_medium_removal + mov [ignore_CD_eject_wait],1 + call EjectMedium + mov [ignore_CD_eject_wait],0 + ret timer_ATAPI_check dd 0 ATAPI_IDE0_lock db 0 @@ -831,22 +832,22 @@ ignore_CD_eject_wait db 0 ;* DiskNumber - номер диска на канале. * ;************************************************* GetEvent_StatusNotification: - pusha - mov [CDDataBuf_pointer],CDDataBuf + pusha + mov [CDDataBuf_pointer],CDDataBuf ; Очистить буфер пакетной команды - call clear_packet_buffer + call clear_packet_buffer ; Задать код команды - mov [PacketCommand],byte 4Ah - mov [PacketCommand+1],byte 00000001b + mov [PacketCommand],byte 4Ah + mov [PacketCommand+1],byte 00000001b ; Задать запрос класса сообщений - mov [PacketCommand+4],byte 00010000b + mov [PacketCommand+4],byte 00010000b ; Размер выделенной области - mov [PacketCommand+7],byte 8h - mov [PacketCommand+8],byte 0h + mov [PacketCommand+7],byte 8h + mov [PacketCommand+8],byte 0h ; Подать команду - call SendPacketDatCommand - popa - ret + call SendPacketDatCommand + popa + ret ;************************************************* ; прочитать информацию из TOC @@ -856,22 +857,22 @@ GetEvent_StatusNotification: ;* DiskNumber - номер диска на канале. * ;************************************************* Read_TOC: - pusha - mov [CDDataBuf_pointer],CDDataBuf + pusha + mov [CDDataBuf_pointer],CDDataBuf ; Очистить буфер пакетной команды - call clear_packet_buffer + call clear_packet_buffer ; Сформировать пакетную команду для считывания ; сектора данных - mov [PacketCommand],byte 0x43 - ; Задать формат - mov [PacketCommand+2],byte 1 + mov [PacketCommand],byte 0x43 + ; Задать формат + mov [PacketCommand+2],byte 1 ; Размер выделенной области - mov [PacketCommand+7],byte 0xFF - mov [PacketCommand+8],byte 0h + mov [PacketCommand+7],byte 0xFF + mov [PacketCommand+8],byte 0h ; Подать команду - call SendPacketDatCommand - popa - ret + call SendPacketDatCommand + popa + ret ;************************************************* ;* ОПРЕДЕЛИТЬ ОБЩЕЕ КОЛИЧЕСТВО СЕКТОРОВ НА ДИСКЕ * @@ -895,7 +896,7 @@ Read_TOC: clear_packet_buffer: ; Очистить буфер пакетной команды - mov [PacketCommand],dword 0 - mov [PacketCommand+4],dword 0 - mov [PacketCommand+8],dword 0 - ret + mov [PacketCommand],dword 0 + mov [PacketCommand+4],dword 0 + mov [PacketCommand+8],dword 0 + ret diff --git a/kernel/branches/net/blkdev/flp_drv.inc b/kernel/branches/net/blkdev/flp_drv.inc index 3e9cdc41cf..2253f30fc7 100644 --- a/kernel/branches/net/blkdev/flp_drv.inc +++ b/kernel/branches/net/blkdev/flp_drv.inc @@ -282,6 +282,7 @@ save_timer_fdd_motor: ;***************************************** ;* ПРОВЕРКА ЗАДЕРЖКИ ВЫКЛЮЧЕНИЯ МОТОРА * ;***************************************** +align 4 check_fdd_motor_status: cmp [fdd_motor_status],0 je end_check_fdd_motor_status_1 diff --git a/kernel/branches/net/boot/bootcode.inc b/kernel/branches/net/boot/bootcode.inc index f20a38491e..c1299165cc 100644 --- a/kernel/branches/net/boot/bootcode.inc +++ b/kernel/branches/net/boot/bootcode.inc @@ -815,9 +815,12 @@ end if dec al mov [boot_dev], al +; GET MEMORY MAP +include 'detect/biosmem.inc' + ; READ DISKETTE TO MEMORY -; cmp [boot_dev],0 + cmp [boot_dev],0 jne no_sys_on_floppy mov si,diskload call print diff --git a/kernel/branches/net/boot/booteng.inc b/kernel/branches/net/boot/booteng.inc index f800008d30..618709f655 100644 --- a/kernel/branches/net/boot/booteng.inc +++ b/kernel/branches/net/boot/booteng.inc @@ -104,7 +104,7 @@ _rs db 186,' _bt db 186,' АДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДБДЩ',13,10,0 remark1 db "Default values were selected to match most of configurations, but not all.",0 -remark2 db "If you have LCD-monitor, disable VRR in the item [c] - you do not need it.",0 +remark2 db "If you have CRT-monitor, enable VRR in the item [c].",0 remark3 db "If the system does not boot, try to disable the item [b].",0 remarks dw remark1, remark2, remark3 num_remarks = 3 diff --git a/kernel/branches/net/boot/bootet.inc b/kernel/branches/net/boot/bootet.inc index d4f4a14037..95f62ea845 100644 --- a/kernel/branches/net/boot/bootet.inc +++ b/kernel/branches/net/boot/bootet.inc @@ -109,7 +109,7 @@ save_quest db "J loader_block_error db "Alglaaduri andmed vigased, ei saa jдtkata. Peatatud.",0 remark1 db "Default values were selected to match most of configurations, but not all.",0 -remark2 db "If you have LCD-monitor, disable VRR in the item [c] - you do not need it.",0 +remark2 db "If you have CRT-monitor, enable VRR in the item [c].",0 remark3 db "If the system does not boot, try to disable the item [b].",0 remarks dw remark1, remark2, remark3 num_remarks = 3 diff --git a/kernel/branches/net/boot/bootge.inc b/kernel/branches/net/boot/bootge.inc index 68449203ff..7c852f8a7d 100644 --- a/kernel/branches/net/boot/bootge.inc +++ b/kernel/branches/net/boot/bootge.inc @@ -114,7 +114,7 @@ save_quest db "Aktuelle Einstellungen speichern? [y/n]: ",0 loader_block_error db "Bootloader Daten ungueltig, Kann nicht fortfahren. Angehalten.",0 remark1 db "Default values were selected to match most of configurations, but not all.",0 -remark2 db "If you have LCD-monitor, disable VRR in the item [c] - you do not need it.",0 +remark2 db "If you have CRT-monitor, enable VRR in the item [c].",0 remark3 db "If the system does not boot, try to disable the item [b].",0 remarks dw remark1, remark2, remark3 num_remarks = 3 diff --git a/kernel/branches/net/boot/bootru.inc b/kernel/branches/net/boot/bootru.inc index c9ed6e72e7..8f0253aab6 100644 --- a/kernel/branches/net/boot/bootru.inc +++ b/kernel/branches/net/boot/bootru.inc @@ -85,7 +85,7 @@ _bt db 186,' remark1 db "‡­ зҐ­Ёп Ї® 㬮«з ­Ёо ўлЎа ­л ¤«п 㤮Ўбвў  Ў®«миЁ­бвў , ­® ­Ґ ўбҐе.",0 -remark2 db "…б«Ё г ‚ б LCD-¬®­Ёв®а, ®вЄ«озЁвҐ VRR ў Їг­ЄвҐ [c] - ®­ ‚ ¬ ­Ґ ­г¦Ґ­.",0 +remark2 db "…б«Ё г ‚ б ќ‹’-¬®­Ёв®а, ўЄ«озЁвҐ VRR ў Їг­ЄвҐ [c].",0 remark3 db "…б«Ё г ‚ б ­Ґ Јаг§Ёвбп бЁб⥬ , Ї®Їа®Ўг©вҐ ®вЄ«озЁвм Їг­Єв [b].",0 remarks dw remark1, remark2, remark3 num_remarks = 3 diff --git a/kernel/branches/net/build.bat b/kernel/branches/net/build.bat index becb36ebb1..e322d1e191 100644 --- a/kernel/branches/net/build.bat +++ b/kernel/branches/net/build.bat @@ -1,5 +1,5 @@ @echo off - +cls set languages=en ru ge et set drivers=sound sis infinity ensoniq ps2mouse com_mouse uart ati2d vmode set targets=all kernel drivers skins clean @@ -74,6 +74,33 @@ goto :eof ) cd .. move bin\drivers\vmode.obj bin\drivers\vmode.mdr + + +kpack >nul 2>&1 + +if %errorlevel%==9009 goto :Error_KpackFailed + +echo * +echo ############################################## +echo * +echo Kpack KolibriOS drivers? +echo * + +set /P res=[y/n]? + +if "%res%"=="y" ( + + echo * + echo Compressing system + + echo * + for %%a in (bin\drivers\*.obj) do ( + echo ================== kpack %%a + kpack %%a + if not %errorlevel%==0 goto :Error_KpackFailed + ) + +) goto :eof @@ -95,11 +122,21 @@ goto :Exit_OK :Error_FasmFailed echo error: fasm execution failed -erase lang.inc +erase lang.inc >nul 2>&1 +echo. +pause +exit 1 + +:Error_KpackFailed +echo *** NOTICE *** +echo If you want to pack all applications you may +echo place "kpack" in accessible directory or system %PATH%. +echo You can get this tool from KolibriOS distribution kit. pause exit 1 :Exit_OK -echo all operations has been done +echo. +echo all operations have been done pause exit 0 diff --git a/kernel/branches/net/const.inc b/kernel/branches/net/const.inc index df9c178814..a00b078993 100644 --- a/kernel/branches/net/const.inc +++ b/kernel/branches/net/const.inc @@ -95,11 +95,11 @@ CAPS_SVM equ 73 ;secure virual machine CAPS_ALTMOVCR8 equ 74 ; ; CPU MSR names -MSR_SYSENTER_CS equ 0x174 -MSR_SYSENTER_ESP equ 0x175 -MSR_SYSENTER_EIP equ 0x176 -MSR_AMD_EFER equ 0xC0000080 ; Extended Feature Enable Register -MSR_AMD_STAR equ 0xC0000081 ; SYSCALL/SYSRET Target Address Register +MSR_SYSENTER_CS equ 0x174 +MSR_SYSENTER_ESP equ 0x175 +MSR_SYSENTER_EIP equ 0x176 +MSR_AMD_EFER equ 0xC0000080 ; Extended Feature Enable Register +MSR_AMD_STAR equ 0xC0000081 ; SYSCALL/SYSRET Target Address Register CR0_PE equ 0x00000001 ;protected mode CR0_MP equ 0x00000002 ;monitor fpu @@ -186,7 +186,7 @@ TSS_SIZE equ (128+8192) OS_BASE equ 0x80000000 -window_data equ OS_BASE +window_data equ (OS_BASE+0x0001000) CURRENT_TASK equ (OS_BASE+0x0003000) TASK_COUNT equ (OS_BASE+0x0003004) @@ -331,7 +331,7 @@ LFB_BASE equ 0xFE000000 new_app_base equ 0; -twdw equ 0x3000 ;(CURRENT_TASK-window_data) +twdw equ 0x2000 ;(CURRENT_TASK-window_data) std_application_base_address equ new_app_base RING0_STACK_SIZE equ (0x2000 - 512) ;512 байт для контекста FPU @@ -469,8 +469,9 @@ struc EVENT .state dd ? ;internal flags .code dd ? rd 5 + .size = $ - .magic + .codesize = $ - .code } -EVENT_SIZE equ 52 virtual at 0 EVENT EVENT @@ -687,4 +688,3 @@ end virtual virtual at 0 CSYM COFF_SYM end virtual - diff --git a/kernel/branches/net/core/debug.inc b/kernel/branches/net/core/debug.inc index 112213cc7b..c6ca66eb37 100644 --- a/kernel/branches/net/core/debug.inc +++ b/kernel/branches/net/core/debug.inc @@ -10,71 +10,71 @@ $Revision: 750 $ ; diamond, 2006 sys_debug_services: - cmp eax, 9 - ja @f - jmp dword [sys_debug_services_table+eax*4] -@@: ret + cmp eax, 9 + ja @f + jmp dword [sys_debug_services_table+eax*4] +@@: ret sys_debug_services_table: - dd debug_set_event_data - dd debug_getcontext - dd debug_setcontext - dd debug_detach - dd debug_suspend - dd debug_resume - dd debug_read_process_memory - dd debug_write_process_memory - dd debug_terminate - dd debug_set_drx + dd debug_set_event_data + dd debug_getcontext + dd debug_setcontext + dd debug_detach + dd debug_suspend + dd debug_resume + dd debug_read_process_memory + dd debug_write_process_memory + dd debug_terminate + dd debug_set_drx debug_set_event_data: ; in: ebx = pointer ; destroys eax mov eax, [current_slot] mov [eax+APPDATA.dbg_event_mem], ebx - ret + ret get_debuggee_slot: ; in: ebx=PID ; out: CF=1 if error ; CF=0 and eax=slot*0x20 if ok ; out: interrupts disabled - cli - mov eax, ebx - call pid_to_slot - test eax, eax - jz .ret_bad - shl eax, 5 - push ebx + cli + mov eax, ebx + call pid_to_slot + test eax, eax + jz .ret_bad + shl eax, 5 + push ebx mov ebx, [CURRENT_TASK] cmp [SLOT_BASE+eax*8+APPDATA.debugger_slot], ebx - pop ebx - jnz .ret_bad -; clc ; automatically - ret + pop ebx + jnz .ret_bad +; clc ; automatically + ret .ret_bad: - stc - ret + stc + ret debug_detach: ; in: ebx=pid ; destroys eax,ebx - call get_debuggee_slot - jc .ret + call get_debuggee_slot + jc .ret and dword [eax*8+SLOT_BASE+APPDATA.debugger_slot], 0 - call do_resume + call do_resume .ret: - sti - ret + sti + ret debug_terminate: ; in: ebx=pid - call get_debuggee_slot - jc debug_detach.ret - mov ecx, eax - shr ecx, 5 - push 2 - pop ebx - jmp sys_system + call get_debuggee_slot + jc debug_detach.ret + mov ecx, eax + shr ecx, 5 + push 2 + pop ebx + jmp sys_system debug_suspend: ; in: ebx=pid @@ -85,30 +85,30 @@ debug_suspend: shl eax, 5 jz .ret mov bl, [CURRENT_TASK+eax+TASKDATA.state] ; process state - test bl, bl - jz .1 - cmp bl, 5 - jnz .ret - mov bl, 2 + test bl, bl + jz .1 + cmp bl, 5 + jnz .ret + mov bl, 2 .2: mov [CURRENT_TASK+eax+TASKDATA.state], bl .ret: - sti - ret + sti + ret .1: - inc ebx - jmp .2 + inc ebx + jmp .2 do_resume: mov bl, [CURRENT_TASK+eax+TASKDATA.state] - cmp bl, 1 - jz .1 - cmp bl, 2 - jnz .ret - mov bl, 5 + cmp bl, 1 + jz .1 + cmp bl, 2 + jnz .ret + mov bl, 5 .2: mov [CURRENT_TASK+eax+TASKDATA.state], bl -.ret: ret -.1: dec ebx - jmp .2 +.ret: ret +.1: dec ebx + jmp .2 debug_resume: ; in: ebx=pid @@ -119,8 +119,8 @@ debug_resume: shl eax, 5 jz .ret call do_resume -.ret: sti - ret +.ret: sti + ret debug_getcontext: ; in: @@ -128,16 +128,16 @@ debug_getcontext: ; ecx=sizeof(CONTEXT) ; edx->CONTEXT ; destroys eax,ecx,edx,esi,edi - cmp ecx, 28h - jnz .ret - push ebx - mov ebx, edx - call check_region - pop ebx - dec eax - jnz .ret - call get_debuggee_slot - jc .ret + cmp ecx, 28h + jnz .ret + push ebx + mov ebx, edx + call check_region + pop ebx + dec eax + jnz .ret + call get_debuggee_slot + jc .ret mov eax, [eax*8+SLOT_BASE+APPDATA.pl0_stack] lea esi, [eax+RING0_STACK_SIZE] mov edi, edx @@ -147,30 +147,30 @@ debug_getcontext: ; top of ring0 stack: ring3 stack ptr (ss+esp), iret data (cs+eip+eflags), pushad sub esi, 8+12+20h lodsd ;edi - mov [edi+24h], eax + mov [edi+24h], eax lodsd ;esi - mov [edi+20h], eax + mov [edi+20h], eax lodsd ; ebp - mov [edi+1Ch], eax + mov [edi+1Ch], eax lodsd ;esp lodsd ;ebx - mov [edi+14h], eax + mov [edi+14h], eax lodsd ;edx - mov [edi+10h], eax + mov [edi+10h], eax lodsd ;ecx - mov [edi+0Ch], eax + mov [edi+0Ch], eax lodsd ;eax - mov [edi+8], eax + mov [edi+8], eax lodsd ;eip - mov [edi], eax + mov [edi], eax lodsd ;cs lodsd ;eflags - mov [edi+4], eax + mov [edi+4], eax lodsd ;esp - mov [edi+18h], eax + mov [edi+18h], eax .ret: - sti - ret + sti + ret debug_setcontext: ; in: @@ -178,120 +178,120 @@ debug_setcontext: ; ecx=sizeof(CONTEXT) ; edx->CONTEXT ; destroys eax,ecx,edx,esi,edi - cmp ecx, 28h - jnz .ret - push ebx - mov ebx, edx - call check_region - pop ebx - dec eax - jnz .ret - call get_debuggee_slot - jc .stiret + cmp ecx, 28h + jnz .ret + push ebx + mov ebx, edx + call check_region + pop ebx + dec eax + jnz .ret + call get_debuggee_slot + jc .stiret 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 - stosd + stosd mov eax, [esi+20h] ;esi - stosd + stosd mov eax, [esi+1Ch] ;ebp - stosd + stosd scasd mov eax, [esi+14h] ;ebx - stosd + stosd mov eax, [esi+10h] ;edx - stosd + stosd mov eax, [esi+0Ch] ;ecx - stosd + stosd mov eax, [esi+8] ;eax - stosd + stosd mov eax, [esi] ;eip - stosd - scasd + stosd + scasd mov eax, [esi+4] ;eflags - stosd + stosd mov eax, [esi+18h] ;esp - stosd + stosd .stiret: - sti + sti .ret: - ret + ret debug_set_drx: - call get_debuggee_slot - jc .errret - mov ebp, eax + call get_debuggee_slot + jc .errret + mov ebp, eax 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 jae .errret - cmp cl, 3 - ja .errret - mov ebx, dr7 - shr ebx, cl - shr ebx, cl - test ebx, 2 ; bit 1+2*index = G0..G3, global break enable - jnz .errret2 - test ch, ch - jns .new + cmp cl, 3 + ja .errret + mov ebx, dr7 + shr ebx, cl + shr ebx, cl + test ebx, 2 ; bit 1+2*index = G0..G3, global break enable + jnz .errret2 + test ch, ch + 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 - test byte [eax+10h], 55h - jnz .okret + movzx ecx, cl + add ecx, ecx + and dword [eax+ecx*2], 0 ; clear DR + btr dword [eax+10h], ecx ; 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 - sti - ret + and dword [esp+36], 0 + sti + ret .errret: - sti - mov dword [esp+36], 1 - ret + sti + mov dword [esp+36], 1 + ret .errret2: - sti - mov dword [esp+36], 2 - ret + sti + mov dword [esp+36], 2 + ret .new: ; add new breakpoint ; cl=index; ch=flags; edx=address - test ch, 0xF0 - jnz .errret - mov bl, ch - and bl, 3 - cmp bl, 2 - jz .errret - mov bl, ch - shr bl, 2 - cmp bl, 2 - jz .errret - test dl, bl - jnz .errret - or byte [eax+10h+1], 3 ; set GE and LE flags - movzx ebx, ch - movzx ecx, cl - 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 - shl edx, cl - not edx - and [eax+10h+2], dx - or [eax+10h+2], bx ; set R/W and LEN fields + test ch, 0xF0 + jnz .errret + mov bl, ch + and bl, 3 + cmp bl, 2 + jz .errret + mov bl, ch + shr bl, 2 + cmp bl, 2 + jz .errret + test dl, bl + jnz .errret + or byte [eax+10h+1], 3 ; set GE and LE flags + movzx ebx, ch + movzx ecx, cl + 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 + shl edx, cl + not edx + and [eax+10h+2], dx + or [eax+10h+2], bx ; 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 - jmp .okret + jmp .okret debug_read_process_memory: ; in: @@ -301,23 +301,23 @@ debug_read_process_memory: ; edx=address in debuggee ; out: [esp+36]=sizeof(read) ; destroys all - push ebx - mov ebx, esi - call check_region - pop ebx - dec eax - jnz .err - call get_debuggee_slot - jc .err - shr eax, 5 - mov ebx, esi - call read_process_memory - sti - mov dword [esp+36], eax - ret + push ebx + mov ebx, esi + call check_region + pop ebx + dec eax + jnz .err + call get_debuggee_slot + jc .err + shr eax, 5 + mov ebx, esi + call read_process_memory + sti + mov dword [esp+36], eax + ret .err: - or dword [esp+36], -1 - ret + or dword [esp+36], -1 + ret debug_write_process_memory: ; in: @@ -327,20 +327,20 @@ debug_write_process_memory: ; edx=address in debuggee ; out: [esp+36]=sizeof(write) ; destroys all - push ebx - mov ebx, esi - call check_region - 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 - call write_process_memory - sti - mov [esp+36], eax - ret + push ebx + mov ebx, esi + call check_region + 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 + call write_process_memory + sti + mov [esp+36], eax + ret debugger_notify: ; in: eax=debugger slot @@ -349,127 +349,68 @@ debugger_notify: ; interrupts must be disabled! ; destroys all general registers ; interrupts remain disabled - xchg ebp, eax - mov edi, [timer_ticks] - add edi, 500 ; 5 sec timeout + xchg ebp, eax + mov edi, [timer_ticks] + add edi, 500 ; 5 sec timeout .1: - mov eax, ebp - shl eax, 8 + mov eax, ebp + shl eax, 8 mov edx, [SLOT_BASE+eax+APPDATA.dbg_event_mem] - test edx, edx - jz .ret + test edx, edx + jz .ret ; read buffer header - push ecx - push eax - push eax - mov eax, ebp - mov ebx, esp - mov ecx, 8 - call read_process_memory - cmp eax, ecx - jz @f - add esp, 12 - jmp .ret + push ecx + push eax + push eax + mov eax, ebp + mov ebx, esp + mov ecx, 8 + call read_process_memory + cmp eax, ecx + jz @f + add esp, 12 + jmp .ret @@: - cmp dword [ebx], 0 - jg @f + cmp dword [ebx], 0 + jg @f .2: - pop ecx - pop ecx - pop ecx + pop ecx + pop ecx + pop ecx cmp dword [CURRENT_TASK], 1 - jnz .notos - cmp [timer_ticks], edi - jae .ret + jnz .notos + cmp [timer_ticks], edi + jae .ret .notos: - sti - call change_task - cli - jmp .1 + sti + call change_task + cli + jmp .1 @@: - mov ecx, [ebx+8] - add ecx, [ebx+4] - cmp ecx, [ebx] - ja .2 + mov ecx, [ebx+8] + add ecx, [ebx+4] + cmp ecx, [ebx] + ja .2 ; advance buffer position - push ecx - mov ecx, 4 - sub ebx, ecx - mov eax, ebp - add edx, ecx - call write_process_memory - pop eax + push ecx + mov ecx, 4 + sub ebx, ecx + mov eax, ebp + add edx, ecx + call write_process_memory + pop eax ; write message - mov eax, ebp - add edx, ecx - add edx, [ebx+8] - add ebx, 20 - pop ecx - pop ecx - pop ecx - call write_process_memory + mov eax, ebp + add edx, ecx + add edx, [ebx+8] + add ebx, 20 + pop ecx + pop ecx + pop ecx + call write_process_memory ; new debug event - mov eax, ebp - shl eax, 8 + mov eax, ebp + shl eax, 8 or byte [SLOT_BASE+eax+APPDATA.event_mask+1], 1 ; set flag 100h .ret: - ret - -debug_exc: - test byte [esp+8+2], 2 - jnz v86_debug_exc -; int 1 = #DB - save_ring3_context - cld - mov ax, app_data ;os_data - mov ds, ax - mov es, ax - mov eax, dr6 - push eax - xor eax, eax - mov dr6, eax -; test if debugging - cli - mov eax, [current_slot] - mov eax, [eax+APPDATA.debugger_slot] - test eax, eax - jnz .debug - sti -; not debuggee => say error and terminate - add esp, 0x20+4 - mov [error_interrupt], 1 - call show_error_parameters - mov edx, [TASK_BASE] - mov byte [edx+TASKDATA.state], 4 - jmp change_task -.debug: -; we are debugged process, notify debugger and suspend ourself -; eax=debugger PID - pop edx - mov ebx, dr7 - mov cl, not 1 -.l1: - test bl, 1 - jnz @f - and dl, cl -@@: - shr ebx, 2 - add cl, cl - inc ecx - cmp cl, not 10h - jnz .l1 - push edx ; DR6 image - mov ecx, [TASK_BASE] - push dword [ecx+TASKDATA.pid] ; PID - push 12 - pop ecx - push 3 ; 3 = debug exception - call debugger_notify - pop ecx - pop ecx - pop ecx - mov edx, [TASK_BASE] - mov byte [edx+TASKDATA.state], 1 ; suspended - call change_task - restore_ring3_context - iretd + ret diff --git a/kernel/branches/net/core/exports.inc b/kernel/branches/net/core/exports.inc index ffe91ff216..e634f09a2f 100644 --- a/kernel/branches/net/core/exports.inc +++ b/kernel/branches/net/core/exports.inc @@ -9,57 +9,57 @@ $Revision: 924 $ 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 + szLoadCursor db 'LoadCursor',0 szSelectHwCursor db 'SelectHwCursor',0 szSetHwCursor db 'SetHwCursor',0 szHwCursorRestore db 'HwCursorRestore', 0 @@ -68,19 +68,19 @@ iglobal 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 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 +95,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 @@ -131,11 +131,11 @@ kernel_export: dd szGetPid , get_pid dd szCreateObject , create_kernel_object dd szDestroyObject , destroy_kernel_object - dd szCreateEvent , create_event - dd szRaiseEvent , raise_event - dd szWaitEvent , wait_event - dd szDestroyEvent , destroy_event - dd szClearEvent , clear_event + 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 @@ -148,17 +148,17 @@ kernel_export: dd szSysMsgBoardChar , sys_msg_board dd szGetCurrentTask , get_curr_task dd szLoadFile , load_file ;retval eax, ebx - dd szSendEvent , send_event + 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,7 +167,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/fpu.inc b/kernel/branches/net/core/fpu.inc index b08c005d33..25a86a29e4 100644 --- a/kernel/branches/net/core/fpu.inc +++ b/kernel/branches/net/core/fpu.inc @@ -142,7 +142,7 @@ fpu_restore: ret align 4 -e7: ;#NM exception handler +except_7: ;#NM exception handler save_ring3_context clts mov ax, app_data ; @@ -180,109 +180,4 @@ e7: ;#NM exception handler iglobal fpu_owner dd 0 - endg - -reg_eip equ ebp+4 -reg_cs equ ebp+8 -reg_eflags equ ebp+12 -reg_esp equ ebp+16 -reg_ss equ ebp+20 - -align 4 -except_16: ;fpu native exceptions handler - test byte [esp+8+2], 2 - jnz v86_except_16 - push ebp - mov ebp, esp - - push eax - push ebx - push ecx - push edx - - mov ebx, [CURRENT_TASK] - shl ebx, 8 - - mov eax, [ebx+SLOT_BASE+APPDATA.fpu_handler] - test eax, eax - jz .default - - mov ecx, [reg_eip] - mov edx, [reg_esp] - sub edx, 4 - mov [edx], ecx - mov [reg_esp], edx - mov dword [reg_eip], eax - - pop edx - pop ecx - pop ebx - pop eax - - leave - iretd - -.default: - pop edx - pop ecx - pop ebx - pop eax - leave - - save_ring3_context ;debugger support - - mov bl, 16 - jmp exc_c - -align 4 -except_19: ;sse exceptions handler - test byte [esp+8+2], 2 - jnz v86_except_19 - push ebp - mov ebp, esp - - push eax - push ebx - push ecx - push edx - - mov ebx, [current_slot] - - mov eax, [ebx+APPDATA.sse_handler] - test eax, eax - jz .default - - mov ecx, [reg_eip] - mov edx, [reg_esp] - sub edx, 4 - mov [edx], ecx - mov [reg_esp], edx - mov dword [reg_eip], eax - - pop edx - pop ecx - pop ebx - pop eax - - leave - iretd - -.default: - pop edx - pop ecx - pop ebx - pop eax - leave - - save_ring3_context ;debugger support - - mov bl, 19 - jmp exc_c - -restore reg_eip -restore reg_cs -restore reg_eflags -restore reg_esp -restore reg_ss - - +endg diff --git a/kernel/branches/net/core/heap.inc b/kernel/branches/net/core/heap.inc index 5b3e2eb9ff..c6f732acd4 100644 --- a/kernel/branches/net/core/heap.inc +++ b/kernel/branches/net/core/heap.inc @@ -91,11 +91,11 @@ macro remove_from_used op align 4 proc init_kernel_heap - mov ecx, 64/4 - mov edi, mem_block_list - xor eax, eax - cld - rep stosd + mov ecx, 64 + mov edi, mem_block_list + xor eax, eax + cld + rep stosd mov ecx, 512/4 mov edi, mem_block_map @@ -138,22 +138,23 @@ proc init_kernel_heap mov [ebx+list_bk], eax mov [ebx+block_base], HEAP_BASE+4096*MEM_BLOCK_SIZE - mov ecx, [MEM_AMOUNT] - 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 ecx, [pg_data.kernel_pages] + shl ecx, 12 + sub ecx, HEAP_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_list+63*4], ebx - mov byte [mem_block_map], 0xFC - and [heap_mutex], 0 - mov [heap_blocks], 4095 - mov [free_blocks], 4095 - ret + mov [mem_block_list+63*4], ebx + mov byte [mem_block_map], 0xFC + and [heap_mutex], 0 + mov [heap_blocks], 4095 + mov [free_blocks], 4094 + ret endp ; param diff --git a/kernel/branches/net/core/memory.inc b/kernel/branches/net/core/memory.inc index 3d9dbd2460..40736abd64 100644 --- a/kernel/branches/net/core/memory.inc +++ b/kernel/branches/net/core/memory.inc @@ -453,7 +453,7 @@ proc new_mem_resize stdcall, new_size:dword @@: call alloc_page test eax, eax - jz .exit + jz .exit_pop stdcall map_page_table, edi, eax @@ -491,6 +491,9 @@ proc new_mem_resize stdcall, new_size:dword jb @B jmp .update_size +.exit_pop: + pop edi + pop esi .exit: xor eax, eax inc eax @@ -544,24 +547,16 @@ get_pg_addr: align 4 +; Now it is called from core/sys32::exc_c (see stack frame there) proc page_fault_handler - test byte [esp+12+2], 2 - jnz v86_page_fault + .err_addr equ ebp-4 - .err_code equ ebp+32 - .err_addr equ ebp-4 - - pushad - mov ebp, esp - mov eax, cr2 - push eax - - mov ax, app_data - mov ds, ax - mov es, ax - - 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 @@ -571,129 +566,115 @@ proc page_fault_handler ; pop edx ; pop eax - mov ebx, [.err_addr] - mov eax, [.err_code] + mov eax, [pf_err_code] - cmp ebx, OS_BASE - 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 ;таблицы страниц ядра + ;Ошибка + .lfb: + ;область LFB + ;Ошибка + jmp .fail +end if +.core_tabs: +.fail: ;simply return to caller + mov esp, ebp + pop ebx ;restore exception number (#PF) + ret - cmp ebx, LFB_BASE - jb .core_tabs ;таблицы страниц ядра - ;Ошибка -.lfb: - ;область LFB - ;Ошибка - jmp .fail - -align 4 .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,[ebp-4],eax,dword PG_UW + stdcall map_page,[.err_addr],eax,dword PG_UW - mov edi, [ebp-4] - and edi, 0xFFFFF000 - mov ecx, 1024 - xor eax, eax - cld - rep stosd -.exit: - mov esp, ebp - popad - add esp, 4 - iretd + 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 -.err_access: +.err_access = .fail ;никогда не происходит - jmp .fail + ;jmp .fail .kernel_space: - test eax, PG_MAP - jz .fail ;страница не присутствует + test eax, PG_MAP + jz .fail ;страница не присутствует - test eax, 4 ;U/S - jnz .fail ;приложение обратилось к памяти - ;ядра - test eax, 8 - jnz .fail ;установлен зарезервированный бит - ;в таблицах страниц. добавлено в P4/Xeon + test eax,12 ;U/S (+below) + jnz .fail ;приложение обратилось к памяти + ;ядра + ;test eax, 8 + ;jnz .fail ;установлен зарезервированный бит + ;в таблицах страниц. добавлено в 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,[ebp-4],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 - cld - rep movsd - jmp .exit - - -;не обрабатываем. Ошибка - -.core_tabs: -.fail: - mov esp, ebp - popad - add esp, 4 - -; iretd - - save_ring3_context ;debugger support - - mov bl, 14 - jmp exc_c - iretd + add esi, [default_io_map] + mov ecx, 4096/4 + ;cld ;caller is duty for this + rep movsd + jmp .exit endp align 4 @@ -983,29 +964,29 @@ endp align 4 sysfn_meminfo: - ; add ebx, new_app_base - cmp ebx, OS_BASE + ; add ecx, new_app_base + cmp ecx, OS_BASE jae .fail mov eax, [pg_data.pages_count] - mov [ebx], eax + mov [ecx], eax shl eax, 12 - mov [esp+36], eax - mov ecx, [pg_data.pages_free] - mov [ebx+4], ecx - mov edx, [pg_data.pages_faults] - mov [ebx+8], edx - mov esi, [heap_size] - mov [ebx+12], esi - mov edi, [heap_free] - mov [ebx+16], edi + 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 [ebx+20], eax - mov ecx, [free_blocks] - mov [ebx+24], ecx + mov [ecx+20], eax + mov eax, [free_blocks] + mov [ecx+24], eax ret .fail: - mov dword [esp+36], -1 + mov dword [esp+32], -1 ret align 4 @@ -1014,15 +995,17 @@ f68call: dd f68.12 dd f68.13 dd f68.14 - dd f68.15 + dd f68.fail ;moved to f68.24 dd f68.16 dd f68.17 - dd f68.18 + 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 align 4 f68: @@ -1032,7 +1015,7 @@ f68: cmp eax, 11 jb .fail - cmp eax, 23 + cmp eax, 25 ja .fail jmp dword [f68call+eax*4-11*4] @@ -1051,14 +1034,16 @@ f68: .14: cmp ebx, OS_BASE jae .fail - stdcall get_event_ex, ebx, ecx + mov edi,ebx + call get_event_ex mov [esp+36], eax ret -.15: - mov ecx, [current_slot] - mov eax, [ecx+APPDATA.fpu_handler] - mov [ecx+APPDATA.fpu_handler], ebx - mov [esp+36], eax +.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 .16: test ebx, ebx @@ -1072,12 +1057,15 @@ f68: call srv_handlerEx ;ebx mov [esp+36], eax ret -.18: - mov ecx, [current_slot] - mov eax, [ecx+APPDATA.sse_handler] - mov [ecx+APPDATA.sse_handler], 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 .19: cmp ebx, OS_BASE jae .fail @@ -1318,6 +1306,3 @@ proc create_ring_buffer stdcall, size:dword, flags:dword .fail: ret endp - - - diff --git a/kernel/branches/net/core/sched.inc b/kernel/branches/net/core/sched.inc index 20a0922464..6cf987f1af 100644 --- a/kernel/branches/net/core/sched.inc +++ b/kernel/branches/net/core/sched.inc @@ -15,321 +15,229 @@ $Revision: 907 $ align 32 irq0: - pushad - mov ax, app_data ; - mov ds, ax - mov es, ax - -; cmp dword[CURRENT_TASK], 1 -; jnz @f -; mov eax, [esp + 32] -; cmp eax, idle_loop + 1 -; jz @f -; DEBUGF 1, "K : OOOPS! EAX = 0x%x\n", eax -; @@: - - inc dword [timer_ticks] - - mov eax, [timer_ticks] - call playNote ; <<<--- Speaker driver - - cmp eax,[next_usage_update] - jb .nocounter - add eax,100 - mov [next_usage_update],eax - call updatecputimes -.nocounter: - cmp [DONT_SWITCH], byte 1 - jne .change_task - - mov al,0x20 ; send End Of Interrupt signal - mov dx,0x20 - out dx,al - - mov [DONT_SWITCH], byte 0 - - popad - iretd - -.change_task: - call update_counters - - call find_next_task - mov ecx, eax - - mov al,0x20 ; send End Of Interrupt signal - mov dx,0x20 - out dx,al - - test ecx, ecx ; if there is only one running process - jnz .return - - call do_change_task - -.return: - popad - ; popfd - iretd - + pushad + Mov ds, ax, app_data + mov es, ax + inc [timer_ticks] + mov eax, [timer_ticks] + call playNote ; <<<--- Speaker driver + sub eax,[next_usage_update] + cmp eax,100 + jb .nocounter + add [next_usage_update],100 + call updatecputimes + .nocounter: + mov al,0x20 ; send End Of Interrupt signal + out 0x20,al + btr dword[DONT_SWITCH], 0 + jc .return + call find_next_task + jz .return ; if there is only one running process + call do_change_task + .return: + popad + iretd align 4 change_task: - - pushfd - cli - pushad - - call update_counters - + pushfd + cli + pushad if 0 - -; \begin{Mario79} - cmp [dma_task_switched], 1 - jne .find_next_task - mov [dma_task_switched], 0 - mov ebx, [dma_process] - cmp [CURRENT_TASK], ebx - je .return - mov edi, [dma_slot_ptr] - mov [CURRENT_TASK], ebx - mov [TASK_BASE], edi - jmp @f +; \begin{Mario79} ; <- must be refractoried, if used... + cmp [dma_task_switched], 1 + jne .find_next_task + mov [dma_task_switched], 0 + mov ebx, [dma_process] + cmp [CURRENT_TASK], ebx + je .return + mov edi, [dma_slot_ptr] + mov [CURRENT_TASK], ebx + mov [TASK_BASE], edi + jmp @f .find_next_task: ; \end{Mario79} - end if - - call find_next_task - test eax, eax ; the same task -> skip switch - jnz .return -@@: - mov [DONT_SWITCH],byte 1 - call do_change_task - -.return: - popad - popfd - ret - + call find_next_task + jz .return ; the same task -> skip switch + @@: mov byte[DONT_SWITCH], 1 + call do_change_task + .return: + popad + popfd + ret uglobal - align 4 - far_jump: - .offs dd ? - .sel dw ? - context_counter dd ? ;noname & halyavin - next_usage_update dd ? - timer_ticks dd ? - prev_slot dd ? - event_sched dd ? +align 4 +; far_jump: +; .offs dd ? +; .sel dw ? + context_counter dd 0 ;noname & halyavin + next_usage_update dd 0 + timer_ticks dd 0 +; prev_slot dd ? +; event_sched dd ? endg - +align 4 update_counters: - mov edi, [TASK_BASE] - mov ebx, [edi+TASKDATA.counter_add] ; time stamp counter add - rdtsc - sub eax, ebx - add eax, [edi+TASKDATA.counter_sum] ; counter sum - mov [edi+TASKDATA.counter_sum], eax -ret - - -; Find next task to execute -; result: ebx = number of the selected task -; eax = 1 if the task is the same -; edi = address of the data for the task in ebx -; [0x3000] = ebx and [0x3010] = edi -; corrupts other regs -find_next_task: - mov ebx, [CURRENT_TASK] - mov edi, [TASK_BASE] - mov [prev_slot], ebx - -.waiting_for_termination: -.waiting_for_reuse: -.waiting_for_event: -.suspended: - cmp ebx, [TASK_COUNT] - jb @f - mov edi, CURRENT_TASK - xor ebx, ebx -@@: - - add edi,0x20 - inc ebx - - mov al, byte [edi+TASKDATA.state] - test al, al - jz .found - cmp al, 1 - jz .suspended - cmp al, 2 - jz .suspended - cmp al, 3 - je .waiting_for_termination - cmp al, 4 - je .waiting_for_termination - cmp al, 9 - je .waiting_for_reuse - - mov [CURRENT_TASK],ebx - mov [TASK_BASE],edi - - cmp al, 5 - jne .noevents - call get_event_for_app - test eax, eax - jnz @f - mov eax, ebx - shl eax, 8 - mov eax, [SLOT_BASE + APPDATA.wait_timeout + eax] - cmp eax, [timer_ticks] - jae .waiting_for_event - xor eax, eax -@@: - mov [event_sched], eax - mov [edi+TASKDATA.state], byte 0 -.noevents: -.found: - mov [CURRENT_TASK],ebx - mov [TASK_BASE],edi - rdtsc ;call _rdtsc - mov [edi+TASKDATA.counter_add],eax - - mov esi, [prev_slot] - xor eax, eax - cmp ebx, esi - sete al -ret - -; param -; ebx = incoming task -; esi = outcomig task - -do_change_task: - - shl ebx, 8 - add ebx, SLOT_BASE - mov [current_slot], ebx - - shl esi, 8 - add esi, SLOT_BASE - - mov [esi+APPDATA.saved_esp], esp - mov esp, [ebx+APPDATA.saved_esp] - -; set thread io map - - mov ecx, [ebx+APPDATA.io_map] - mov edx, [ebx+APPDATA.io_map+4] - mov dword [page_tabs+((tss._io_map_0 and -4096) shr 10)], ecx - mov dword [page_tabs+((tss._io_map_1 and -4096) shr 10)], edx - - mov eax, [ebx+APPDATA.dir_table] - cmp eax, [esi+APPDATA.dir_table] - je @F - mov cr3, eax -@@: - mov eax, [ebx+APPDATA.saved_esp0] - mov [tss._esp0], eax - mov ax, graph_data - mov gs, ax - - mov eax, [CURRENT_TASK] - cmp eax, [fpu_owner] - clts ;clear a task switch flag - je @F - ;and set it again if the owner - mov ecx, cr0 ;of a fpu has changed - or ecx, CR0_TS - mov cr0, ecx -@@: - inc [context_counter] ;noname & halyavin - test [ebx+APPDATA.dbg_state], 1 - jnz @F - ret -@@: - mov eax, [ebx+APPDATA.dbg_regs.dr0] - mov dr0, eax - mov eax, [ebx+APPDATA.dbg_regs.dr1] - mov dr1, eax - mov eax, [ebx+APPDATA.dbg_regs.dr2] - mov dr2, eax - mov eax, [ebx+APPDATA.dbg_regs.dr3] - mov dr3, eax - xor eax, eax - mov dr6, eax - mov eax, [ebx+APPDATA.dbg_regs.dr7] - mov dr7, eax - ret - + mov edi, [TASK_BASE] + rdtsc + sub eax, [edi+TASKDATA.counter_add] ; time stamp counter add + add [edi+TASKDATA.counter_sum], eax ; counter sum + ret align 4 updatecputimes: + xor eax,eax + xchg eax,[idleuse] + mov [idleusesec],eax + mov ecx, [TASK_COUNT] + mov edi, TASK_DATA + .newupdate: + xor eax,eax + xchg eax,[edi+TASKDATA.counter_sum] + mov [edi+TASKDATA.cpu_usage],eax + add edi,0x20 + loop .newupdate + ret - mov eax,[idleuse] - mov [idleusesec],eax - mov [idleuse],dword 0 - mov ecx, [TASK_COUNT] - mov edi, TASK_DATA -.newupdate: - mov ebx,[edi+TASKDATA.counter_sum] - mov [edi+TASKDATA.cpu_usage],ebx - mov [edi+TASKDATA.counter_sum],dword 0 - add edi,0x20 - dec ecx - jnz .newupdate +align 4 +find_next_task: +;info: +; Find next task to execute +;retval: +; ebx = address of the APPDATA for the selected task (slot-base) +; esi = previous slot-base ([current_slot] at the begin) +; edi = address of the TASKDATA for the selected task +; ZF = 1 if the task is the same +;warning: +; [CURRENT_TASK] = bh , [TASK_BASE] = edi -- as result +; [current_slot] is not set to new value (ebx)!!! +;scratched: eax,ecx + call update_counters ; edi := [TASK_BASE] + Mov esi, ebx, [current_slot] + .loop: + cmp bh,[TASK_COUNT] + jb @f + xor bh, bh + mov edi,CURRENT_TASK + @@: inc bh ; ebx += APPDATA.size + add edi,0x20 ; edi += TASKDATA.size + mov al, [edi+TASKDATA.state] + test al, al + jz .found ; state == 0 + cmp al, 5 + jne .loop ; state == 1,2,3,4,9 + ; state == 5 + pushad ; more freedom for [APPDATA.wait_test] + call [ebx+APPDATA.wait_test] + mov [esp+28],eax + popad + or eax,eax + jnz @f + ; testing for timeout + mov ecx, [timer_ticks] + sub ecx, [ebx+APPDATA.wait_begin] + cmp ecx, [ebx+APPDATA.wait_timeout] + jb .loop + @@: mov [ebx+APPDATA.wait_param], eax ; retval for wait + mov [edi+TASKDATA.state], 0 + .found: + mov [CURRENT_TASK],bh + mov [TASK_BASE],edi + rdtsc ;call _rdtsc + mov [edi+TASKDATA.counter_add],eax ; for next using update_counters + cmp ebx, esi ;esi - previous slot-base + ret +;TODO: Надо бы убрать использование do_change_task из V86... +; и после этого перенести обработку TASKDATA.counter_add/sum в do_change_task - ret +align 4 +do_change_task: +;param: +; ebx = address of the APPDATA for incoming task (new) +;warning: +; [CURRENT_TASK] and [TASK_BASE] must be changed before (e.g. in find_next_task) +; [current_slot] is the outcoming (old), and set here to a new value (ebx) +;scratched: eax,ecx,esi + mov esi,ebx + xchg esi,[current_slot] + ; set new stack after saving old + mov [esi+APPDATA.saved_esp], esp + mov esp, [ebx+APPDATA.saved_esp] + ; 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 + 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 + Mov [tss._esp0],eax,[ebx+APPDATA.saved_esp0] + ; set gs selector unconditionally + Mov gs,ax,graph_data + ; set CR0.TS + cmp bh, byte[fpu_owner] ;bh == incoming task (new) + clts ;clear a task switch flag + je @f + mov eax, cr0 ;and set it again if the owner + or eax, CR0_TS ;of a fpu has changed + mov cr0, eax + @@: ; set context_counter (only for user pleasure ???) + inc [context_counter] ;noname & halyavin + ; set debug-registers, if it's necessary + test byte[ebx+APPDATA.dbg_state], 1 + jz @f + xor eax, eax + mov dr6, eax + lea esi,[ebx+ecx+APPDATA.dbg_regs-APPDATA.dir_table] ;offset>0x7F + cld + macro lodsReg [reg] { + lodsd + mov reg,eax + } lodsReg dr0, dr1, dr2, dr3, dr7 + purge lodsReg + @@: ret +;end. if 0 - - struc TIMER { .next dd ? .exp_time dd ? .func dd ? - .arg dd ? + .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) -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 +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) +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 rdy_head rd 16 - align 4 pick_task: - xor eax, eax -.pick: - mov ebx, [rdy_head+eax*4] - test ebx, ebx - jz .next - - mov [next_task], ebx - test [ebx+flags.billable] - jz @F - mov [bill_task], ebx -@@: - ret -.next: - inc eax - jmp .pick + xor eax, eax + .pick: + mov ebx, [rdy_head+eax*4] + test ebx, ebx + jz .next + mov [next_task], ebx + test [ebx+flags.billable] + jz @F + mov [bill_task], ebx + @@: + ret + .next: + inc eax + jmp .pick ; param ; eax= task @@ -338,51 +246,48 @@ pick_task: ; eax= task ; ebx= queue ; ecx= front if 1 or back if 0 - align 4 shed: - cmp [eax+.tics_left], 0 ;signed compare - mov ebx, [eax+.priority] - setg ecx - jg @F + cmp [eax+.tics_left], 0 ;signed compare + mov ebx, [eax+.priority] + setg ecx + jg @F - mov edx, [eax+.tics_quantum] - mov [eax+.ticks_left], edx - cmp ebx, (IDLE_PRIORITY-1) - je @F - inc ebx -@@: - ret + mov edx, [eax+.tics_quantum] + mov [eax+.ticks_left], edx + cmp ebx, (IDLE_PRIORITY-1) + je @F + inc ebx + @@: + ret ; param ; eax= task - align 4 enqueue: - call shed ;eax - cmp [rdy_head+ebx*4],0 - jnz @F + call shed ;eax + cmp [rdy_head+ebx*4],0 + jnz @F - mov [rdy_head+ebx*4], eax - mov [rdy_tail+ebx*4], eax - mov [eax+.next_ready], 0 - jmp .pick -@@: - test ecx, ecx - jz .back + mov [rdy_head+ebx*4], eax + mov [rdy_tail+ebx*4], eax + mov [eax+.next_ready], 0 + jmp .pick + @@: + test ecx, ecx + jz .back - mov ecx, [rdy_head+ebx*4] - mov [eax+.next_ready], ecx - mov [rdy_head+ebx*4], eax - jmp .pick -.back: - mov ecx, [rdy_tail+ebx*4] - mov [ecx+.next_ready], eax - mov [rdy_tail+ebx*4], eax - mov [eax+.next_ready], 0 -.pick: - call pick_proc ;select next task - ret + mov ecx, [rdy_head+ebx*4] + mov [eax+.next_ready], ecx + mov [rdy_head+ebx*4], eax + jmp .pick + .back: + mov ecx, [rdy_tail+ebx*4] + mov [ecx+.next_ready], eax + mov [rdy_tail+ebx*4], eax + mov [eax+.next_ready], 0 + .pick: + call pick_proc ;select next task + ret end if - diff --git a/kernel/branches/net/core/sys32.inc b/kernel/branches/net/core/sys32.inc index 2021a98611..94bbc1bee9 100644 --- a/kernel/branches/net/core/sys32.inc +++ b/kernel/branches/net/core/sys32.inc @@ -14,212 +14,227 @@ $Revision: 982 $ -align 4 -idtreg: - dw 8*0x41-1 - dd idts+8 - +align 4 ;3A08 build_interrupt_table: - - mov edi, idts+8 - mov esi, sys_int - mov ecx, 0x40 - @@: - lodsd - mov [edi], ax ; lower part of offset - mov [edi+2], word os_code ; segment selector - mov ax, word 10001110b shl 8 ; type: interrupt gate - mov [edi+4], eax - add edi, 8 - loop @b - - ;mov edi,8*0x40+idts+8 - mov dword [edi], (i40 and 0xFFFF) or (os_code shl 16) - mov dword [edi+4], (11101111b shl 8) or (i40 and 0xFFFF0000) - ; type: trap gate - ret + mov edi, idts + mov esi, sys_int + mov ecx, 0x40 + mov eax, (10001110b shl 24) + os_code + @@: movsw ;low word of code-entry + stosd ;interrupt gate type : os_code selector + movsw ;high word of code-entry + loop @b + movsd ;copy low dword of trap gate for int 0x40 + movsd ;copy high dword of trap gate for int 0x40 + lidt [esi] + ret iglobal - - msg_sel_ker db "kernel", 0 - msg_sel_app db "application", 0 - + align 4 sys_int: - dd e0,debug_exc,e2,e3 - dd e4,e5,e6,e7 - dd e8,e9,e10,e11 - dd e12,e13,page_fault_handler,e15 + ;exception handlers addresses (for interrupt gate construction) + dd e0,e1,e2,e3,e4,e5,e6,except_7 ; SEE: core/fpu.inc + dd e8,e9,e10,e11,e12,e13,page_fault_exc,e15 + dd e16, e17,e18, e19 + times 12 dd unknown_interrupt ;int_20..int_31 - dd except_16, e17,e18, except_19 - times 12 dd unknown_interrupt + ;interrupt handlers addresses (for interrupt gate construction) + dd irq0, irq_serv.irq_1, irq_serv.irq_2 + if USE_COM_IRQ + dd irq_serv.irq_3, irq_serv.irq_4 + else + dd p_irq3, p_irq4 ;??? нестыковка + end if + dd irq_serv.irq_5, p_irq6, irq_serv.irq_7 + dd irq_serv.irq_8, irq_serv.irq_9, irq_serv.irq_10 + dd irq_serv.irq_11, irq_serv.irq_12, irqD,p_irq14,p_irq15 + times 16 dd unknown_interrupt ;int_0x30..int_0x3F - dd irq0, irq_serv.irq_1, irq_serv.irq_2 -if USE_COM_IRQ - dd irq_serv.irq_3, irq_serv.irq_4 -else - dd p_irq3, p_irq4 -end if - dd irq_serv.irq_5, p_irq6, irq_serv.irq_7 - dd irq_serv.irq_8, irq_serv.irq_9, irq_serv.irq_10 - dd irq_serv.irq_11, irq_serv.irq_12,irqD ,p_irq14,p_irq15 + ;int_0x40 gate trap (for directly copied) + dw i40 and 0xFFFF, os_code, 11101111b shl 8, i40 shr 16 - times 16 dd unknown_interrupt + idtreg: ; data for LIDT instruction (!!! must be immediately below sys_int data) + dw 2*($-sys_int-4)-1 + dd idts ;0x8000B100 + dw 0 ;просто выравнивание + + msg_fault_sel dd msg_exc_8,msg_exc_u,msg_exc_a,msg_exc_b + dd msg_exc_c,msg_exc_d,msg_exc_e + + msg_exc_8 db "Double fault", 0 + msg_exc_u db "Undefined Exception", 0 + msg_exc_a db "Invalid TSS", 0 + msg_exc_b db "Segment not present", 0 + msg_exc_c db "Stack fault", 0 + msg_exc_d db "General protection fault", 0 + msg_exc_e db "Page fault", 0 + + msg_sel_ker db "kernel", 0 + msg_sel_app db "application", 0 - dd i40 endg -macro save_ring3_context -{ - pushad +macro save_ring3_context { + pushad } -macro restore_ring3_context -{ - popad +macro restore_ring3_context { + popad } - -; simply return control to interrupted process -unknown_interrupt: - iret - -macro exc_wo_code [num] -{ - forward +macro exc_wo_code [num] { e#num : - save_ring3_context - mov bl, num - jmp exc_c -} + save_ring3_context + mov bl, num + jmp exc_c +} exc_wo_code 0,1,2,3,4,5,6,15,16,19 -macro exc_w_code [num] -{ - forward +macro exc_w_code [num] { e#num : - add esp, 4 - save_ring3_context - mov bl, num - jmp exc_c -} + add esp, 4 + save_ring3_context + mov bl, num + jmp exc_c +} exc_w_code 8,9,10,11,12,13,17,18 -exc_wo_code 0, 2, 3, 4, 5, 6, 9, 15, 18 -exc_w_code 8, 10, 11, 12, 13, 14, 17 -exc_c: - mov ax, app_data ;исключение - mov ds, ax ;загрузим правильные значени - mov es, ax ;в регистры +uglobal + pf_err_code dd ? +endg +page_fault_exc: ; дуракоусточивость: селекторы испорчены... + pop [ss:pf_err_code]; действительно до следующего #PF + save_ring3_context + mov bl,14 + +exc_c: ; исключения (все, кроме 7-го - #NM) +; Фрэйм стека при исключении/прерывании из 3-го кольца + pushad (т.е., именно здесь) + reg_ss equ esp+0x30 + reg_esp3 equ esp+0x2C + reg_eflags equ esp+0x28 + reg_cs3 equ esp+0x24 + reg_eip equ esp+0x20 + ; это фрэйм от pushad + reg_eax equ esp+0x1C + reg_ecx equ esp+0x18 + reg_edx equ esp+0x14 + reg_ebx equ esp+0x10 + reg_esp0 equ esp+0x0C + reg_ebp equ esp+0x08 + reg_esi equ esp+0x04 + reg_edi equ esp+0x00 + + Mov ds,ax,app_data ; загрузим правильные значения + mov es,ax ; в сегментные регистры + cld ; и приводим DF к стандарту + movzx ebx,bl ; redirect to V86 manager? (EFLAGS & 0x20000) != 0? - test byte [esp+20h+8+2], 2 - jnz v86_exc_c - -; test if debugging - cli - mov eax, [current_slot] - mov eax, [eax+APPDATA.debugger_slot] - test eax, eax - jnz .debug - sti + test byte[reg_eflags+2],2 + jnz v86_exc_c + cmp bl,14 ; #PF + jne @f + call page_fault_handler ; SEE: core/memory.inc + @@: mov esi, [current_slot] + btr [esi+APPDATA.except_mask], ebx + jnc @f + mov eax,[esi+APPDATA.exc_handler] + test eax, eax + jnz IRetToUserHook + @@: cli + mov eax, [esi+APPDATA.debugger_slot] + test eax, eax + jnz .debug + sti ; not debuggee => say error and terminate - movzx eax, bl - mov [error_interrupt], eax - call show_error_parameters - add esp, 0x20 - mov edx, [TASK_BASE] - mov [edx + TASKDATA.state], byte 4 - - jmp change_task - + call show_error_parameters ;; only ONE using, inline ??? + ;mov edx, [TASK_BASE] + mov [edx + TASKDATA.state], byte 4 ; terminate + jmp change_task ; stack - here it does not matter at all, SEE: core/shed.inc .debug: ; we are debugged process, notify debugger and suspend ourself ; eax=debugger PID - cld - movzx ecx, bl - push ecx - mov ecx, [TASK_BASE] - push dword [ecx+TASKDATA.pid] ; PID of current process - push 12 - pop ecx - push 1 ; 1=exception - call debugger_notify - pop ecx - pop ecx - pop ecx - mov edx, [TASK_BASE] - mov byte [edx+TASKDATA.state], 1 ; suspended - call change_task - restore_ring3_context - iretd + mov ecx,1 ; debug_message code=other_exception + cmp bl,1 ; #DB + jne .notify ; notify debugger and suspend ourself + mov ebx, dr6 ; debug_message data=DR6_image + xor edx, edx + mov dr6, edx + mov edx, dr7 + mov cl, not 8 + .l1: shl dl,2 + jc @f + and bl, cl + @@: sar cl,1 + jc .l1 + mov cl, 3 ; debug_message code=debug_exception +.notify: + push ebx ; debug_message data + mov ebx, [TASK_BASE] + push [ebx+TASKDATA.pid] ; PID + push ecx ; debug_message code ((here: ecx==1/3)) + mov cl, 12 ; debug_message size + call debugger_notify ;; only ONE using, inline ??? SEE: core/debug.inc + add esp,12 + mov edx, [TASK_BASE] + mov byte [edx+TASKDATA.state], 1 ; suspended + call change_task ; SEE: core/shed.inc + restore_ring3_context + iretd -iglobal - hexletters db '0123456789ABCDEF' - error_interrupt dd -1 -endg +IRetToUserHook: + xchg eax, [reg_eip] + sub dword[reg_esp3], 8 + mov edi, [reg_esp3] + stosd + mov [edi], ebx + restore_ring3_context +unknown_interrupt: + iretd ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= show_error_parameters: - mov eax,[CURRENT_TASK] - shl eax, 5 - DEBUGF 1, "K : Process - forced terminate PID: %x\n", [CURRENT_TASK + TASKDATA.pid + eax] - mov eax, [error_interrupt] - cmp al, 0x08 - jne @f - DEBUGF 1, "K : Double fault\n" - jmp defined_error -@@: - cmp al, 0x0a - jne @f - DEBUGF 1, "K : Invalid TSS\n" - jmp defined_error -@@: - cmp al, 0x0b - jne @f - DEBUGF 1, "K : Segment not present\n" - jmp defined_error -@@: - cmp al, 0x0c - jne @f - DEBUGF 1, "K : Stack fault\n" - jmp defined_error -@@: - cmp al, 0x0d - jne @f - DEBUGF 1, "K : General protection fault\n" - jmp defined_error -@@: - cmp al, 0x0e - jne @f - DEBUGF 1, "K : Page fault\n" - jmp defined_error -@@: - DEBUGF 1, "K : Undefined Exception\n" -defined_error: - DEBUGF 1, "K : EAX : %x EBX : %x ECX : %x\n", [esp + 0x20], [esp - 12 + 0x20], [esp - 4 + 0x20] - DEBUGF 1, "K : EDX : %x ESI : %x EDI : %x\n", [esp - 8 + 0x20], [esp - 24 + 0x20], [esp - 28 + 0x20] - DEBUGF 1, "K : EBP : %x EIP : %x ", [esp - 20 + 0x20], [esp + 4 + 0x20] - - mov eax, [esp + 8 + 0x20] - mov edi, msg_sel_app - mov ebx, [esp + 16 + 0x20] - cmp eax, app_code - je @f - mov edi, msg_sel_ker - mov ebx, [esp - 16 + 0x20] -@@: - DEBUGF 1, "ESP : %x\nK : Flags : %x CS : %x (%s)\n", ebx, [esp + 12 + 0x20], eax, edi - ret + mov edx,[TASK_BASE] ;not scratched below + DEBUGF 1, "K : Process - forced terminate PID: %x\n", [edx+TASKDATA.pid] + cmp bl, 0x08 + jb .l0 + cmp bl, 0x0e + jbe .l1 + .l0: mov bl, 0x09 + .l1: mov eax,[msg_fault_sel+ebx*4 - 0x08*4] + DEBUGF 1, "K : %s\n", eax + mov eax, [reg_cs3+4] + mov edi, msg_sel_app + mov ebx, [reg_esp3+4] + cmp eax, app_code + je @f + mov edi, msg_sel_ker + mov ebx, [reg_esp0+4] + @@: DEBUGF 1, "K : EAX : %x EBX : %x ECX : %x\n", [reg_eax+4], [reg_ebx+4], [reg_ecx+4] + DEBUGF 1, "K : EDX : %x ESI : %x EDI : %x\n", [reg_edx+4], [reg_esi+4], [reg_edi+4] + DEBUGF 1, "K : EBP : %x EIP : %x ESP : %x\n", [reg_ebp+4], [reg_eip+4], ebx + DEBUGF 1, "K : Flags : %x CS : %x (%s)\n", [reg_eflags+4], eax, edi + ret ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + restore reg_ss + restore reg_esp3 + restore reg_eflags + restore reg_cs + restore reg_eip + restore reg_eax + restore reg_ecx + restore reg_edx + restore reg_ebx + restore reg_esp0 + restore reg_ebp + restore reg_esi + restore reg_edi ; irq1 -> hid/keyboard.inc -macro irqh [num] -{ - forward +macro irqh [num] { p_irq#num : - mov edi, num - jmp irqhandler + mov edi, num + jmp irqhandler } -irqh 2,3,4,5,7,8,9,10,11 p_irq6: @@ -237,72 +252,64 @@ p_irq6: p_irq14: - save_ring3_context - mov ax, app_data ;os_data - mov ds, ax - mov es, ax - mov edi, 14 - cmp [v86_irqhooks+edi*8], 0 - jnz v86_irq2 -; mov byte [BOOT_VAR + 0x48E], 0xFF - call [irq14_func] - call ready_for_next_irq_1 - restore_ring3_context - iret + save_ring3_context + mov ax, app_data ;os_data + mov ds, ax + mov es, ax + mov edi, 14 + cmp [v86_irqhooks+edi*8], 0 + jnz v86_irq2 +; mov byte [BOOT_VAR + 0x48E], 0xFF + call [irq14_func] + call ready_for_next_irq_1 + restore_ring3_context + iret p_irq15: - save_ring3_context - mov ax, app_data ;os_data - mov ds, ax - mov es, ax - mov edi, 15 - cmp [v86_irqhooks+edi*8], 0 - jnz v86_irq2 -; mov byte [BOOT_VAR + 0x48E], 0xFF - call [irq15_func] - call ready_for_next_irq_1 - restore_ring3_context - iret + save_ring3_context + mov ax, app_data ;os_data + mov ds, ax + mov es, ax + mov edi, 15 + cmp [v86_irqhooks+edi*8], 0 + jnz v86_irq2 +; mov byte [BOOT_VAR + 0x48E], 0xFF + call [irq15_func] + call ready_for_next_irq_1 + restore_ring3_context + iret ready_for_next_irq: - mov [check_idle_semaphore],5 - mov al, 0x20 - out 0x20, al - ret + mov [check_idle_semaphore],5 + mov al, 0x20 + out 0x20, al + ret ready_for_next_irq_1: - mov [check_idle_semaphore],5 - mov al, 0x20 - out 0xa0,al - out 0x20, al - ret + mov [check_idle_semaphore],5 + mov al, 0x20 + out 0xa0,al + out 0x20, al + ret irqD: - save_ring3_context - mov ax, app_data ;os_data - mov ds, ax - mov es, ax + push eax + mov al,0 + out 0xf0,al + mov al,0x20 + out 0xa0,al + out 0x20,al + pop eax + iret - mov dx,0xf0 - mov al,0 - out dx,al - - mov dx,0xa0 - mov al,0x20 - out dx,al - mov dx,0x20 - out dx,al - - restore_ring3_context - - iret +irqh 2,3,4,5,7,8,9,10,11 irqhandler: - mov esi,edi ; 1 - shl esi,6 ; 1 + mov esi,edi ; 1 + shl esi,6 ; 1 add esi,irq00read ; 1 - shl edi,12 ; 1 + shl edi,12 ; 1 add edi,IRQ_SAVE mov ecx,16 @@ -310,37 +317,37 @@ irqhandler: dec ecx js irqover - movzx edx, word [esi] ; 2+ + movzx edx, word [esi] ; 2+ - test edx, edx ; 1 + test edx, edx ; 1 jz irqover - mov ebx, [edi] ; address of begin of buffer in edi ; + 0x0 dword - data size - mov eax, 4000 ; + 0x4 dword - data begin offset + mov ebx, [edi] ; address of begin of buffer in edi ; + 0x0 dword - data size + mov eax, 4000 ; + 0x4 dword - data begin offset cmp ebx, eax je irqfull - add ebx, [edi + 0x4] ; add data size to data begin offset - cmp ebx, eax ; if end of buffer, begin cycle again + add ebx, [edi + 0x4] ; add data size to data begin offset + cmp ebx, eax ; if end of buffer, begin cycle again jb @f xor ebx, ebx @@: add ebx, edi - movzx eax, byte[esi + 3] ; get type of data being received 1 - byte, 2 - word + movzx eax, byte[esi + 3] ; get type of data being received 1 - byte, 2 - word dec eax jz irqbyte dec eax jnz noirqword in ax,dx - cmp ebx, 3999 ; check for address odd in the end of buffer + cmp ebx, 3999 ; check for address odd in the end of buffer jne .odd mov [ebx + 0x10], ax jmp .add_size .odd: - mov [ebx + 0x10], al ; I could make mistake here :) + mov [ebx + 0x10], al ; I could make mistake here :) mov [edi + 0x10], ah .add_size: add dword [edi], 2 @@ -365,50 +372,50 @@ irqhandler: set_application_table_status: - push eax + push eax - mov eax,[CURRENT_TASK] - shl eax, 5 - add eax,CURRENT_TASK+TASKDATA.pid - mov eax,[eax] + mov eax,[CURRENT_TASK] + shl eax, 5 + add eax,CURRENT_TASK+TASKDATA.pid + mov eax,[eax] - mov [application_table_status],eax + mov [application_table_status],eax - pop eax + pop eax - ret + ret clear_application_table_status: - push eax + push eax - mov eax,[CURRENT_TASK] - shl eax, 5 - add eax,CURRENT_TASK+TASKDATA.pid - mov eax,[eax] + mov eax,[CURRENT_TASK] + shl eax, 5 + add eax,CURRENT_TASK+TASKDATA.pid + mov eax,[eax] - cmp eax,[application_table_status] - jne apptsl1 - mov [application_table_status],0 + cmp eax,[application_table_status] + jne apptsl1 + mov [application_table_status],0 apptsl1: - pop eax + pop eax - ret + ret sys_resize_app_memory: - ; eax = 1 - resize - ; ebx = new amount of memory + ; eax = 1 - resize + ; ebx = new amount of memory - cmp eax,1 - jne .no_application_mem_resize + cmp eax,1 + jne .no_application_mem_resize - stdcall new_mem_resize, ebx - mov [esp+36], eax - ret + stdcall new_mem_resize, ebx + mov [esp+36], eax + ret .no_application_mem_resize: - ret + ret sys_threads: @@ -421,9 +428,9 @@ sys_threads: jmp new_sys_threads iglobal - process_terminating db 'K : Process - terminating',13,10,0 - process_terminated db 'K : Process - done',13,10,0 - msg_obj_destroy db 'K : destroy app object',13,10,0 +; process_terminating db 'K : Process - terminating',13,10,0 +; process_terminated db 'K : Process - done',13,10,0 + msg_obj_destroy db 'K : destroy app object',13,10,0 endg ; param @@ -431,126 +438,125 @@ endg terminate: ; terminate application - .slot equ esp ;locals + .slot equ esp ;locals - push esi ;save .slot + push esi ;save .slot - shl esi, 8 - cmp [SLOT_BASE+esi+APPDATA.dir_table], 0 - jne @F - pop esi - shl esi, 5 - mov [CURRENT_TASK+esi+TASKDATA.state], 9 - ret + shl esi, 8 + cmp [SLOT_BASE+esi+APPDATA.dir_table], 0 + jne @F + pop esi + shl esi, 5 + mov [CURRENT_TASK+esi+TASKDATA.state], 9 + ret @@: - ;mov esi,process_terminating - ;call sys_msg_board_str - DEBUGF 1,"%s",process_terminating + ;mov esi,process_terminating + ;call sys_msg_board_str @@: - cli - cmp [application_table_status],0 - je term9 - sti - call change_task - jmp @b + cli + cmp [application_table_status],0 + je term9 + sti + call change_task + jmp @b term9: - call set_application_table_status + call set_application_table_status ; if the process is in V86 mode... - mov eax, [.slot] - shl eax, 8 - mov esi, [eax+SLOT_BASE+APPDATA.pl0_stack] - add esi, RING0_STACK_SIZE - cmp [eax+SLOT_BASE+APPDATA.saved_esp0], esi - jz .nov86 + mov eax, [.slot] + shl eax, 8 + mov esi, [eax+SLOT_BASE+APPDATA.pl0_stack] + add esi, RING0_STACK_SIZE + cmp [eax+SLOT_BASE+APPDATA.saved_esp0], esi + jz .nov86 ; ...it has page directory for V86 mode - mov esi, [eax+SLOT_BASE+APPDATA.saved_esp0] - mov ecx, [esi+4] - mov [eax+SLOT_BASE+APPDATA.dir_table], ecx + mov esi, [eax+SLOT_BASE+APPDATA.saved_esp0] + mov ecx, [esi+4] + mov [eax+SLOT_BASE+APPDATA.dir_table], ecx ; ...and I/O permission map for V86 mode - mov ecx, [esi+12] - mov [eax+SLOT_BASE+APPDATA.io_map], ecx - mov ecx, [esi+8] - mov [eax+SLOT_BASE+APPDATA.io_map+4], ecx + mov ecx, [esi+12] + mov [eax+SLOT_BASE+APPDATA.io_map], ecx + mov ecx, [esi+8] + mov [eax+SLOT_BASE+APPDATA.io_map+4], ecx .nov86: - mov esi, [.slot] - shl esi,8 - add esi, SLOT_BASE+APP_OBJ_OFFSET + mov esi, [.slot] + shl esi,8 + add esi, SLOT_BASE+APP_OBJ_OFFSET @@: - mov eax, [esi+APPOBJ.fd] - test eax, eax - jz @F + mov eax, [esi+APPOBJ.fd] + test eax, eax + jz @F - cmp eax, esi - je @F + cmp eax, esi + je @F - push esi - call [eax+APPOBJ.destroy] - DEBUGF 1,"%s",msg_obj_destroy - pop esi - jmp @B + push esi + call [eax+APPOBJ.destroy] + DEBUGF 1,"%s",msg_obj_destroy + pop esi + jmp @B @@: - mov eax, [.slot] - shl eax, 8 - mov eax,[SLOT_BASE+eax+APPDATA.dir_table] - stdcall destroy_app_space, eax + mov eax, [.slot] + shl eax, 8 + mov eax,[SLOT_BASE+eax+APPDATA.dir_table] + stdcall destroy_app_space, eax - mov esi, [.slot] - cmp [fpu_owner],esi ; if user fpu last -> fpu user = 1 - jne @F + mov esi, [.slot] + cmp [fpu_owner],esi ; if user fpu last -> fpu user = 1 + jne @F - mov [fpu_owner],1 - mov eax, [256+SLOT_BASE+APPDATA.fpu_state] - clts - bt [cpu_caps], CAPS_SSE - jnc .no_SSE - fxrstor [eax] - jmp @F + mov [fpu_owner],1 + mov eax, [256+SLOT_BASE+APPDATA.fpu_state] + clts + bt [cpu_caps], CAPS_SSE + jnc .no_SSE + fxrstor [eax] + jmp @F .no_SSE: - fnclex - frstor [eax] + fnclex + frstor [eax] @@: - 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 ; remove defined hotkeys - mov eax, hotkey_list + mov eax, hotkey_list .loop: - cmp [eax+8], esi - jnz .cont - mov ecx, [eax] - jecxz @f - push dword [eax+12] - pop dword [ecx+12] + cmp [eax+8], esi + jnz .cont + mov ecx, [eax] + jecxz @f + push dword [eax+12] + pop dword [ecx+12] @@: - mov ecx, [eax+12] - push dword [eax] - pop dword [ecx] - xor ecx, ecx - mov [eax], ecx - mov [eax+4], ecx - mov [eax+8], ecx - mov [eax+12], ecx + mov ecx, [eax+12] + push dword [eax] + pop dword [ecx] + xor ecx, ecx + mov [eax], ecx + mov [eax+4], ecx + mov [eax+8], ecx + mov [eax+12], ecx .cont: - add eax, 16 - cmp eax, hotkey_list+256*16 - jb .loop + add eax, 16 + cmp eax, hotkey_list+256*16 + jb .loop ; remove hotkeys in buffer - mov eax, hotkey_buffer + mov eax, hotkey_buffer .loop2: - cmp [eax], esi - jnz .cont2 - and dword [eax+4], 0 - and dword [eax], 0 + cmp [eax], esi + jnz .cont2 + and dword [eax+4], 0 + and dword [eax], 0 .cont2: - add eax, 8 - cmp eax, hotkey_buffer+120*8 - jb .loop2 + add eax, 8 + cmp eax, hotkey_buffer+120*8 + jb .loop2 - mov ecx,esi ; remove buttons + mov ecx,esi ; remove buttons bnewba2: mov edi,[BTN_ADDR] mov eax,edi @@ -559,7 +565,7 @@ term9: inc bx bnewba: dec bx - jz bnmba + jz bnmba add eax,0x10 cmp cx,[eax] jnz bnewba @@ -608,10 +614,10 @@ term9: shl edi, 5 mov eax, [SLOT_BASE+edi*8+APPDATA.debugger_slot] test eax, eax - jz .nodebug + jz .nodebug push 8 pop ecx - push dword [CURRENT_TASK+edi+TASKDATA.pid] ; PID + push dword [CURRENT_TASK+edi+TASKDATA.pid] ; PID push 2 call debugger_notify pop ecx @@ -619,86 +625,86 @@ term9: .nodebug: popad - mov ebx, [.slot] - shl ebx, 8 - push ebx - mov ebx,[SLOT_BASE+ebx+APPDATA.pl0_stack] + mov ebx, [.slot] + shl ebx, 8 + push ebx + mov ebx,[SLOT_BASE+ebx+APPDATA.pl0_stack] - stdcall kernel_free, ebx + stdcall kernel_free, ebx - pop ebx - mov ebx,[SLOT_BASE+ebx+APPDATA.cur_dir] - stdcall kernel_free, ebx + pop ebx + mov ebx,[SLOT_BASE+ebx+APPDATA.cur_dir] + stdcall kernel_free, ebx - mov edi, [.slot] - shl edi,8 - add edi,SLOT_BASE + mov edi, [.slot] + shl edi,8 + add edi,SLOT_BASE - mov eax, [edi+APPDATA.io_map] - cmp eax, (tss._io_map_0-OS_BASE+PG_MAP) - je @F - call free_page + mov eax, [edi+APPDATA.io_map] + cmp eax, (tss._io_map_0-OS_BASE+PG_MAP) + je @F + call free_page @@: - mov eax, [edi+APPDATA.io_map+4] - cmp eax, (tss._io_map_1-OS_BASE+PG_MAP) - je @F - call free_page + mov eax, [edi+APPDATA.io_map+4] + cmp eax, (tss._io_map_1-OS_BASE+PG_MAP) + je @F + call free_page @@: - mov eax, 0x20202020 - stosd - stosd - stosd - mov ecx,244/4 - xor eax, eax - rep stosd + mov eax, 0x20202020 + stosd + stosd + stosd + mov ecx,244/4 + xor eax, eax + rep stosd ; activate window - movzx eax, word [WIN_STACK + esi*2] - cmp eax, [TASK_COUNT] - jne .dont_activate - pushad + movzx eax, word [WIN_STACK + esi*2] + cmp eax, [TASK_COUNT] + jne .dont_activate + pushad .check_next_window: - dec eax - cmp eax, 1 - jbe .nothing_to_activate - lea esi, [WIN_POS+eax*2] - movzx edi, word [esi] ; edi = process - shl edi, 5 - cmp [CURRENT_TASK + edi + TASKDATA.state], byte 9 ; skip dead slots - je .check_next_window - add edi, window_data + dec eax + cmp eax, 1 + jbe .nothing_to_activate + lea esi, [WIN_POS+eax*2] + movzx edi, word [esi] ; edi = process + shl edi, 5 + cmp [CURRENT_TASK + edi + TASKDATA.state], byte 9 ; skip dead slots + je .check_next_window + add edi, window_data ; \begin{diamond}[19.09.2006] ; skip minimized windows - test [edi + WDATA.fl_wstate], WSTATE_MINIMIZED - jnz .check_next_window + test [edi + WDATA.fl_wstate], WSTATE_MINIMIZED + jnz .check_next_window ; \end{diamond} - call waredraw + call waredraw .nothing_to_activate: - popad + popad .dont_activate: - push esi ; remove hd1 & cd & flp reservation - shl esi, 5 - mov esi, [esi+CURRENT_TASK+TASKDATA.pid] - cmp [hd1_status], esi - jnz @f - call free_hd_channel - mov [hd1_status], 0 + push esi ; remove hd1 & cd & flp reservation + shl esi, 5 + mov esi, [esi+CURRENT_TASK+TASKDATA.pid] + cmp [hd1_status], esi + jnz @f + call free_hd_channel + mov [hd1_status], 0 @@: - cmp [cd_status], esi - jnz @f - call free_cd_channel - mov [cd_status], 0 + cmp [cd_status], esi + jnz @f + call free_cd_channel + mov [cd_status], 0 @@: - cmp [flp_status], esi - jnz @f - mov [flp_status], 0 + cmp [flp_status], esi + jnz @f + mov [flp_status], 0 @@: - pop esi - cmp [bgrlockpid], esi - jnz @f - and [bgrlockpid], 0 - mov [bgrlock], 0 + pop esi + cmp [bgrlockpid], esi + jnz @f + and [bgrlockpid], 0 + mov [bgrlock], 0 @@: pusha ; remove all irq reservations @@ -711,16 +717,16 @@ term9: newirqfree: cmp [edi + 4 * ebx], eax jne nofreeirq - mov [edi + 4 * ebx], edx ; remove irq reservation - mov [irq_tab + 4 * ebx], edx ; remove irq handler - mov [irq_rights + 4 * ebx], edx ; set access rights to full access + mov [edi + 4 * ebx], edx ; remove irq reservation + mov [irq_tab + 4 * ebx], edx ; remove irq handler + mov [irq_rights + 4 * ebx], edx ; set access rights to full access nofreeirq: inc ebx cmp ebx, 16 - jb newirqfree + jb newirqfree popa - pusha ; remove all port reservations + pusha ; remove all port reservations mov edx,esi shl edx, 5 add edx,CURRENT_TASK @@ -731,7 +737,7 @@ term9: mov esi,[RESERVED_PORTS] cmp esi,0 - je rmpr9 + je rmpr9 rmpr3: @@ -740,7 +746,7 @@ term9: add edi,RESERVED_PORTS cmp edx,[edi] - je rmpr4 + je rmpr4 dec esi jnz rmpr3 @@ -765,7 +771,7 @@ term9: rmpr9: popa - mov edi,esi ; do not run this process slot + mov edi,esi ; do not run this process slot shl edi, 5 mov [edi+CURRENT_TASK + TASKDATA.state],byte 9 ; debugger test - terminate all debuggees @@ -773,7 +779,7 @@ term9: mov ecx, SLOT_BASE+2*0x100+APPDATA.debugger_slot .xd0: cmp eax, [TASK_COUNT] - ja .xd1 + ja .xd1 cmp dword [ecx], esi jnz @f and dword [ecx], 0 @@ -805,24 +811,23 @@ term9: mov [application_table_status],0 ;mov esi,process_terminated ;call sys_msg_board_str - DEBUGF 1,"%s",process_terminated add esp, 4 ret restore .slot iglobal - boot_sched_1 db 'Building gdt tss pointer',0 - boot_sched_2 db 'Building IDT table',0 + boot_sched_1 db 'Building gdt tss pointer',0 + boot_sched_2 db 'Building IDT table',0 endg build_scheduler: - mov esi,boot_sched_1 - call boot_log + mov esi,boot_sched_1 + call boot_log ; call build_process_gdt_tss_pointer ; mov esi,boot_sched_2 ; call boot_log - ret + ret diff --git a/kernel/branches/net/core/syscall.inc b/kernel/branches/net/core/syscall.inc index bd12d4fb1a..4b1aae6316 100644 --- a/kernel/branches/net/core/syscall.inc +++ b/kernel/branches/net/core/syscall.inc @@ -10,33 +10,17 @@ $Revision: 940 $ ; Old style system call converter align 16 cross_order: - ; load all registers in crossed order - mov eax, ebx - mov ebx, ecx - mov ecx, edx - mov edx, esi - mov esi, edi - mov edi, [esp+28 + 4] - and edi,0xff - call dword [servetable+edi*4] - ret + ; load all registers in crossed order + mov eax, ebx + mov ebx, ecx + mov ecx, edx + mov edx, esi + mov esi, edi + movzx edi, byte[esp+28 + 4] + call dword [servetable+edi*4] + ret -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; ;; -;; SYSTEM CALL ENTRY ;; -;; ;; -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - - -align 16 -i40: - pushad - cld - movzx eax, al - call dword [servetable2 + eax * 4] - popad - iretd ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; ;; SYSENTER ENTRY ;; @@ -45,28 +29,43 @@ i40: align 32 sysenter_entry: - ; Настраиваем стек - mov esp, [ss:tss._esp0] - sti - push ebp ; save app esp + 4 - mov ebp, [ebp] ; ebp - original ebp - ;------------------ - pushad - cld + ; Настраиваем стек + mov esp, [ss:tss._esp0] + sti + push ebp ; save app esp + 4 + mov ebp, [ebp] ; ebp - original ebp + ;------------------ + pushad + cld - movzx eax, al - call dword [servetable2 + eax * 4] + movzx eax, al + call dword [servetable2 + eax * 4] - popad - ;------------------ - xchg ecx, [ss:esp] ; в вершин стека - app ecx, ecx - app esp + 4 - sub ecx, 4 - xchg edx, [ecx] ; edx - return point, & save original edx - push edx - mov edx, [ss:esp + 4] - mov [ecx + 4], edx ; save original ecx - pop edx - sysexit + popad + ;------------------ + xchg ecx, [ss:esp] ; в вершин стека - app ecx, ecx - app esp + 4 + sub ecx, 4 + xchg edx, [ecx] ; edx - return point, & save original edx + push edx + mov edx, [ss:esp + 4] + mov [ecx + 4], edx ; save original ecx + pop edx + sysexit + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; ;; +;; SYSTEM CALL ENTRY ;; +;; ;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +align 16 +i40: + pushad + cld + movzx eax, al + call dword [servetable2 + eax * 4] + popad + iretd ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; @@ -76,25 +75,26 @@ sysenter_entry: align 32 syscall_entry: ; cli syscall clear IF - xchg esp, [ss:tss._esp0] - push ecx - lea ecx, [esp+4] - xchg ecx, [ss:tss._esp0] - sti - push ecx - mov ecx, [ecx] - ;------------------ - pushad - cld + xchg esp, [ss:tss._esp0] + push ecx + lea ecx, [esp+4] + xchg ecx, [ss:tss._esp0] + sti + push ecx + mov ecx, [ecx] + ;------------------ + pushad + cld - movzx eax, al - call dword [servetable2 + eax * 4] + movzx eax, al + call dword [servetable2 + eax * 4] + + popad + ;------------------ + mov ecx, [ss:esp+4] + pop esp + sysret - popad - ;------------------ - mov ecx, [ss:esp+4] - pop esp - sysret iglobal ;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; SYSTEM FUNCTIONS TABLE ;; @@ -133,7 +133,7 @@ iglobal dd 0 dd 0 ; dd 0 - dd sys_current_directory ; 30-Get/SetCurrentDirectory + dd sys_current_directory ; 30-Get/SetCurrentDirectory dd 0 dd 0 dd 0 @@ -153,7 +153,7 @@ iglobal 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 random_shaped_window ; 50-Window shape & scale dd syscall_threads ; 51-Threads dd 0 dd 0 @@ -167,7 +167,7 @@ iglobal 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 sys_resize_app_memory ; 64-Resize application memory usage dd syscall_putimage_palette; 65-PutImagePalette dd sys_process_def ; 66-Process definitions - keyboard dd sys_window_move ; 67-Window move or resize @@ -175,7 +175,6 @@ iglobal 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_sendwindowmsg ; 72-Send window message ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -198,9 +197,9 @@ iglobal dd sys_getevent ; 11-CheckForEvent dd sys_redrawstat ; 12-BeginDraw and EndDraw dd syscall_drawrect ; 13-DrawRect - dd syscall_getscreensize ; 14-GetScreenSize + dd syscall_getscreensize ; 14-GetScreenSize dd sys_background ; 15-bgr - dd sys_cachetodiskette ; 16-FlushFloppyCache + dd sys_cachetodiskette ; 16-FlushFloppyCache dd sys_getbutton ; 17-GetButton dd sys_system ; 18-System Services dd paleholder ; 19-reserved @@ -225,7 +224,7 @@ iglobal dd syscall_drawline ; 38-DrawLine dd cross_order ; 39-GetBackgroundSize,ReadBgrData,. dd set_app_param ; 40-WantEvents - dd syscall_getirqowner ; 41-GetIrqOwner + dd syscall_getirqowner ; 41-GetIrqOwner dd get_irq_data ; 42-ReadIrqData dd cross_order ; 43-SendDeviceData dd sys_programirq ; 44-ProgramIrqs @@ -256,7 +255,7 @@ iglobal dd cross_order ; 69-Debug dd cross_order ; 70-Common file system interface, version 2 dd cross_order ; 71-Window settings - dd cross_order ; 72-Send window message + dd sys_sendwindowmsg ; 72-Send window message dd sys_network ; 73-Network stack dd sys_socket ; 74-Sockets dd sys_protocols ; 75-Protocols diff --git a/kernel/branches/net/core/taskman.inc b/kernel/branches/net/core/taskman.inc index 4cd7132f2c..3339cacea3 100644 --- a/kernel/branches/net/core/taskman.inc +++ b/kernel/branches/net/core/taskman.inc @@ -32,11 +32,11 @@ struc APP_HEADER_01 struc APP_PARAMS -{ .app_cmdline ;0x00 - .app_path ;0x04 - .app_eip ;0x08 - .app_esp ;0x0C - .app_mem ;0x10 +{ .app_cmdline ;0x00 + .app_path ;0x04 + .app_eip ;0x08 + .app_esp ;0x0C + .app_mem ;0x10 } macro _clear_ op @@ -47,9 +47,9 @@ macro _clear_ op } fs_execute_from_sysdir: - xor ebx, ebx - xor edx, edx - mov esi, sysdir_path + xor ebx, ebx + xor edx, edx + mov esi, sysdir_path align 4 proc fs_execute @@ -61,250 +61,249 @@ proc fs_execute ; ebp - full filename ; [esp+4] = procedure DoRead, [esp+8] = filesize & [esp+12]... - arguments for it - locals - cmdline rd 64 ;256/4 - filename rd 256 ;1024/4 - flags dd ? + locals + cmdline rd 64 ;256/4 + filename rd 256 ;1024/4 + flags dd ? - save_cr3 dd ? - slot dd ? - slot_base dd ? - file_base dd ? - file_size dd ? - ;app header data - hdr_cmdline dd ? ;0x00 - hdr_path dd ? ;0x04 - hdr_eip dd ? ;0x08 - hdr_esp dd ? ;0x0C - hdr_mem dd ? ;0x10 - hdr_i_end dd ? ;0x14 - endl + save_cr3 dd ? + slot dd ? + slot_base dd ? + file_base dd ? + file_size dd ? + ;app header data + hdr_cmdline dd ? ;0x00 + hdr_path dd ? ;0x04 + hdr_eip dd ? ;0x08 + hdr_esp dd ? ;0x0C + hdr_mem dd ? ;0x10 + hdr_i_end dd ? ;0x14 + endl - pushad + pushad - mov [flags], edx + mov [flags], edx ; [ebp] pointer to filename - lea edi, [filename] - lea ecx, [edi+1024] - mov al, '/' - stosb + lea edi, [filename] + lea ecx, [edi+1024] + mov al, '/' + stosb @@: - cmp edi, ecx - jae .bigfilename - lodsb - stosb - test al, al - jnz @b - mov esi, [ebp] - test esi, esi - jz .namecopied - mov byte [edi-1], '/' + cmp edi, ecx + jae .bigfilename + lodsb + stosb + test al, al + jnz @b + mov esi, [ebp] + test esi, esi + jz .namecopied + mov byte [edi-1], '/' @@: - cmp edi, ecx - jae .bigfilename - lodsb - stosb - test al, al - jnz @b - jmp .namecopied + cmp edi, ecx + jae .bigfilename + lodsb + stosb + test al, al + jnz @b + jmp .namecopied .bigfilename: - popad - mov eax, -ERROR_FILE_NOT_FOUND - ret + popad + mov eax, -ERROR_FILE_NOT_FOUND + ret .namecopied: - mov [cmdline], ebx - test ebx, ebx - jz @F + mov [cmdline], ebx + test ebx, ebx + jz @F - lea eax, [cmdline] - mov dword [eax+252], 0 - stdcall strncpy, eax, ebx, 255 + lea eax, [cmdline] + mov dword [eax+252], 0 + stdcall strncpy, eax, ebx, 255 @@: - lea eax, [filename] - stdcall load_file, eax - mov ecx, -ERROR_FILE_NOT_FOUND - test eax, eax - jz .err_file + lea eax, [filename] + stdcall load_file, eax + mov ecx, -ERROR_FILE_NOT_FOUND + test eax, eax + jz .err_file - mov [file_base], eax - mov [file_size], ebx + mov [file_base], eax + mov [file_size], ebx - lea ebx, [hdr_cmdline] - call test_app_header - mov ecx, -0x1F - test eax, eax - jz .err_hdr + lea ebx, [hdr_cmdline] + call test_app_header + mov ecx, -0x1F + test eax, eax + jz .err_hdr - ;mov esi, new_process_loading - ;call sys_msg_board_str ; write message to message board - DEBUGF 1,"%s",new_process_loading + ;mov esi, new_process_loading + ;call sys_msg_board_str ; write message to message board .wait_lock: - cmp [application_table_status],0 - je .get_lock - call change_task - jmp .wait_lock + cmp [application_table_status],0 + je .get_lock + call change_task + jmp .wait_lock .get_lock: - mov eax, 1 - xchg eax, [application_table_status] - cmp eax, 0 - jne .wait_lock + mov eax, 1 + xchg eax, [application_table_status] + cmp eax, 0 + jne .wait_lock - call set_application_table_status + call set_application_table_status - call get_new_process_place - test eax, eax - mov ecx, -0x20 ; too many processes - jz .err + call get_new_process_place + test eax, eax + mov ecx, -0x20 ; too many processes + jz .err - mov [slot], eax - shl eax, 8 - add eax, SLOT_BASE - mov [slot_base], eax - mov edi, eax - _clear_ 256 ;clean extended information about process + mov [slot], eax + shl eax, 8 + add eax, SLOT_BASE + mov [slot_base], eax + mov edi, eax + _clear_ 256 ;clean extended information about process ; write application name - lea eax, [filename] - stdcall strrchr, eax, '/' ; now eax points to name without path + lea eax, [filename] + stdcall strrchr, eax, '/' ; now eax points to name without path - lea esi, [eax+1] - test eax, eax - jnz @F - lea esi, [filename] + lea esi, [eax+1] + test eax, eax + jnz @F + lea esi, [filename] @@: - mov ecx, 8 ; 8 chars for name - mov edi, [slot_base] + mov ecx, 8 ; 8 chars for name + mov edi, [slot_base] .copy_process_name_loop: - lodsb - cmp al, '.' - jz .copy_process_name_done - test al, al - jz .copy_process_name_done - stosb - loop .copy_process_name_loop + lodsb + cmp al, '.' + jz .copy_process_name_done + test al, al + jz .copy_process_name_done + stosb + loop .copy_process_name_loop .copy_process_name_done: - mov ebx, cr3 - mov [save_cr3], ebx + mov ebx, cr3 + mov [save_cr3], ebx - stdcall create_app_space,[hdr_mem],[file_base],[file_size] - mov ecx, -30 ; no memory - test eax, eax - jz .failed + stdcall create_app_space,[hdr_mem],[file_base],[file_size] + mov ecx, -30 ; no memory + test eax, eax + jz .failed - mov ebx,[slot_base] - mov [ebx+APPDATA.dir_table],eax - mov eax,[hdr_mem] - mov [ebx+APPDATA.mem_size],eax + mov ebx,[slot_base] + mov [ebx+APPDATA.dir_table],eax + mov eax,[hdr_mem] + mov [ebx+APPDATA.mem_size],eax if GREEDY_KERNEL else - mov ecx, [hdr_mem] - mov edi, [file_size] - add edi, 4095 - and edi, not 4095 - sub ecx, edi - jna @F + mov ecx, [hdr_mem] + mov edi, [file_size] + add edi, 4095 + and edi, not 4095 + sub ecx, edi + jna @F - xor eax, eax + xor eax, eax cld - rep stosb + rep stosb @@: end if ; release only virtual space, not phisical memory - stdcall free_kernel_space, [file_base] - lea eax, [hdr_cmdline] - lea ebx, [cmdline] - lea ecx, [filename] - stdcall set_app_params ,[slot],eax,ebx,ecx,[flags] + stdcall free_kernel_space, [file_base] + lea eax, [hdr_cmdline] + lea ebx, [cmdline] + lea ecx, [filename] + stdcall set_app_params ,[slot],eax,ebx,ecx,[flags] - mov eax, [save_cr3] - call set_cr3 + mov eax, [save_cr3] + call set_cr3 - xor ebx, ebx - mov [application_table_status],ebx ;unlock application_table_status mutex - mov eax,[process_number] ;set result - ret + xor ebx, ebx + mov [application_table_status],ebx ;unlock application_table_status mutex + mov eax,[process_number] ;set result + ret .failed: - mov eax, [save_cr3] - call set_cr3 + mov eax, [save_cr3] + call set_cr3 .err: .err_hdr: - stdcall kernel_free,[file_base] + stdcall kernel_free,[file_base] .err_file: - xor eax, eax - mov [application_table_status],eax - mov eax, ecx - ret + xor eax, eax + mov [application_table_status],eax + mov eax, ecx + ret endp align 4 test_app_header: - virtual at eax - APP_HEADER_00 APP_HEADER_00 - end virtual - virtual at eax - APP_HEADER_01 APP_HEADER_01 - end virtual + virtual at eax + APP_HEADER_00 APP_HEADER_00 + end virtual + virtual at eax + APP_HEADER_01 APP_HEADER_01 + end virtual - cmp dword [eax], 'MENU' - jne .fail - cmp word [eax+4],'ET' - jne .fail + cmp dword [eax], 'MENU' + jne .fail + cmp word [eax+4],'ET' + jne .fail - cmp [eax+6], word '00' - jne .check_01_header + cmp [eax+6], word '00' + jne .check_01_header - mov ecx,[APP_HEADER_00.start] - mov [ebx+0x08], ecx ;app_eip - mov edx,[APP_HEADER_00.mem_size] - mov [ebx+0x10], edx ;app_mem - shr edx,1 - sub edx,0x10 - 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 edx, [APP_HEADER_00.i_end] - mov [ebx+0x14], edx - ret + mov ecx,[APP_HEADER_00.start] + mov [ebx+0x08], ecx ;app_eip + mov edx,[APP_HEADER_00.mem_size] + mov [ebx+0x10], edx ;app_mem + shr edx,1 + sub edx,0x10 + 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 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' + jne .fail - mov ecx,[APP_HEADER_01.start] - mov [ebx+0x08], ecx ;app_eip - mov edx,[APP_HEADER_01.mem_size] + mov ecx,[APP_HEADER_01.start] + mov [ebx+0x08], ecx ;app_eip + mov edx,[APP_HEADER_01.mem_size] ; \begin{diamond}[20.08.2006] ; sanity check (functions 19,58 load app_i_end bytes and that must ; fit in allocated memory to prevent kernel faults) - cmp edx,[APP_HEADER_01.i_end] - jb .fail + cmp edx,[APP_HEADER_01.i_end] + jb .fail ; \end{diamond}[20.08.2006] - mov [ebx+0x10], edx ;app_mem - mov ecx,[APP_HEADER_01.stack_top] - mov [ebx+0x0C], ecx ;app_esp - mov edx,[APP_HEADER_01.i_param] - mov [ebx], edx ;app_cmdline - mov ecx,[APP_HEADER_01.i_icon] - mov [ebx+4], ecx ;app_path - mov edx, [APP_HEADER_01.i_end] - mov [ebx+0x14], edx - ret + mov [ebx+0x10], edx ;app_mem + mov ecx,[APP_HEADER_01.stack_top] + mov [ebx+0x0C], ecx ;app_esp + mov edx,[APP_HEADER_01.i_param] + mov [ebx], edx ;app_cmdline + mov ecx,[APP_HEADER_01.i_icon] + mov [ebx+4], ecx ;app_path + mov edx, [APP_HEADER_01.i_end] + mov [ebx+0x14], edx + ret .fail: - xor eax, eax - ret + xor eax, eax + ret align 4 proc get_new_process_place @@ -315,266 +314,266 @@ proc get_new_process_place ; 0 - failed. ;This function find least empty slot. ;It doesn't increase [TASK_COUNT]! - mov eax,CURRENT_TASK - mov ebx,[TASK_COUNT] - inc ebx - shl ebx,5 - add ebx,eax ;ebx - address of process information for (last+1) slot + mov eax,CURRENT_TASK + mov ebx,[TASK_COUNT] + inc ebx + shl ebx,5 + add ebx,eax ;ebx - address of process information for (last+1) slot .newprocessplace: ;eax = address of process information for current slot - cmp eax,ebx - jz .endnewprocessplace ;empty slot after high boundary - add eax,0x20 - cmp word [eax+0xa],9 ;check process state, 9 means that process slot is empty - jnz .newprocessplace + cmp eax,ebx + jz .endnewprocessplace ;empty slot after high boundary + add eax,0x20 + cmp word [eax+0xa],9 ;check process state, 9 means that process slot is empty + jnz .newprocessplace .endnewprocessplace: - mov ebx,eax - sub eax,CURRENT_TASK - shr eax,5 ;calculate slot index - cmp eax,256 - jge .failed ;it should be <256 - mov word [ebx+0xa],9 ;set process state to 9 (for slot after hight boundary) - ret + mov ebx,eax + sub eax,CURRENT_TASK + shr eax,5 ;calculate slot index + cmp eax,256 + jge .failed ;it should be <256 + mov word [ebx+0xa],9 ;set process state to 9 (for slot after hight boundary) + ret .failed: - xor eax,eax - ret + xor eax,eax + ret endp align 4 proc create_app_space stdcall, app_size:dword,img_base:dword,img_size:dword - locals - app_pages dd ? - img_pages dd ? - dir_addr dd ? - app_tabs dd ? - endl + locals + app_pages dd ? + img_pages dd ? + dir_addr dd ? + app_tabs dd ? + endl - mov ebx, pg_data.pg_mutex - call wait_mutex ;ebx + mov ebx, pg_data.pg_mutex + call wait_mutex ;ebx - xor eax, eax - mov [dir_addr], eax + xor eax, eax + mov [dir_addr], eax - mov eax, [app_size] - add eax, 4095 - and eax, NOT(4095) - mov [app_size], eax - mov ebx, eax - shr eax, 12 - mov [app_pages], eax + mov eax, [app_size] + add eax, 4095 + and eax, NOT(4095) + mov [app_size], eax + mov ebx, eax + shr eax, 12 + mov [app_pages], eax - add ebx, 0x3FFFFF - and ebx, NOT(0x3FFFFF) - shr ebx, 22 - mov [app_tabs], ebx + add ebx, 0x3FFFFF + and ebx, NOT(0x3FFFFF) + shr ebx, 22 + mov [app_tabs], ebx - mov ecx, [img_size] - add ecx, 4095 - and ecx, NOT(4095) + mov ecx, [img_size] + add ecx, 4095 + and ecx, NOT(4095) - mov [img_size], ecx - shr ecx, 12 - mov [img_pages], ecx + mov [img_size], ecx + shr ecx, 12 + mov [img_pages], ecx if GREEDY_KERNEL - lea eax, [ecx+ebx+2] ;only image size + lea eax, [ecx+ebx+2] ;only image size else - lea eax, [eax+ebx+2] ;all requested memory + lea eax, [eax+ebx+2] ;all requested memory end if - cmp eax, [pg_data.pages_free] - ja .fail + cmp eax, [pg_data.pages_free] + ja .fail - call alloc_page - test eax, eax - jz .fail - mov [dir_addr], eax - stdcall map_page,[tmp_task_pdir],eax,dword PG_SW + call alloc_page + test eax, eax + jz .fail + mov [dir_addr], eax + stdcall map_page,[tmp_task_pdir],eax,dword PG_SW - mov edi, [tmp_task_pdir] - mov ecx, (OS_BASE shr 20)/4 - xor eax, eax - cld - rep stosd + mov edi, [tmp_task_pdir] + mov ecx, (OS_BASE shr 20)/4 + xor eax, eax + cld + rep stosd - mov ecx, (OS_BASE shr 20)/4 - mov esi, sys_pgdir+(OS_BASE shr 20) - rep movsd + mov ecx, (OS_BASE shr 20)/4 + mov esi, sys_pgdir+(OS_BASE shr 20) + rep movsd - mov eax, [dir_addr] - or eax, PG_SW - mov [edi-4096+(page_tabs shr 20)], eax + mov eax, [dir_addr] + or eax, PG_SW + mov [edi-4096+(page_tabs shr 20)], eax - and eax, -4096 - call set_cr3 + and eax, -4096 + call set_cr3 - mov edx, [app_tabs] - mov edi, new_app_base + mov edx, [app_tabs] + mov edi, new_app_base @@: - call alloc_page - test eax, eax - jz .fail + call alloc_page + test eax, eax + jz .fail - stdcall map_page_table, edi, eax - add edi, 0x00400000 - dec edx - jnz @B + stdcall map_page_table, edi, eax + add edi, 0x00400000 + dec edx + jnz @B - mov edi, new_app_base - shr edi, 10 - add edi, page_tabs + mov edi, new_app_base + shr edi, 10 + add edi, page_tabs - mov ecx, [app_tabs] - shl ecx, 10 - xor eax, eax - rep stosd + mov ecx, [app_tabs] + shl ecx, 10 + xor eax, eax + rep stosd - mov ecx, [img_pages] - mov ebx, PG_UW - mov edx, new_app_base - mov esi, [img_base] - mov edi, new_app_base - shr esi, 10 - shr edi, 10 - add esi, page_tabs - add edi, page_tabs + mov ecx, [img_pages] + mov ebx, PG_UW + mov edx, new_app_base + mov esi, [img_base] + mov edi, new_app_base + shr esi, 10 + shr edi, 10 + add esi, page_tabs + add edi, page_tabs .remap: - lodsd - or eax, ebx ; force user level r/w access - stosd - add edx, 0x1000 - dec [app_pages] - dec ecx - jnz .remap + lodsd + or eax, ebx ; force user level r/w access + stosd + add edx, 0x1000 + dec [app_pages] + dec ecx + jnz .remap - mov ecx, [app_pages] - test ecx, ecx - jz .done + mov ecx, [app_pages] + test ecx, ecx + jz .done if GREEDY_KERNEL - mov eax, 0x02 + mov eax, 0x02 rep stosd else .alloc: - call alloc_page - test eax, eax - jz .fail + call alloc_page + test eax, eax + jz .fail - stdcall map_page,edx,eax,dword PG_UW - add edx, 0x1000 - dec [app_pages] - jnz .alloc + stdcall map_page,edx,eax,dword PG_UW + add edx, 0x1000 + dec [app_pages] + jnz .alloc end if .done: - stdcall map_page,[tmp_task_pdir],dword 0,dword PG_UNMAP + stdcall map_page,[tmp_task_pdir],dword 0,dword PG_UNMAP - dec [pg_data.pg_mutex] - mov eax, [dir_addr] - ret + dec [pg_data.pg_mutex] + mov eax, [dir_addr] + ret .fail: - dec [pg_data.pg_mutex] - cmp [dir_addr], 0 - je @f - stdcall destroy_app_space, [dir_addr] + dec [pg_data.pg_mutex] + cmp [dir_addr], 0 + je @f + stdcall destroy_app_space, [dir_addr] @@: - xor eax, eax - ret + xor eax, eax + ret endp align 4 set_cr3: - mov ebx, [current_slot] - mov [ebx+APPDATA.dir_table], eax - mov cr3, eax - ret + mov ebx, [current_slot] + mov [ebx+APPDATA.dir_table], eax + mov cr3, eax + ret align 4 proc destroy_page_table stdcall, pg_tab:dword - push esi + push esi - mov esi, [pg_tab] - mov ecx, 1024 + mov esi, [pg_tab] + mov ecx, 1024 .free: - mov eax, [esi] - test eax, 1 - jz .next + mov eax, [esi] + test eax, 1 + jz .next test eax, 1 shl 9 jnz .next ;skip shared pages - call free_page + call free_page .next: - add esi, 4 - dec ecx - jnz .free - pop esi - ret + add esi, 4 + dec ecx + jnz .free + pop esi + ret endp align 4 proc destroy_app_space stdcall, pg_dir:dword - mov ebx, pg_data.pg_mutex - call wait_mutex ;ebx + mov ebx, pg_data.pg_mutex + call wait_mutex ;ebx - xor edx,edx - mov eax,0x2 - mov ebx, [pg_dir] + xor edx,edx + mov eax,0x2 + mov ebx, [pg_dir] .loop: ;eax = current slot of process - mov ecx,eax - shl ecx,5 - 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 - jnz @f - inc edx ;thread found + mov ecx,eax + shl ecx,5 + 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 + jnz @f + inc edx ;thread found @@: - inc eax - cmp eax,[TASK_COUNT] ;exit loop if we look through all processes - jle .loop + inc eax + cmp eax,[TASK_COUNT] ;exit loop if we look through all processes + jle .loop ;edx = number of threads ;our process is zombi so it isn't counted - cmp edx,1 - jg .exit + cmp edx,1 + jg .exit ;if there isn't threads then clear memory. - mov eax, [pg_dir] - and eax, not 0xFFF - stdcall map_page,[tmp_task_pdir],eax,dword PG_SW - mov esi, [tmp_task_pdir] - mov edi, (OS_BASE shr 20)/4 + mov eax, [pg_dir] + and eax, not 0xFFF + stdcall map_page,[tmp_task_pdir],eax,dword PG_SW + mov esi, [tmp_task_pdir] + mov edi, (OS_BASE shr 20)/4 .destroy: - mov eax, [esi] - test eax, 1 - jz .next - and eax, not 0xFFF - stdcall map_page,[tmp_task_ptab],eax,dword PG_SW - stdcall destroy_page_table, [tmp_task_ptab] - mov eax, [esi] - call free_page + mov eax, [esi] + test eax, 1 + jz .next + and eax, not 0xFFF + stdcall map_page,[tmp_task_ptab],eax,dword PG_SW + stdcall destroy_page_table, [tmp_task_ptab] + mov eax, [esi] + call free_page .next: - add esi, 4 - dec edi - jnz .destroy + add esi, 4 + dec edi + jnz .destroy - mov eax, [pg_dir] - call free_page + 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 - dec [pg_data.pg_mutex] - ret + stdcall map_page,[tmp_task_ptab],dword 0,dword PG_UNMAP + stdcall map_page,[tmp_task_pdir],dword 0,dword PG_UNMAP + dec [pg_data.pg_mutex] + ret endp align 4 get_pid: - mov eax, [TASK_BASE] + mov eax, [TASK_BASE] mov eax, [eax+TASKDATA.pid] - ret + ret pid_to_slot: ;Input: @@ -592,9 +591,9 @@ pid_to_slot: ;ecx=offset of current process info entry ;ebx=maximum permitted offset cmp byte [CURRENT_TASK+ecx+0xa],9 - jz .endloop ;skip empty slots + jz .endloop ;skip empty slots cmp [CURRENT_TASK+ecx+0x4],eax ;check PID - jz .pid_found + jz .pid_found .endloop: add ecx,32 cmp ecx,ebx @@ -607,7 +606,7 @@ pid_to_slot: .pid_found: shr ecx,5 - mov eax,ecx ;convert offset to index of slot + mov eax,ecx ;convert offset to index of slot pop ecx pop ebx ret @@ -704,61 +703,61 @@ proc read_process_memory ; edx - start address in other process ;Output: ; eax - number of bytes read. - locals - slot dd ? - buff dd ? - r_count dd ? - offset dd ? - tmp_r_cnt dd ? - endl + locals + slot dd ? + buff dd ? + r_count dd ? + offset dd ? + tmp_r_cnt dd ? + endl - mov [slot], eax - mov [buff], ebx - and [r_count], 0 - mov [tmp_r_cnt], ecx - mov [offset], edx + mov [slot], eax + mov [buff], ebx + and [r_count], 0 + mov [tmp_r_cnt], ecx + mov [offset], edx - pushad + pushad .read_mem: - mov edx, [offset] - mov ebx, [tmp_r_cnt] + mov edx, [offset] + mov ebx, [tmp_r_cnt] - mov ecx, 0x400000 - and edx, 0x3FFFFF - sub ecx, edx - cmp ecx, ebx - jbe @f - mov ecx, ebx + mov ecx, 0x400000 + and edx, 0x3FFFFF + sub ecx, edx + cmp ecx, ebx + jbe @f + mov ecx, ebx @@: - cmp ecx, 0x8000 - jna @F - mov ecx, 0x8000 + cmp ecx, 0x8000 + jna @F + mov ecx, 0x8000 @@: - mov eax, [slot] - shl eax,8 - mov ebx, [offset] + 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 - pop ecx + push ecx + stdcall map_memEx, [proc_mem_map],\ + [SLOT_BASE+eax+0xB8],\ + ebx, ecx + pop ecx - mov esi, [offset] - and esi, 0xfff - add esi, [proc_mem_map] - mov edi, [buff] - mov edx, ecx - rep movsb - add [r_count], edx + mov esi, [offset] + and esi, 0xfff + add esi, [proc_mem_map] + mov edi, [buff] + mov edx, ecx + rep movsb + add [r_count], edx - add [offset], edx - sub [tmp_r_cnt], edx - jnz .read_mem + add [offset], edx + sub [tmp_r_cnt], edx + jnz .read_mem - popad - mov eax, [r_count] - ret + popad + mov eax, [r_count] + ret endp align 4 @@ -771,149 +770,147 @@ proc write_process_memory ;Output: ; eax - number of bytes written - locals - slot dd ? - buff dd ? - w_count dd ? - offset dd ? - tmp_w_cnt dd ? - endl + locals + slot dd ? + buff dd ? + w_count dd ? + offset dd ? + tmp_w_cnt dd ? + endl - mov [slot], eax - mov [buff], ebx - and [w_count], 0 - mov [tmp_w_cnt], ecx - mov [offset], edx + mov [slot], eax + mov [buff], ebx + and [w_count], 0 + mov [tmp_w_cnt], ecx + mov [offset], edx - pushad + pushad .read_mem: - mov edx, [offset] - mov ebx, [tmp_w_cnt] + mov edx, [offset] + mov ebx, [tmp_w_cnt] - mov ecx, 0x400000 - and edx, 0x3FFFFF - sub ecx, edx - cmp ecx, ebx - jbe @f - mov ecx, ebx + mov ecx, 0x400000 + and edx, 0x3FFFFF + sub ecx, edx + cmp ecx, ebx + jbe @f + mov ecx, ebx @@: - cmp ecx, 0x8000 - jna @F - mov ecx, 0x8000 + cmp ecx, 0x8000 + jna @F + mov ecx, 0x8000 @@: - mov eax, [slot] - shl eax,8 - mov ebx, [offset] + 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 - pop ecx + push ecx + stdcall map_memEx, [proc_mem_map],\ + [SLOT_BASE+eax+0xB8],\ + ebx, ecx + pop ecx - mov edi, [offset] - and edi, 0xfff - add edi, [proc_mem_map] - mov esi, [buff] - mov edx, ecx - rep movsb + mov edi, [offset] + and edi, 0xfff + add edi, [proc_mem_map] + mov esi, [buff] + mov edx, ecx + rep movsb - add [w_count], edx - add [offset], edx - sub [tmp_w_cnt], edx - jnz .read_mem + add [w_count], edx + add [offset], edx + sub [tmp_w_cnt], edx + jnz .read_mem - popad - mov eax, [w_count] - ret + popad + mov eax, [w_count] + ret endp align 4 proc new_sys_threads - locals - slot dd ? - app_cmdline dd ? ;0x00 - app_path dd ? ;0x04 - app_eip dd ? ;0x08 - app_esp dd ? ;0x0C - app_mem dd ? ;0x10 - endl + locals + slot dd ? + app_cmdline dd ? ;0x00 + app_path dd ? ;0x04 + app_eip dd ? ;0x08 + app_esp dd ? ;0x0C + app_mem dd ? ;0x10 + endl - cmp eax,1 - jne .failed ;other subfunctions + cmp eax,1 + jne .failed ;other subfunctions - xor eax,eax - mov [app_cmdline], eax - mov [app_path], eax - mov [app_eip], ebx - mov [app_esp], ecx + xor eax,eax + mov [app_cmdline], eax + mov [app_path], eax + mov [app_eip], ebx + mov [app_esp], ecx - ;mov esi,new_process_loading - ;call sys_msg_board_str - DEBUGF 1,"%s",new_process_loading + ;mov esi,new_process_loading + ;call sys_msg_board_str .wait_lock: - cmp [application_table_status],0 - je .get_lock - call change_task - jmp .wait_lock + cmp [application_table_status],0 + je .get_lock + call change_task + jmp .wait_lock .get_lock: - mov eax, 1 - xchg eax, [application_table_status] - cmp eax, 0 - jne .wait_lock + mov eax, 1 + xchg eax, [application_table_status] + cmp eax, 0 + jne .wait_lock - call set_application_table_status + call set_application_table_status - call get_new_process_place - test eax, eax - jz .failed + call get_new_process_place + test eax, eax + jz .failed - mov [slot], eax + mov [slot], eax - mov esi,[current_slot] - mov ebx,esi ;ebx=esi - pointer to extended information about current thread + mov esi,[current_slot] + mov ebx,esi ;ebx=esi - pointer to extended information about current thread - mov edi, eax - shl edi,8 - add edi,SLOT_BASE - mov edx,edi ;edx=edi - pointer to extended infomation about new thread - mov ecx,256/4 - xor eax, eax - cld - rep stosd ;clean extended information about new thread - mov esi,ebx - mov edi,edx - mov ecx,11 - rep movsb ;copy process name + mov edi, eax + shl edi,8 + add edi,SLOT_BASE + mov edx,edi ;edx=edi - pointer to extended infomation about new thread + mov ecx,256/4 + xor eax, eax + cld + rep stosd ;clean extended information about new thread + mov esi,ebx + mov edi,edx + mov ecx,11 + rep movsb ;copy process name - mov eax,[ebx+APPDATA.heap_base] - mov [edx+APPDATA.heap_base], eax + mov eax,[ebx+APPDATA.heap_base] + mov [edx+APPDATA.heap_base], eax - mov ecx,[ebx+APPDATA.heap_top] - mov [edx+APPDATA.heap_top], ecx + mov ecx,[ebx+APPDATA.heap_top] + mov [edx+APPDATA.heap_top], ecx - mov eax,[ebx+APPDATA.mem_size] - mov [edx+APPDATA.mem_size], eax + mov eax,[ebx+APPDATA.mem_size] + mov [edx+APPDATA.mem_size], eax - mov ecx,[ebx+APPDATA.dir_table] - mov [edx+APPDATA.dir_table],ecx ;copy page directory + mov ecx,[ebx+APPDATA.dir_table] + mov [edx+APPDATA.dir_table],ecx ;copy page directory - lea eax, [app_cmdline] - stdcall set_app_params ,[slot],eax,dword 0,\ - dword 0,dword 0 + 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 - DEBUGF 1,"%s",new_process_running + ;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 - ret + mov [application_table_status],0 ;unlock application_table_status mutex + mov eax,[process_number] ;set result + ret .failed: - mov [application_table_status],0 - mov eax,-1 - ret + mov [application_table_status],0 + mov eax,-1 + ret endp ; param @@ -921,23 +918,20 @@ endp align 4 wait_mutex: - push eax - push ebx +;;Maxis use atomic bts for mutex 4.4.2009 + push eax + push ebx .do_wait: - cmp dword [ebx],0 - je .get_lock - call change_task - jmp .do_wait -.get_lock: - mov eax, 1 - xchg eax, [ebx] - test eax, eax - jnz .do_wait - pop ebx - pop eax - ret + bts dword [ebx],0 + jnc .locked + call change_task + jmp .do_wait +.locked: + pop ebx + pop eax + ret -EFL_IF equ 0x0200 +EFL_IF equ 0x0200 EFL_IOPL1 equ 0x1000 EFL_IOPL2 equ 0x2000 EFL_IOPL3 equ 0x3000 @@ -945,167 +939,166 @@ EFL_IOPL3 equ 0x3000 align 4 proc set_app_params stdcall,slot:dword, params:dword,\ - cmd_line:dword, app_path:dword, flags:dword + cmd_line:dword, app_path:dword, flags:dword - locals - pl0_stack dd ? - endl + locals + pl0_stack dd ? + endl - stdcall kernel_alloc, RING0_STACK_SIZE+512 - mov [pl0_stack], eax + stdcall kernel_alloc, RING0_STACK_SIZE+512 + mov [pl0_stack], eax - lea edi, [eax+RING0_STACK_SIZE] + lea edi, [eax+RING0_STACK_SIZE] - mov eax, [slot] - mov ebx, eax + mov eax, [slot] + mov ebx, eax - shl eax, 8 - mov [eax+SLOT_BASE+APPDATA.fpu_state], edi - mov [eax+SLOT_BASE+APPDATA.fpu_handler], 0 - mov [eax+SLOT_BASE+APPDATA.sse_handler], 0 + shl eax, 8 + mov [eax+SLOT_BASE+APPDATA.fpu_state], edi + mov [eax+SLOT_BASE+APPDATA.exc_handler], 0 + 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 [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 esi, fpu_data - mov ecx, 512/4 - rep movsd + mov esi, fpu_data + mov ecx, 512/4 + rep movsd - cmp ebx,[TASK_COUNT] - jle .noinc - inc dword [TASK_COUNT] ;update number of processes + cmp ebx,[TASK_COUNT] + jle .noinc + inc dword [TASK_COUNT] ;update number of processes .noinc: - shl ebx,8 - lea edx, [ebx+SLOT_BASE+APP_EV_OFFSET] - mov [SLOT_BASE+APPDATA.fd_ev+ebx],edx - mov [SLOT_BASE+APPDATA.bk_ev+ebx],edx + shl ebx,8 + lea edx, [ebx+SLOT_BASE+APP_EV_OFFSET] + mov [SLOT_BASE+APPDATA.fd_ev+ebx],edx + mov [SLOT_BASE+APPDATA.bk_ev+ebx],edx - add edx, APP_OBJ_OFFSET-APP_EV_OFFSET - mov [SLOT_BASE+APPDATA.fd_obj+ebx],edx - mov [SLOT_BASE+APPDATA.bk_obj+ebx],edx + add edx, APP_OBJ_OFFSET-APP_EV_OFFSET + mov [SLOT_BASE+APPDATA.fd_obj+ebx],edx + mov [SLOT_BASE+APPDATA.bk_obj+ebx],edx - mov ecx, [def_cursor] - mov [SLOT_BASE+APPDATA.cursor+ebx],ecx - mov eax, [pl0_stack] - mov [SLOT_BASE+APPDATA.pl0_stack+ebx],eax - add eax, RING0_STACK_SIZE - mov [SLOT_BASE+APPDATA.saved_esp0+ebx], eax + mov ecx, [def_cursor] + mov [SLOT_BASE+APPDATA.cursor+ebx],ecx + mov eax, [pl0_stack] + mov [SLOT_BASE+APPDATA.pl0_stack+ebx],eax + add eax, RING0_STACK_SIZE + mov [SLOT_BASE+APPDATA.saved_esp0+ebx], eax - push ebx - stdcall kernel_alloc, 0x1000 - pop ebx - mov esi,[current_slot] - mov esi,[esi+APPDATA.cur_dir] - mov ecx,0x1000/4 - mov edi,eax - mov [ebx+SLOT_BASE+APPDATA.cur_dir],eax - rep movsd + push ebx + stdcall kernel_alloc, 0x1000 + pop ebx + mov esi,[current_slot] + mov esi,[esi+APPDATA.cur_dir] + mov ecx,0x1000/4 + mov edi,eax + mov [ebx+SLOT_BASE+APPDATA.cur_dir],eax + rep movsd - shr ebx,3 - mov eax, new_app_base - mov dword [CURRENT_TASK+ebx+0x10],eax + shr ebx,3 + mov eax, new_app_base + mov dword [CURRENT_TASK+ebx+0x10],eax .add_command_line: - mov edx,[params] - mov edx,[edx] ;app_cmdline - test edx,edx - jz @f ;application doesn't need parameters + mov edx,[params] + mov edx,[edx] ;app_cmdline + test edx,edx + jz @f ;application doesn't need parameters - mov eax, edx - add eax, 256 - jc @f + mov eax, edx + add eax, 256 + jc @f - cmp eax, [SLOT_BASE+APPDATA.mem_size+ebx*8] - ja @f + cmp eax, [SLOT_BASE+APPDATA.mem_size+ebx*8] + ja @f - mov byte [edx], 0 ;force empty string if no cmdline given - mov eax, [cmd_line] - test eax, eax - jz @f - stdcall strncpy, edx, eax, 256 + mov byte [edx], 0 ;force empty string if no cmdline given + mov eax, [cmd_line] + test eax, eax + jz @f + stdcall strncpy, edx, eax, 256 @@: - mov edx,[params] - mov edx, [edx+4] ;app_path - test edx,edx - jz @F ;application don't need path of file - mov eax, edx - add eax, 1024 - jc @f - cmp eax, [SLOT_BASE+APPDATA.mem_size+ebx*8] - ja @f - stdcall strncpy, edx, [app_path], 1024 + mov edx,[params] + mov edx, [edx+4] ;app_path + test edx,edx + jz @F ;application don't need path of file + mov eax, edx + add eax, 1024 + jc @f + cmp eax, [SLOT_BASE+APPDATA.mem_size+ebx*8] + ja @f + stdcall strncpy, edx, [app_path], 1024 @@: - mov ebx,[slot] - mov eax,ebx - shl ebx,5 - lea ecx,[draw_data+ebx] ;ecx - pointer to draw data + mov ebx,[slot] + mov eax,ebx + shl ebx,5 + lea ecx,[draw_data+ebx] ;ecx - pointer to draw data ; 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 - add ebx,CURRENT_TASK ;ebx - pointer to information about process - mov [ebx+TASKDATA.wnd_number],al;set window number on screen = process slot + mov [ebx+window_data+WDATA.fl_wstate], WSTATE_NORMAL + mov [ebx+window_data+WDATA.fl_redraw], 1 + add ebx,CURRENT_TASK ;ebx - pointer to information about process + mov [ebx+TASKDATA.wnd_number],al;set window number on screen = process slot - mov [ebx+TASKDATA.event_mask],dword 1+2+4 ;set default event flags (see 40 function) + mov [ebx+TASKDATA.event_mask],dword 1+2+4 ;set default event flags (see 40 function) - inc dword [process_number] - mov eax,[process_number] - mov [ebx+4],eax ;set PID + inc dword [process_number] + mov eax,[process_number] + mov [ebx+4],eax ;set PID ;set draw data to full screen - mov [ecx+0],dword 0 - mov [ecx+4],dword 0 - mov eax,[Screen_Max_X] - mov [ecx+8],eax - mov eax,[Screen_Max_Y] - mov [ecx+12],eax + mov [ecx+0],dword 0 + mov [ecx+4],dword 0 + mov eax,[Screen_Max_X] + mov [ecx+8],eax + mov eax,[Screen_Max_Y] + mov [ecx+12],eax - mov ebx, [pl0_stack] - mov esi,[params] - lea ecx, [ebx+REG_EIP] - xor eax, eax + mov ebx, [pl0_stack] + mov esi,[params] + lea ecx, [ebx+REG_EIP] + xor eax, eax - mov [ebx+REG_RET], dword irq0.return - mov [ebx+REG_EDI], eax - mov [ebx+REG_ESI], eax - mov [ebx+REG_EBP], eax - mov [ebx+REG_ESP], ecx ;ebx+REG_EIP - mov [ebx+REG_EBX], eax - mov [ebx+REG_EDX], eax - mov [ebx+REG_ECX], eax - mov [ebx+REG_EAX], eax + mov [ebx+REG_RET], dword irq0.return + mov [ebx+REG_EDI], eax + mov [ebx+REG_ESI], eax + mov [ebx+REG_EBP], eax + mov [ebx+REG_ESP], ecx ;ebx+REG_EIP + mov [ebx+REG_EBX], eax + mov [ebx+REG_EDX], eax + mov [ebx+REG_ECX], eax + mov [ebx+REG_EAX], eax - mov eax, [esi+0x08] ;app_eip - mov [ebx+REG_EIP], eax ;app_entry - mov [ebx+REG_CS], dword app_code - mov [ebx+REG_EFLAGS], dword EFL_IOPL1+EFL_IF + mov eax, [esi+0x08] ;app_eip + mov [ebx+REG_EIP], eax ;app_entry + mov [ebx+REG_CS], dword app_code + mov [ebx+REG_EFLAGS], dword EFL_IOPL1+EFL_IF - mov eax, [esi+0x0C] ;app_esp - mov [ebx+REG_APP_ESP], eax ;app_stack - mov [ebx+REG_SS], dword app_data + mov eax, [esi+0x0C] ;app_esp + mov [ebx+REG_APP_ESP], eax ;app_stack + mov [ebx+REG_SS], dword app_data - lea ecx, [ebx+REG_RET] - mov ebx, [slot] - shl ebx, 5 - mov [ebx*8+SLOT_BASE+APPDATA.saved_esp], ecx + lea ecx, [ebx+REG_RET] + mov ebx, [slot] + shl ebx, 5 + mov [ebx*8+SLOT_BASE+APPDATA.saved_esp], ecx - xor ecx, ecx ; process state - running + xor ecx, ecx ; process state - running ; set if debuggee - test byte [flags], 1 - jz .no_debug - inc ecx ; process state - suspended - mov eax,[CURRENT_TASK] - mov [SLOT_BASE+ebx*8+APPDATA.debugger_slot],eax + test byte [flags], 1 + jz .no_debug + inc ecx ; process state - suspended + mov eax,[CURRENT_TASK] + mov [SLOT_BASE+ebx*8+APPDATA.debugger_slot],eax .no_debug: - mov [CURRENT_TASK+ebx+TASKDATA.state], cl - ;mov esi,new_process_running - ;call sys_msg_board_str ;output information about succefull startup - DEBUGF 1,"%s",new_process_running - ret + mov [CURRENT_TASK+ebx+TASKDATA.state], cl + ;mov esi,new_process_running + ;call sys_msg_board_str ;output information about succefull startup + ret endp include "debug.inc" diff --git a/kernel/branches/net/core/v86.inc b/kernel/branches/net/core/v86.inc index 1ddd0ef7df..ca0a14c729 100644 --- a/kernel/branches/net/core/v86.inc +++ b/kernel/branches/net/core/v86.inc @@ -203,7 +203,7 @@ v86_set_page: ; add edx, ecx ; cmp dword [edx], 0 ; free block? ; jnz .n -; cmp dword [edx+4], +; cmp dword [edx+4], ; and [esi+V86_machine.mutex], 0 ; pop edi edx ecx ebx ; ret @@ -351,47 +351,27 @@ endg ; a protected-mode interrupt handler (typically the general-protection ; exception handler, which in turn calls the virtual 8086-mode monitor). -v86_debug_exc: - pushad - xor eax, eax - mov dr6, eax - mov bl, 1 - jmp v86_exc_c - -v86_page_fault: - add esp, 4 - pushad - mov bl, 14 - jmp v86_exc_c - -v86_except_16: - pushad - mov bl, 16 - jmp v86_exc_c -v86_except_19: - pushad - mov bl, 19 - iglobal -v86_exc_str1 db 'V86 : unexpected exception ',0 -v86_exc_str2 db ' at ',0 -v86_exc_str3 db ':',0 -v86_exc_str4 db 13,10,'V86 : faulted code:',0 -v86_exc_str5 db ' (unavailable)',0 -v86_newline db 13,10,0 -v86_io_str1 db 'V86 : access to disabled i/o port ',0 -v86_io_byte db ' (byte)',13,10,0 -v86_io_word db ' (word)',13,10,0 -v86_io_dword db ' (dword)',13,10,0 -v86_irqerr db 'V86 : IRQ already hooked',13,10,0 + v86_exc_str1 db 'V86 : unexpected exception ',0 + v86_exc_str2 db ' at ',0 + v86_exc_str3 db ':',0 + v86_exc_str4 db 13,10,'V86 : faulted code:',0 + v86_exc_str5 db ' (unavailable)',0 + v86_newline db 13,10,0 + v86_io_str1 db 'V86 : access to disabled i/o port ',0 + v86_io_byte db ' (byte)',13,10,0 + v86_io_word db ' (word)',13,10,0 + v86_io_dword db ' (dword)',13,10,0 + v86_irqerr db 'V86 : IRQ already hooked',13,10,0 endg v86_exc_c: - mov ax, app_data - mov ds, ax - mov es, ax ; Did we all that we have wanted to do? - mov eax, [esp+v86_regs.size+10h+18h] + cmp bl,1 + jne @f + xor eax, eax + mov dr6, eax + @@: mov eax, [esp+v86_regs.size+10h+18h] cmp word [esp+v86_regs.eip], ax jnz @f shr eax, 16 @@ -945,12 +925,11 @@ v86_irq2: mov cx, [eax*4+2] mov word [esi-v86_regs.size+v86_regs.cs], cx and byte [esi-v86_regs.size+v86_regs.eflags+1], not 3 - push ebx call update_counters - pop ebx - sub ebx, SLOT_BASE - shr ebx, 8 - mov esi, [CURRENT_TASK] + lea edi, [ebx + 0x100000000 - SLOT_BASE] + shr edi, 3 + add edi, TASK_DATA + call find_next_task.found call do_change_task popad iretd diff --git a/kernel/branches/net/data32.inc b/kernel/branches/net/data32.inc index 486f707e87..2e0a60109a 100644 --- a/kernel/branches/net/data32.inc +++ b/kernel/branches/net/data32.inc @@ -48,38 +48,39 @@ keymap_alt: - 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_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 + 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 + 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 +;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 +msg_CR db 13,10,0 aSis db 'SIS',0 intel_str db "GenuineIntel",0 @@ -87,11 +88,11 @@ 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 +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 @@ -102,13 +103,13 @@ 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 +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 +vmode db '/sys/drivers/VMODE.MDR',0 +vrr_m db 'VRR_M',0 kernel_file db 'KERNEL MNT' @@ -144,14 +145,14 @@ mode_320_240_8: ; 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 +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 +drawbar dd __sys_drawbar.forced ;//mike.dld, 2006-08-02 ] -putpixel dd __sys_putpixel +putpixel dd __sys_putpixel ; } mike.dld @@ -159,10 +160,10 @@ align 4 keyboard dd 1 syslang dd 1 -boot_y dd 10 +boot_y dd 10 -pci_bios_entry dd 0 - dw pci_code_sel +pci_bios_entry dd 0 + dw pci_code_sel if __DEBUG__ eq 1 include_debug_strings @@ -173,136 +174,135 @@ IncludeIGlobals align 16 gdts: - dw gdte-$-1 - dd gdts - dw 0 + 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 + 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 + 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; + 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; + 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 + 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 + 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 + 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 + 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 + 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 + 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 + 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 +cur_saved_data rb 4096 +fpu_data: rb 512 ; device irq owners -irq_owner rd 16 ; process id +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 +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 +irq_tab rd 16 -mem_block_map rb 512 -event_map rb 64 -mem_block_list rd 64 +mem_block_map rb 512 +mem_block_list rd 64 large_block_list rd 31 -mem_block_mask rd 2 +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_arr rd 1 mem_block_start rd 1 -mem_block_end rd 1 +mem_block_end rd 1 heap_mutex rd 1 heap_size rd 1 @@ -314,143 +314,139 @@ mst MEM_STATE page_start rd 1 page_end rd 1 -events rd 1 -event_start rd 1 -event_end rd 1 -event_uid rd 1 -sys_page_map rd 1 -os_stack_seg rd 1 +sys_page_map rd 1 +os_stack_seg rd 1 -srv.fd rd 1 -srv.bk rd 1 +srv.fd rd 1 +srv.bk rd 1 -scr_width rd 1 -scr_height rd 1 +scr_width rd 1 +scr_height rd 1 -create_cursor rd 1 +create_cursor rd 1 select_hw_cursor rd 1 -set_hw_cursor rd 1 -hw_restore 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 +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 +cur_saved_w rd 1 +cur_saved_h rd 1 -ipc_tmp rd 1 -ipc_pdir rd 1 -ipc_ptab 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 +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 +tmp_task_pdir rd 1 +tmp_task_ptab rd 1 -default_io_map rd 1 +default_io_map rd 1 -LFBSize rd 1 +LFBSize rd 1 -stall_mcs rd 1 -current_slot rd 1 +stall_mcs rd 1 +current_slot rd 1 ; status -hd1_status rd 1 ; 0 - free : other - pid +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 +mididp rd 1 +midisp rd 1 -cdbase rd 1 -cdid 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 +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 +cpu_vendor rd 3 +cpu_sign rd 1 +cpu_info rd 1 +cpu_caps rd 4 -pg_data PG_DATA -heap_test rd 1 +pg_data PG_DATA +heap_test rd 1 -buttontype rd 1 +buttontype rd 1 windowtypechanged rd 1 -hd_entries rd 1 ;unused ? 0xfe10 +hd_entries rd 1 ;unused ? 0xfe10 ;* start code - Mario79 -mouse_active rd 1 -mouse_pause rd 1 +mouse_active rd 1 +mouse_pause rd 1 MouseTickCounter rd 1 ;* end code - Mario79 -img_background rd 1 -mem_BACKGROUND rd 1 -wraw_bacground_select rb 1 +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_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_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_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_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_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_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_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_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 @@ -462,12 +458,11 @@ 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 +timer_ticks_enable rb 1 ; for cd driver -NumBiosDisks rd 1 -BiosDisksData rb 200h -BiosDiskCaches rb 80h*(cache_ide1-cache_ide0) +NumBiosDisks rd 1 +BiosDisksData rb 200h +BiosDiskCaches rb 80h*(cache_ide1-cache_ide0) BiosDiskPartitions rd 80h IncludeUGlobals - diff --git a/kernel/branches/net/detect/biosmem.inc b/kernel/branches/net/detect/biosmem.inc new file mode 100644 index 0000000000..7b66cd4b66 --- /dev/null +++ b/kernel/branches/net/detect/biosmem.inc @@ -0,0 +1,43 @@ +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; ;; +;; Copyright (C) KolibriOS team 2009. All rights reserved. ;; +;; Distributed under terms of the GNU General Public License ;; +;; ;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +; Query physical memory map from BIOS. +; diamond, 2009 + + push ds +; first call to fn E820 + mov eax, 0xE820 + xor ebx, ebx + mov es, bx + mov ds, bx + mov di, 0x9104 + mov [di-4], ebx ; no blocks yet + mov ecx, 20 + mov edx, 0x534D4150 + int 15h + jc no_E820 + cmp eax, 0x534D4150 + jnz no_E820 +e820_mem_loop: + cmp byte [di+16], 1 ; ignore non-free areas + jnz e820_mem_next + inc byte [0x9100] + add di, 20 +e820_mem_next: +; consequent calls to fn E820 + test ebx, ebx + jz e820_test_done + cmp byte [0x9100], 32 + jae e820_test_done + mov eax, 0xE820 + int 15h + jc e820_test_done + jmp e820_mem_loop +no_E820: +; let's hope for mem_test from init.inc +e820_test_done: + pop ds diff --git a/kernel/branches/net/detect/getcache.inc b/kernel/branches/net/detect/getcache.inc index e8a93a3931..2fc363197a 100644 --- a/kernel/branches/net/detect/getcache.inc +++ b/kernel/branches/net/detect/getcache.inc @@ -70,15 +70,26 @@ $Revision: 750 $ jz .endbd mov esi,BiosDiskCaches .loopbd: - cmp byte [BiosDisksData+ecx*4+2],-1 - jnz .contbd + push ecx + movsx ecx,byte [BiosDisksData+ecx*4+2] + inc ecx + jz .getbd + add ecx,ecx + movzx eax,byte [DRIVE_DATA+1] + shl eax,cl + and ah,3 + cmp ah,1 + jz .contbd + pop ecx + mov byte [BiosDisksData+ecx*4+2], -1 + push ecx +.getbd: mov eax,[cache_ide0_size] mov [esi+cache_ide0_size-cache_ide0],eax - push ecx mov cl,1 call get_cache_ide - pop ecx .contbd: + pop ecx add esi,cache_ide1-cache_ide0 inc ecx cmp ecx,[NumBiosDisks] diff --git a/kernel/branches/net/drivers/sb16/CONFIG.INC b/kernel/branches/net/drivers/sb16/CONFIG.INC index 026915d943..322fccfbc8 100644 --- a/kernel/branches/net/drivers/sb16/CONFIG.INC +++ b/kernel/branches/net/drivers/sb16/CONFIG.INC @@ -22,7 +22,7 @@ sb_dma_num equ 5 ;default values for SB16, may be overrided by autodetect small_buffer equ 32768 full_buffer equ 65536 -sb_buffer_size equ full_buffer +sb_buffer_size equ small_buffer ; FIX ring buffer overlapped events issue; full_buffer __supported_buffer_sizes fix diff --git a/kernel/branches/net/fdo.inc b/kernel/branches/net/fdo.inc index c63d628353..c7d91ee173 100644 --- a/kernel/branches/net/fdo.inc +++ b/kernel/branches/net/fdo.inc @@ -201,7 +201,6 @@ macro DEBUGH_N _sign,_num,_hex { if ~_hex eq ax movzx eax,_hex end if - shl eax,16 if (_num eq) mov edx,4 end if @@ -209,7 +208,6 @@ macro DEBUGH_N _sign,_num,_hex { if ~_hex eq al movzx eax,_hex end if - shl eax,24 if (_num eq) mov edx,2 end if diff --git a/kernel/branches/net/fs/fat32.inc b/kernel/branches/net/fs/fat32.inc index f27d99b889..7a9d020f4d 100644 --- a/kernel/branches/net/fs/fat32.inc +++ b/kernel/branches/net/fs/fat32.inc @@ -1062,14 +1062,6 @@ fs_HdRead: mov eax, ERROR_ACCESS_DENIED ret -.noaccess_3: - add esp,4 -.noaccess_1: - add esp,4 -.noaccess_4: - add esp,4*5 - jmp .noaccess_2 - @@: call hd_find_lfn jnc .found @@ -1133,9 +1125,9 @@ fs_HdRead: push ebx mov ebx, edx call hd_read + pop ebx cmp [hd_error],0 jne .noaccess_1 - pop ebx add edx, 512 sub ecx, 512 jmp .skip @@ -1144,11 +1136,10 @@ fs_HdRead: push eax ebx mov ebx, buffer call hd_read - cmp [hd_error],0 - jne .noaccess_3 - mov eax, ebx pop ebx + cmp [hd_error],0 + jne .noaccess_3 add eax, ebx push ecx add ecx, ebx @@ -1171,9 +1162,14 @@ fs_HdRead: mov eax, [cluster_tmp] call get_FAT cmp [hd_error],0 - jne .noaccess_4 + jne .noaccess_1 jmp .new_cluster +.noaccess_3: + pop eax +.noaccess_1: + pop eax + push 11 .done: mov ebx, edx pop eax edx ecx edi diff --git a/kernel/branches/net/fs/part_set.inc b/kernel/branches/net/fs/part_set.inc index 795ac79a2c..9c21709859 100644 --- a/kernel/branches/net/fs/part_set.inc +++ b/kernel/branches/net/fs/part_set.inc @@ -383,9 +383,13 @@ boot_read_ok: mov [FAT_START],eax ; fat_start = partition_start + reserved movzx eax,byte [ebx+0xd] ; sectors per cluster + test eax,eax + jz problem_fat_dec_count mov [SECTORS_PER_CLUSTER],eax movzx ecx,word [ebx+0xb] ; bytes per sector + cmp ecx,0x200 + jnz problem_fat_dec_count mov [BYTES_PER_SECTOR],ecx movzx eax,word [ebx+0x11] ; count of rootdir entries (=0 fat32) diff --git a/kernel/branches/net/gui/button.inc b/kernel/branches/net/gui/button.inc index 3375cbfa58..f351dbdce8 100644 --- a/kernel/branches/net/gui/button.inc +++ b/kernel/branches/net/gui/button.inc @@ -69,103 +69,103 @@ incecx2: drawbuttonframes: - push esi - push edi - push eax - push ebx - push ecx - push edx + push esi + push edi + push eax + push ebx + push ecx + push edx - shr ebx,16 - shr ecx,16 - mov eax,[TASK_BASE] + 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] + 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] + 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] + 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] + 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 + pop edx + pop ecx + pop ebx + pop eax + pop edi + pop esi - ret + ret button_dececx: - cmp [buttontype],dword 1 - jne .finish + cmp [buttontype],dword 1 + jne .finish ; je bdece ; ret ; bdece: - push eax - mov eax,0x01 - cmp edi,20 - jg @f - mov eax,0x02 + push eax + mov eax,0x01 + cmp edi,20 + jg @f + mov eax,0x02 @@: - test ecx,0xff - jz @f - sub ecx,eax + test ecx,0xff + jz @f + sub ecx,eax @@: - shl eax,8 - test ecx,0xff00 - 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 + shl eax,8 + test ecx,0xff0000 + jz @f + sub ecx,eax @@: - pop eax + pop eax .finish: - ret + ret sys_button: @@ -190,7 +190,7 @@ sys_button: test edx, 0x40000000 jnz button_no_draw - pushad ; button body + pushad ; button body movzx edi, cx shr ebx, 16 shr ecx, 16 @@ -293,44 +293,44 @@ rnmba: find_pressed_button_frames: - pushad + pushad - movzx ebx,word [eax+0] - shl ebx,5 - add ebx,window_data + 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 + 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 + 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 + add ecx,edx + mov ebx,ecx + mov dx,[eax+10] ; button y size + add dx,cx + inc dx - pop eax + pop eax - ; eax x beginning - ; ebx y beginning - ; esi x end - ; edx y end - ; ecx color + ; 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 + 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 + popad + ret uglobal pressed_button_eax dd 0 @@ -343,70 +343,70 @@ endg ; negative button image negativebutton: - ; If requested, do not display button - ; boarder on press. - test ebx,0x20000000 - jz draw_negative_button - ret + ; If requested, do not display button + ; boarder on press. + test ebx,0x20000000 + jz draw_negative_button + ret draw_negative_button: - pushad + 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 + 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 + dec edx + push edx + inc edx + dec esi + push esi + inc esi - push eax - push ebx - push ecx - push edx - push edi + push eax + push ebx + push ecx + push edx + push edi - call [disable_mouse] + 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 + 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] + ;;;call [disable_mouse] + call [putpixel] nbneg: - inc eax - cmp eax,esi - jnz bdbnewline - mov eax,[esp+16] - inc ebx - cmp ebx,edx - jnz bdbnewline + inc eax + cmp eax,esi + jnz bdbnewline + mov eax,[esp+16] + inc ebx + cmp ebx,edx + jnz bdbnewline - add esp,28 + add esp,28 - popad + popad - ret + ret ; check buttons @@ -423,7 +423,7 @@ negativebutton: ; ; first at 0x10 - +align 4 checkbuttons: cmp [BTN_DOWN],byte 0 ; mouse buttons pressed @@ -455,7 +455,7 @@ checkbuttons: mov ax,[MOUSE_Y] mov [my],ax @@: - pop ax + pop ax ;and it is only refreshed after the mouse's button release ;..................................... end 2/5 : modified by vhanla ............................. @@ -471,7 +471,7 @@ checkbuttons: cmp edx,esi jge bch - popad ; no button pressed + popad ; no button pressed ret bch: @@ -494,8 +494,8 @@ checkbuttons: movzx ebx,word [eax+0] shl ebx,5 - test [ebx+window_data+WDATA.fl_wstate],WSTATE_MINIMIZED - jnz buttonnewcheck + test [ebx+window_data+WDATA.fl_wstate],WSTATE_MINIMIZED + jnz buttonnewcheck ; add ebx,window_data ; mov ecx,[window_data+ebx+8] ; window end X @@ -509,50 +509,50 @@ checkbuttons: jge buttonnewcheck ; check coordinates - ; mouse x >= button x ? + ; 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 + 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 + jg buttonnewcheck movzx ebx,word [eax+6] ; button x size add edx,ebx cmp ecx,edx - jg buttonnewcheck + jg buttonnewcheck - ; mouse y >= button y ? + ; 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 + 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 + jg buttonnewcheck movzx ebx,word [eax+10] ; button y size add edx,ebx cmp ecx,edx - jg buttonnewcheck + jg buttonnewcheck ; mouse on button pop edx pop esi - mov bx,[eax+0xc] ; button id : bits 16-31 + mov bx,[eax+0xc] ; button id : bits 16-31 shl ebx,16 - mov bx,[eax+2] ; button id : bits 00-16 + mov bx,[eax+2] ; button id : bits 00-16 push ebx mov [MOUSE_DOWN],byte 1 ; no mouse down checks @@ -596,46 +596,46 @@ 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 + 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 + 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 + add edx,ebx + cmp ecx,edx + jg no_on_button - ; mouse y >= button y ? + ; 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 + 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 + 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 + 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 + 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 + mov [BTN_COUNT],byte 0 ; no of buttons in buffer yes_on_button: - mov [MOUSE_DOWN],byte 0 ; mouse down -> do not draw + mov [MOUSE_DOWN],byte 0 ; mouse down -> do not draw popa pop ebx popa diff --git a/kernel/branches/net/gui/event.inc b/kernel/branches/net/gui/event.inc index 63148fed83..fc52dc0687 100644 --- a/kernel/branches/net/gui/event.inc +++ b/kernel/branches/net/gui/event.inc @@ -7,695 +7,481 @@ $Revision: 671 $ +uglobal +align 4 + event_start dd ? + event_end dd ? + event_uid dd 0 +endg +EV_SPACE = 512 +FreeEvents = event_start-EVENT.fd ; "виртуальный" event, используются только поля: + ; FreeEvents.fd=event_start и FreeEvents.bk=event_end +align 4 +init_events: ;; used from kernel.asm + stdcall kernel_alloc,EV_SPACE*EVENT.size + or eax,eax + jz .fail + ; eax - current event, ebx - previos event below + mov ecx,EV_SPACE ; current - in allocated space + mov ebx,FreeEvents ; previos - начало списка + push ebx ; оно же и конец потом будет + @@: mov [ebx+EVENT.fd],eax + mov [eax+EVENT.bk],ebx + mov ebx,eax ; previos <- current + add eax,EVENT.size ; new current + loop @b + pop eax ; вот оно концом и стало + mov [ebx+EVENT.fd],eax + mov [eax+EVENT.bk],ebx +.fail: ret + +EVENT_WATCHED equ 0x10000000 ;бит 28 +EVENT_SIGNALED equ 0x20000000 ;бит 29 +MANUAL_RESET equ 0x40000000 ;бит 30 +MANUAL_DESTROY equ 0x80000000 ;бит 31 align 4 -init_events: - stdcall kernel_alloc, 512*EVENT_SIZE - mov [events], eax - xor eax, eax - mov [event_uid], eax - not eax - mov edi, event_map - mov [event_start], edi - mov ecx, 64/4 - cld - rep stosd - mov [event_end], edi - ret +create_event: ;; EXPORT use +;info: +; Переносим EVENT из списка FreeEvents в список ObjList текущего слота +; EVENT.state устанавливаем из ecx, EVENT.code косвенно из esi (если esi<>0) +;param: +; esi - event data +; ecx - flags +;retval: +; eax - event (=0 => fail) +; edx - uid +;scratched: ebx,ecx,esi,edi + mov ebx,[current_slot] + add ebx,APP_OBJ_OFFSET + mov edx,[TASK_BASE] + mov edx,[edx+TASKDATA.pid] + pushfd + cli + +set_event: ;; INTERNAL use !!! don't use for Call +;info: +; Берем новый event из FreeEvents, заполняем его поля, как указано в ecx,edx,esi +; и устанавливаем в список, указанный в ebx. +; Возвращаем сам event (в eax), и его uid (в edx) +;param: +; ebx - start-chain "virtual" event for entry new event Right of him +; ecx - flags (copied to EVENT.state) +; edx - pid (copied to EVENT.pid) +; esi - event data (copied to EVENT.code indirect, =0 => skip) +;retval: +; eax - event (=0 => fail) +; edx - uid +;scratched: ebx,ecx,esi,edi + mov eax,FreeEvents + cmp eax,[eax+EVENT.fd] + jne @f ; not empty ??? + pushad + call init_events + popad + jz RemoveEventTo.break ; POPF+RET + @@: mov eax,[eax+EVENT.fd] + mov [eax+EVENT.magic],'EVNT' + mov [eax+EVENT.destroy],destroy_event.internal + mov [eax+EVENT.state],ecx + mov [eax+EVENT.pid],edx + inc [event_uid] + Mov [eax+EVENT.id],edx,[event_uid] + or esi,esi + jz RemoveEventTo + lea edi,[eax+EVENT.code] + mov ecx,EVENT.codesize/4 + cld + rep movsd + +RemoveEventTo: ;; INTERNAL use !!! don't use for Call +;param: +; eax - указатель на event, КОТОРЫЙ вставляем +; ebx - указатель на event, ПОСЛЕ которого вставляем +;scratched: ebx,ecx + mov ecx,eax ; ecx=eax=Self, ebx=NewLeft + xchg ecx,[ebx+EVENT.fd] ; NewLeft.fd=Self, ecx=NewRight + cmp eax,ecx ; стоп, себе думаю... + je .break ; - а не дурак ли я? + mov [ecx+EVENT.bk],eax ; NewRight.bk=Self + xchg ebx,[eax+EVENT.bk] ; Self.bk=NewLeft, ebx=OldLeft + xchg ecx,[eax+EVENT.fd] ; Self.fd=NewRight, ecx=OldRight + mov [ebx+EVENT.fd],ecx ; OldLeft.fd=OldRight + mov [ecx+EVENT.bk],ebx ; OldRight.bk=OldLeft +.break: popfd + ret align 4 -proc alloc_event - - pushfd - cli - mov ebx, [event_start] - mov ecx, [event_end] -.l1: - bsf eax,[ebx] - jnz .found - add ebx,4 - cmp ebx, ecx - jb .l1 - popfd - xor eax,eax - ret -.found: - btr [ebx], eax - mov [event_start],ebx - inc [event_uid] - - sub ebx, event_map - lea eax,[eax+ebx*8] - - lea ebx, [eax+eax*4] - shl eax,5 - lea eax,[eax+ebx*4] ;eax*=52 (EVENT_SIZE) - add eax, [events] - mov ebx, [event_uid] - popfd - ret -endp +NotDummyTest: ;; INTERNAL use (not returned for fail !!!) + pop edi + call DummyTest ; not returned for fail !!! + mov ebx,eax + mov eax,[ebx+EVENT.pid] + push edi +.small: ; криво как-то... + pop edi + pushfd + cli + call pid_to_slot ; saved all registers (eax - retval) + shl eax,8 + jz RemoveEventTo.break ; POPF+RET + jmp edi ; штатный возврат align 4 -free_event: - sub eax, [events] - mov ecx, EVENT_SIZE - mov ebx, event_map - cdq - div ecx +raise_event: ;; EXPORT use +;info: +; Устанавливаем данные EVENT.code +; Если там флаг EVENT_SIGNALED уже активен - больше ничего +; Иначе: этот флаг взводится, за исключением случая наличия флага EVENT_WATCHED в edx +; В этом случае EVENT_SIGNALED взводится лишь при наличие EVENT_WATCHED в самом событии +;param: +; eax - event +; ebx - uid (for Dummy testing) +; edx - flags +; esi - event data (=0 => skip) +;scratched: ebx,ecx,esi,edi + call NotDummyTest ; not returned for fail !!! + or esi,esi + jz @f + lea edi,[ebx+EVENT.code] + mov ecx,EVENT.codesize/4 + cld + rep movsd + @@: + test byte[ebx+EVENT.state+3], EVENT_SIGNALED shr 24 + jnz RemoveEventTo.break ; POPF+RET + bt edx, 28 ;EVENT_WATCHED + jnc @f + test byte[ebx+EVENT.state+3], EVENT_WATCHED shr 24 + jz RemoveEventTo.break ; POPF+RET + @@: + or byte[ebx+EVENT.state+3], EVENT_SIGNALED shr 24 + add eax,SLOT_BASE+APP_EV_OFFSET + xchg eax,ebx + jmp RemoveEventTo - pushfd - cli - bts [ebx], eax - shr eax, 3 - and eax, not 3 - add eax, ebx - cmp [event_start], eax - ja @f - popfd - ret -@@: - mov [event_start], eax - popfd - ret - -EVENT_WATCHED equ 0x10000000 -EVENT_SIGNALED equ 0x20000000 -MANUAL_RESET equ 0x40000000 -MANUAL_DESTROY equ 0x80000000 - - -; param -; eax= event data -; ebx= flags +align 4 +clear_event: ;; EXPORT use +;info: ; -; retval -; eax= event -; edx= id - -create_event: - .flags equ esp+4 - .data equ esp - - push ebx - push eax - - call alloc_event - test eax, eax - jz .fail - - mov [eax+APPOBJ.magic], 'EVNT' - mov [eax+APPOBJ.destroy], destroy_event.internal - mov [eax+EVENT.id], ebx - - mov ebx, [CURRENT_TASK] - shl ebx, 5 - mov ebx, [CURRENT_TASK+ebx+4] - mov [eax+APPOBJ.pid], ebx - mov edx, [.flags] - mov [eax+EVENT.state], edx - - mov esi, [.data] - test esi, esi - jz @F - lea edi, [eax+EVENT.code] - mov ecx, 6 - cld - rep movsd -@@: - mov ecx, [current_slot] - add ecx, APP_OBJ_OFFSET - - pushfd - cli - mov edx, [ecx+APPOBJ.fd] - mov [eax+APPOBJ.fd], edx - mov [eax+APPOBJ.bk], ecx - mov [ecx+APPOBJ.fd], eax - mov [edx+APPOBJ.bk], eax - popfd - mov edx, [eax+EVENT.id] -.fail: - add esp, 8 - ret - -restore .flags -restore .data - -; param -; eax= event -; ebx= id - -destroy_event: - - cmp [eax+APPOBJ.magic], 'EVNT' - jne .fail - cmp [eax+EVENT.id], ebx - jne .fail -.internal: - mov ebx, [eax+APPOBJ.fd] - mov ecx, [eax+APPOBJ.bk] - mov [ebx+APPOBJ.bk], ecx - mov [ecx+APPOBJ.fd], ebx -.force: - xor edx, edx ;clear common header - mov [eax], edx - mov [eax+4], edx - mov [eax+8], edx - mov [eax+12], edx - mov [eax+16], edx - - call free_event ;release object memory -.fail: - ret +;param: +; eax - event +; ebx - uid (for Dummy testing) +;scratched: ebx,ecx + call NotDummyTest ; not returned for fail !!! + add eax,SLOT_BASE+APP_OBJ_OFFSET + and byte[ebx+EVENT.state+3], not((EVENT_SIGNALED+EVENT_WATCHED)shr 24) + xchg eax,ebx + jmp RemoveEventTo align 4 -proc send_event stdcall pid:dword, event:dword - locals - slot dd ? - endl - - mov eax, [pid] - call pid_to_slot - test eax, eax - jz .fail - - shl eax, 8 - cmp [SLOT_BASE+eax+APPDATA.ev_count], 32 - ja .fail - - mov [slot], eax - - call alloc_event - test eax, eax - jz .fail - - lea edi, [eax+EVENT.code] - mov ecx, 6 - mov esi, [event] - cld - rep movsd - - mov ecx, [slot] - add ecx, SLOT_BASE+APP_EV_OFFSET - - mov [eax+APPOBJ.magic], 'EVNT' - mov [eax+APPOBJ.destroy], destroy_event - mov ebx, [pid] - mov [eax+APPOBJ.pid], ebx - mov [eax+EVENT.state], EVENT_SIGNALED - - pushfd - cli ;insert event into - mov edx, [ecx+APPOBJ.fd] ;events list - mov [eax+APPOBJ.fd], edx ;and set events flag - mov [eax+APPOBJ.bk], ecx - mov [ecx+APPOBJ.fd], eax - mov [edx+APPOBJ.bk], eax - inc [ecx+APPDATA.ev_count-APP_EV_OFFSET] - or [ecx+APPDATA.event_mask-APP_EV_OFFSET], EVENT_EXTENDED - popfd -.fail: - ret -endp - -; timeout ignored +send_event: ;; EXPORT use +;info: +; Создает новый EVENT (вытаскивает из списка FreeEvents) в списке EventList +; целевого слота (eax=pid), с данными из esi косвенно, и state=EVENT_SIGNALED +;param: +; eax - slots pid, to sending new event +; esi - pointer to sending data (in code field of new event) +;retval: +; eax - event (=0 => fail) +; edx - uid +;warning: +; may be used as CDECL with such prefix... +; mov esi,[esp+8] +; mov eax,[esp+4] +; but not as STDCALL :( +;scratched: ebx,ecx,esi,edi + mov edx,eax + call NotDummyTest.small ; not returned for fail !!! + lea ebx,[eax+SLOT_BASE+APP_EV_OFFSET] + mov ecx,EVENT_SIGNALED + jmp set_event align 4 -proc get_event_ex stdcall, p_ev:dword, timeout:dword +DummyTest: ;; INTERNAL use (not returned for fail !!!) +;param: +; eax - event +; ebx - uid (for Dummy testing) + cmp [eax+EVENT.magic],'EVNT' + jne @f + cmp [eax+EVENT.id],ebx + je .ret + @@: pop eax + xor eax,eax +.ret: ret -.wait: - mov edx,[current_slot] -; cmp [SLOT_BASE+edx+APPDATA.ev_count], 0 -; je .switch - - add edx, APP_EV_OFFSET - - mov eax, [edx+APPOBJ.fd] - cmp eax, edx - je .switch - - lea esi, [eax+EVENT.code] - mov edi, [p_ev] ;copy event data - mov ecx, 6 - cld - rep movsd - - and dword [edi-24], 0xFF00FFFF ;clear priority field - ; - test [eax+EVENT.state], MANUAL_RESET - jnz .done - - pushfd - cli ;remove event from events - mov ebx, [eax+APPOBJ.fd] ;list (reset event) - mov ecx, [eax+APPOBJ.bk] ;and clear events flag - mov [ebx+APPOBJ.bk], ecx ;if no active events - mov [ecx+APPOBJ.fd], ebx - - and [eax+EVENT.state], not (EVENT_SIGNALED+EVENT_WATCHED) - - dec [edx+APPDATA.ev_count-APP_EV_OFFSET] - jnz @F - and [edx+APPDATA.event_mask-APP_EV_OFFSET], not EVENT_EXTENDED -@@: - popfd - - test [eax+EVENT.state], MANUAL_DESTROY - jz .destroy - - add edx, (APP_OBJ_OFFSET-APP_EV_OFFSET) - - pushfd - cli - mov ebx, [edx+APPOBJ.fd] ;insert event into - mov [eax+APPOBJ.fd], ebx ;objects list - mov [eax+APPOBJ.bk], edx - mov [edx+APPOBJ.fd], eax - mov [ebx+APPOBJ.bk], eax - popfd -.done: - ret - -.destroy: - call destroy_event.force - ret -.switch: - mov eax, [TASK_BASE] - mov [eax+TASKDATA.state], byte 5 - call change_task - jmp .wait -endp - -; param -; eax= event -; ebx= id align 4 -wait_event: - .event equ esp - push eax -.wait: - cmp [eax+APPOBJ.magic], 'EVNT' - jne .done - cmp [eax+EVENT.id], ebx - jne .done - - test [eax+EVENT.state], EVENT_SIGNALED - jz .switch - - test [eax+EVENT.state], MANUAL_RESET - jnz .done - - mov edx,[current_slot] - - pushfd - cli ;remove event from events - mov ebx, [eax+APPOBJ.fd] ;list (reset event) - mov ecx, [eax+APPOBJ.bk] ;and clear events flag - mov [ebx+APPOBJ.bk], ecx ;if no active events - mov [ecx+APPOBJ.fd], ebx - dec [edx+APPDATA.ev_count] - jnz @F - and [edx+APPDATA.event_mask], not EVENT_EXTENDED -@@: - and [eax+EVENT.state], not (EVENT_SIGNALED+EVENT_WATCHED) - popfd - - test [eax+EVENT.state], MANUAL_DESTROY - jz .destroy - - add edx, APP_OBJ_OFFSET - - pushfd - cli - mov ecx, [edx+APPOBJ.fd] ;insert event into - mov [eax+APPOBJ.fd], ecx ;objects list - mov [eax+APPOBJ.bk], edx - mov [edx+APPOBJ.fd], eax - mov [ecx+APPOBJ.bk], eax - popfd -.done: - add esp, 4 - ret -.destroy: - call destroy_event.force - add esp, 4 - ret -.switch: - or [eax+EVENT.state], EVENT_WATCHED - mov eax, [TASK_BASE] - mov [eax+TASKDATA.state], byte 5 - call change_task - mov eax, [.event] - jmp .wait -restore .event - -; param -; eax= event -; ebx= id -; ecx= flags -; edx= event data - -raise_event: - .event equ esp - push eax - - cmp [eax+APPOBJ.magic], 'EVNT' - jne .fail - cmp [eax+EVENT.id], ebx - jne .fail - - mov eax, [eax+APPOBJ.pid] - call pid_to_slot - test eax, eax - jz .fail - - mov esi, edx - test esi, esi - mov edx, [.event] - jz @F - - push ecx - lea edi, [edx+EVENT.code] - mov ecx, 6 - cld - rep movsd - pop ecx -@@: - test [edx+EVENT.state], EVENT_SIGNALED - jnz .done - - test ecx, EVENT_WATCHED - jz @F - test [edx+EVENT.state], EVENT_WATCHED - jz .done -@@: - shl eax, 8 - add eax, SLOT_BASE+APP_EV_OFFSET - - pushfd - cli - mov ebx, [edx+APPOBJ.fd] - mov ecx, [edx+APPOBJ.bk] - mov [ebx+APPOBJ.bk], ecx - mov [ecx+APPOBJ.fd], ebx - - mov ecx, [eax+APPOBJ.fd] - mov [edx+APPOBJ.fd], ecx - mov [edx+APPOBJ.bk], eax - mov [eax+APPOBJ.fd], edx - mov [ecx+APPOBJ.bk], edx - or [edx+EVENT.state], EVENT_SIGNALED - - inc [eax+APPDATA.ev_count-APP_EV_OFFSET] - or [eax+APPDATA.event_mask-APP_EV_OFFSET], EVENT_EXTENDED - popfd -.fail: -.done: - add esp, 4 - ret -restore .event - -; param -; eax= event -; ebx= id -align 4 -clear_event: - .event equ esp - push eax - - cmp [eax+APPOBJ.magic], 'EVNT' - jne .fail - cmp [eax+EVENT.id], ebx - jne .fail - - mov eax, [eax+APPOBJ.pid] - call pid_to_slot - test eax, eax - jz .fail - - shl eax, 8 - add eax, SLOT_BASE+APP_EV_OFFSET - mov edx, [.event] - pushfd - cli ;remove event from events - mov ebx, [edx+APPOBJ.fd] ;list (reset event) - mov ecx, [edx+APPOBJ.bk] ;and clear events flag - mov [ebx+APPOBJ.bk], ecx ;if no active events - mov [ecx+APPOBJ.fd], ebx - - and [edx+EVENT.state], not (EVENT_SIGNALED+EVENT_WATCHED) - - dec [eax+APPDATA.ev_count-APP_EV_OFFSET] - jnz @F - and [eax+APPDATA.event_mask-APP_EV_OFFSET], not EVENT_EXTENDED -@@: - add eax, (APP_OBJ_OFFSET-APP_EV_OFFSET) - - mov ecx, [eax+APPOBJ.fd] ;insert event into - mov [edx+APPOBJ.fd], ecx ;objects list - mov [edx+APPOBJ.bk], eax - mov [eax+APPOBJ.fd], edx - mov [ecx+APPOBJ.bk], edx - popfd -.fail: -.done: - add esp, 4 - ret -restore .event - -sys_getevent: - - call get_event_for_app - mov [esp + 32],eax - ret - -sys_waitforevent: - or ebx, 0xFFFFFFFF ; infinite timeout - jmp @f - -sys_wait_event_timeout: - add ebx, [timer_ticks] -@@: - mov eax, [current_slot] - mov [eax + APPDATA.wait_timeout], ebx - call get_event_for_app - test eax, eax - jnz eventoccur - - mov eax, [TASK_BASE] - mov [eax+TASKDATA.state], byte 5 +Wait_events: + or ebx,-1 ; infinite timeout +Wait_events_ex: +;info: +; Ожидание "абстрактного" события через перевод слота в 5-ю позицию. +; Абстрактность заключена в том, что факт события определяется функцией APPDATA.wait_test, +; которая задается клиентом и может быть фактически любой. +; Это позволяет shed-у надежно определить факт события, и не совершать "холостых" переключений, +; предназначенных для разборок типа "свой/чужой" внутри задачи. +;param: +; edx - wait_test, клиентская ф-я тестирования (адрес кода) +; ecx - wait_param, дополнительный параметр, возможно необходимый для [wait_test] +; ebx - wait_timeout +;retval: +; eax - результат вызова [wait_test] (=0 => timeout) +;scratched: esi + mov esi,[current_slot] + mov [esi+APPDATA.wait_param],ecx + pushad + mov ebx,esi;пока это вопрос, чего куды сувать.......... + pushfd ; это следствие общей концепции: пусть ф-я тестирования имеет + cli ; право рассчитывать на закрытые прерывания, как при вызове из shed + call edx + popfd + mov [esp+28],eax + popad + or eax,eax + jnz @f ;RET + mov [esi+APPDATA.wait_test],edx + mov [esi+APPDATA.wait_timeout],ebx + Mov [esi+APPDATA.wait_begin],eax,[timer_ticks] + mov eax,[TASK_BASE] + mov [eax+TASKDATA.state], 5 call change_task + mov eax,[esi+APPDATA.wait_param] + @@: ret - mov eax, [event_sched] -eventoccur: - mov [esp+32], eax - ret +align 4 +wait_event: ;; EXPORT use +;info: +; Ожидание флага EVENT_SIGNALED в совершенно конкретном Event +; (устанавливаемого, надо полагать, через raise_event) +; При активном флаге MANUAL_RESET - больше ничего +; Иначе: флаги EVENT_SIGNALED и EVENT_WATCHED у полученного события сбрасываются, +; и, при активном MANUAL_DESTROY - перемещается в список ObjList текущего слота, +; а при не активном - уничтожается штатно (destroy_event.internal) +;param: +; eax - event +; ebx - uid (for Dummy testing) +;scratched: ecx,edx,esi + call DummyTest + mov ecx,eax ; wait_param + mov edx, get_event_alone ; wait_test + call Wait_events ; timeout ignored + jmp wait_finish -sys_sendwindowmsg: - dec eax - jnz .ret - cmp ebx, 3 - jz .sendbtn - cmp ebx, 2 - jnz .ret -.sendkey: - pushf +align 4 +get_event_ex: ;; f68:14 +;info: +; Ожидание любого события в очереди EventList текущего слота +; Данные события code - копируются в память приложения (косвенно по edi) +; При активном флаге MANUAL_RESET - больше ничего +; Иначе: флаги EVENT_SIGNALED и EVENT_WATCHED у полученного события сбрасываются, +; и, при активном MANUAL_DESTROY - перемещается в список ObjList текущего слота, +; а при не активном - уничтожается штатно (destroy_event.internal) +;param: +; edi - адрес в коде приложения для копирования данных из EVENT.code +;retval: +; eax - собственно EVENT (будем называть это его хэндлом) +;scratched: ebx,ecx,edx,esi,edi + mov edx, get_event_queue ; wait_test + call Wait_events ; timeout ignored + lea esi,[eax+EVENT.code] + mov ecx,EVENT.codesize/4 + cld + rep movsd + mov [edi-EVENT.codesize+2],cl ;clear priority field +wait_finish: + test byte[eax+EVENT.state+3], MANUAL_RESET shr 24 + jnz get_event_queue.ret ; RET + and byte[eax+EVENT.state+3], not((EVENT_SIGNALED+EVENT_WATCHED)shr 24) + test byte[eax+EVENT.state+3], MANUAL_DESTROY shr 24 + jz destroy_event.internal + mov ebx,[current_slot] + add ebx,APP_OBJ_OFFSET + pushfd cli - movzx eax, byte [KEY_COUNT] - cmp al, 120 - jae .overflow - inc eax - mov [KEY_COUNT], al - mov [KEY_COUNT+eax], cl - jmp .ok -.overflow: - popf - mov dword [esp+36], 1 - ret + jmp RemoveEventTo + +align 4 +destroy_event: ;; EXPORT use +;info: +; Переносим EVENT в список FreeEvents, чистим поля magic,destroy,pid,id +;param: +; eax - event +; ebx - uid (for Dummy testing) +;retval: +; eax - адрес объекта EVENT (=0 => fail) +;scratched: ebx,ecx + call DummyTest ; not returned for fail !!! +.internal: + xor ecx,ecx ; clear common header + pushfd + cli + mov [eax+EVENT.magic],ecx + mov [eax+EVENT.destroy],ecx + mov [eax+EVENT.pid],ecx + mov [eax+EVENT.id],ecx + mov ebx,FreeEvents + jmp RemoveEventTo + +align 4 +get_event_queue: +;info: +; клиентская ф-я тестирования для get_event_ex +;warning: +; -don't use [TASK_BASE],[current_slot],[CURRENT_TASK] - it is not for your slot +; -may be assumed, that interrupt are disabled +; -it is not restriction for scratched registers +;param: +; ebx - адрес APPDATA слота тестирования +;retval: +; eax - адрес объекта EVENT (=0 => fail) + add ebx,APP_EV_OFFSET + mov eax,[ebx+APPOBJ.bk] ; выбираем с конца, по принципу FIFO + cmp eax,ebx ; empty ??? + je get_event_alone.ret0 +.ret: ret + +align 4 +get_event_alone: +;info: +; клиентская ф-я тестирования для wait_event +;warning: +; -don't use [TASK_BASE],[current_slot],[CURRENT_TASK] - it is not for your slot +; -may be assumed, that interrupt are disabled +; -it is not restriction for scratched registers +;param: +; ebx - адрес APPDATA слота тестирования +;retval: +; eax - адрес объекта EVENT (=0 => fail) + mov eax,[ebx+APPDATA.wait_param] + test byte[eax+EVENT.state+3], EVENT_SIGNALED shr 24 + jnz .ret + or byte[eax+EVENT.state+3], EVENT_WATCHED shr 24 +.ret0: xor eax,eax ; NO event!!! +.ret: ret + +align 4 +sys_sendwindowmsg: ;; f72 + dec ebx + jnz .ret ;subfunction==1 ? + ;pushfd ;а нафига? + cli + sub ecx,2 + je .sendkey + loop .retf .sendbtn: - pushf - cli - cmp byte [BTN_COUNT], 0 - jnz .overflow - mov byte [BTN_COUNT], 1 - mov [BTN_BUFF], ecx -.ok: - popf - and dword [esp+36], 0 -.ret: + cmp byte[BTN_COUNT],1 + jae .result ;overflow + inc byte[BTN_COUNT] + mov [BTN_BUFF],edx + jmp .result +.sendkey: + movzx eax,byte[KEY_COUNT] + cmp al,120 + jae .result ;overflow + inc byte[KEY_COUNT] + mov [KEY_COUNT+1+eax],dl +.result: + setae byte[esp+32] ;считаем, что исходно: dword[esp+32]==72 +.retf: ;popfd +.ret: ret + +align 4 +sys_getevent: ;; f11 + mov ebx,[current_slot] ;пока это вопрос, чего куды сувать.......... + pushfd ; это следствие общей концепции: пусть ф-я тестирования имеет + cli ; право рассчитывать на закрытые прерывания, как при вызове из shed + call get_event_for_app + popfd + mov [esp+32],eax ret -get_event_for_app: +align 4 +sys_waitforevent: ;; f10 + or ebx,-1 ; infinite timeout +sys_wait_event_timeout: ;; f23 + mov edx,get_event_for_app ; wait_test + call Wait_events_ex ; ebx - timeout + mov [esp+32],eax + ret - pushad - - mov edi,[TASK_BASE] ; WINDOW REDRAW - test [edi+TASKDATA.event_mask], 1 - jz no_eventoccur1 - ;mov edi,[TASK_BASE] - cmp [edi-twdw+WDATA.fl_redraw],byte 0 - je no_eventoccur1 - popad - mov eax,1 - ret - no_eventoccur1: - - ;mov edi,[TASK_BASE] ; KEY IN BUFFER - test [edi+TASKDATA.event_mask],dword 2 - jz no_eventoccur2 - mov ecx, [CURRENT_TASK] - movzx edx,word [WIN_STACK+ecx*2] - mov eax, [TASK_COUNT] - cmp eax,edx - jne no_eventoccur2x - cmp [KEY_COUNT],byte 0 - je no_eventoccur2x - eventoccur2: - popad - mov eax,2 - ret - no_eventoccur2x: - mov eax, hotkey_buffer -@@: - cmp [eax], ecx - jz eventoccur2 - add eax, 8 - cmp eax, hotkey_buffer+120*8 +align 4 +get_event_for_app: ;; used from f10,f11,f23 +;info: +; клиентская ф-я тестирования для приложений (f10,f23) +;warning: +; -don't use [TASK_BASE],[current_slot],[CURRENT_TASK] - it is not for your slot +; -may be assumed, that interrupt are disabled +; -it is not restriction for scratched registers +;param: +; ebx - адрес APPDATA слота тестирования +;retval: +; eax - номер события (=0 => no events) + movzx edi,bh ; bh is assumed as [CURRENT_TASK] + shl edi,5 + add edi,CURRENT_TASK ; edi is assumed as [TASK_BASE] + mov ecx,[edi+TASKDATA.event_mask] +.loop: ; пока не исчерпаем все биты маски + bsr eax,ecx ; находим ненулевой бит маски (31 -> 0) + jz .no_events ; исчерпали все биты маски, но ничего не нашли ??? + btr ecx,eax ; сбрасываем проверяемый бит маски + ; переходим на обработчик этого (eax) бита + cmp eax,16 + jae .IRQ ; eax=[16..31]=retvals, events irq0..irq15 + cmp eax,9 + jae .loop ; eax=[9..15], ignored + cmp eax,3 + je .loop ; eax=3, ignored + ja .FlagAutoReset ; eax=[4..8], retvals=eax+1 + cmp eax,1 + jae .BtKy ; eax=[1,2], retvals=eax+1 +.WndRedraw: ; eax=0, retval WndRedraw=1 + cmp [edi-twdw+WDATA.fl_redraw],al ;al==0 + jne .result + jmp .loop + .no_events: + xor eax,eax + ret +.IRQ: +;TODO: сделать так же, как и для FlagAutoReset (BgrRedraw,Mouse,IPC,Stack,Debug) + mov edx,[irq_owner+eax*4-64] ; eax==16+irq + cmp edx,[edi+TASKDATA.pid] + jne .loop + mov edx,eax + shl edx,12 + cmp dword[IRQ_SAVE+edx-0x10000],0 ; edx==(16+irq)*0x1000 + je .loop ; empty ??? + ret ; retval = eax +.FlagAutoReset: ; retvals: BgrRedraw=5, Mouse=6, IPC=7, Stack=8, Debug=9 + btr [ebx+APPDATA.event_mask],eax + jnc .loop + .result: ; retval = eax+1 + inc eax + ret + .BtKy: + movzx edx,bh + movzx edx, word[WIN_STACK+edx*2] + je .Keys ; eax=1, retval Keys=2 +.Buttons: ; eax=2, retval Buttons=3 + cmp byte[BTN_COUNT],0 + je .loop ; empty ??? + cmp edx,[TASK_COUNT] + jne .loop ; not Top ??? + cmp dword[BTN_BUFF],0xFFFF ;-ID for Minimize-Button of Form + jne .result + mov [window_minimize],1 + dec byte[BTN_COUNT] + jmp .loop +.Keys: ; eax==1 + cmp edx,[TASK_COUNT] + jne @f ; not Top ??? + cmp [KEY_COUNT],al ; al==1 + jae .result ; not empty ??? + @@: mov edx, hotkey_buffer + @@: cmp [edx],bh ; bh - slot for testing + je .result + add edx,8 + cmp edx, hotkey_buffer+120*8 jb @b - no_eventoccur2: - - ;mov edi,[TASK_BASE] ; BUTTON IN BUFFER - test [edi+TASKDATA.event_mask],dword 4 - jz no_eventoccur3 - cmp [BTN_COUNT],byte 0 - je no_eventoccur3 - mov ecx, [CURRENT_TASK] - movzx edx, word [WIN_STACK+ecx*2] - mov eax, [TASK_COUNT] - cmp eax,edx - jnz no_eventoccur3 - popad - mov eax,[BTN_BUFF] - cmp eax,65535 - je no_event_1 - mov eax,3 - ret - - no_event_1: - mov [window_minimize],1 - mov [BTN_COUNT],byte 0 - xor eax, eax - ret - -no_eventoccur3: - - ;mov edi,[TASK_BASE] ; mouse event - mov eax, [CURRENT_TASK] - shl eax, 8 - add eax, SLOT_BASE - test [edi+TASKDATA.event_mask],dword 00100000b - jz no_mouse_event - - test [eax+APPDATA.event_mask],dword 00100000b - jz no_mouse_event - and [eax+APPDATA.event_mask],dword (not 00100000b) - popad - mov eax,6 - ret -no_mouse_event: - - ;mov edi,[TASK_BASE] ; DESKTOP BACKGROUND REDRAW - test [edi+TASKDATA.event_mask], 16 - jz no_eventoccur5 -; cmp [REDRAW_BACKGROUND],byte 2 -; jnz no_eventoccur5 - test [eax+APPDATA.event_mask], 16 - jz no_eventoccur5 - and [eax+APPDATA.event_mask], not 16 - popad - mov eax,5 - ret -no_eventoccur5: - - ;mov edi,[TASK_BASE] ; IPC - test [edi+TASKDATA.event_mask],dword 01000000b - jz no_ipc - test [eax+APPDATA.event_mask],dword 01000000b - jz no_ipc - and [eax+APPDATA.event_mask],dword 0xffffffff-01000000b - popad - mov eax,7 - ret -no_ipc: - - ;mov edi,[TASK_BASE] ; STACK - test [edi+TASKDATA.event_mask],dword 10000000b - jz no_stack_event - test [eax+APPDATA.event_mask],dword 10000000b - jz no_stack_event - and [eax+APPDATA.event_mask],dword 0xffffffff-10000000b - popad - mov eax,8 - ret -no_stack_event: - - test byte [edi+TASKDATA.event_mask+1], 1 ; DEBUG - jz .test_IRQ - test byte [eax+APPDATA.event_mask+1], byte 1 - jz .test_IRQ - and byte [eax+APPDATA.event_mask+1], not 1 - popad - mov eax, 9 - ret - -;.test_ext: -; mov eax, [CURRENT_TASK] -; shl eax, 8 -; test dword [eax+SLOT_BASE+APPDATA.event_mask], EVENT_EXTENDED -; jz .test_IRQ -; popad -; mov eax, 10 -; ret - -.test_IRQ: - cmp dword [edi+TASKDATA.event_mask], 0xFFFF - jbe no_events - - mov esi,IRQ_SAVE ; IRQ'S AND DATA - mov ebx,0x00010000 - xor ecx, ecx - irq_event_test: - mov edi,[TASK_BASE] - test [edi+TASKDATA.event_mask],ebx - jz no_irq_event - mov edi,ecx - shl edi,2 - add edi,irq_owner - mov edx,[edi] - mov eax,[TASK_BASE] - mov eax,[eax+TASKDATA.pid] - cmp edx,eax - jne no_irq_event - cmp [esi],dword 0 - jz no_irq_event - mov eax,ecx - add eax,16 - mov [esp+28],eax - popad - ret - no_irq_event: - add esi,0x1000 - shl ebx,1 - inc ecx - cmp ecx,16 - jb irq_event_test - - no_events: - popad - xor eax, eax - ret - - - + jmp .loop +;end. diff --git a/kernel/branches/net/gui/window.inc b/kernel/branches/net/gui/window.inc index 4eebc3beb8..521c7f3627 100644 --- a/kernel/branches/net/gui/window.inc +++ b/kernel/branches/net/gui/window.inc @@ -1166,10 +1166,10 @@ restore_minimized_window: ret -iglobal - window_moving db 'K : Window - move/resize',13,10,0 - window_moved db 'K : Window - done',13,10,0 -endg +;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 @@ -1316,10 +1316,10 @@ endg .continue: - push esi - mov esi, window_moving - call sys_msg_board_str - pop esi +; push esi +; mov esi, window_moving +; call sys_msg_board_str +; pop esi mov ecx, [timer_ticks] ; double-click ? mov edx, ecx @@ -1684,8 +1684,8 @@ endg 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 +; mov esi,window_moved +; call sys_msg_board_str popad diff --git a/kernel/branches/net/init.inc b/kernel/branches/net/init.inc index e72b2138fc..7dc1b3134b 100644 --- a/kernel/branches/net/init.inc +++ b/kernel/branches/net/init.inc @@ -14,6 +14,9 @@ MEM_UC equ 0 ;uncached memory align 4 proc mem_test +; if we have BIOS with fn E820, skip the test + cmp dword [BOOT_VAR-OS_BASE + 0x9100], 0 + jnz .ret mov eax, cr0 and eax, not (CR0_CD+CR0_NW) @@ -29,37 +32,91 @@ proc mem_test cmp dword [edi], 'TEST' xchg ebx, dword [edi] je @b - mov [MEM_AMOUNT-OS_BASE], edi and eax, not (CR0_CD+CR0_NW) ;enable caching mov cr0, eax - mov eax, edi + inc dword [BOOT_VAR-OS_BASE + 0x9100] + xor eax, eax + mov [BOOT_VAR-OS_BASE + 0x9104], eax + mov [BOOT_VAR-OS_BASE + 0x9108], eax + mov [BOOT_VAR-OS_BASE + 0x910C], edi + mov [BOOT_VAR-OS_BASE + 0x9110], eax +.ret: ret endp align 4 proc init_mem - mov eax, [MEM_AMOUNT-OS_BASE] - mov [pg_data.mem_amount-OS_BASE], eax - - shr eax, 12 +; calculate maximum allocatable address and number of allocatable pages + mov edi, BOOT_VAR-OS_BASE + 0x9104 + mov ecx, [edi-4] + xor esi, esi ; esi will hold total amount of memory + xor edx, edx ; edx will hold maximum allocatable address +.calcmax: +; round all to pages + mov eax, [edi] + test eax, 0xFFF + jz @f + neg eax + and eax, 0xFFF + add [edi], eax + adc dword [edi+4], 0 + sub [edi+8], eax + sbb dword [edi+12], 0 + jc .unusable +@@: + and dword [edi+8], not 0xFFF + jz .unusable +; ignore memory after 4 Gb + cmp dword [edi+4], 0 + jnz .unusable + mov eax, [edi] + cmp dword [edi+12], 0 + jnz .overflow + add eax, [edi+8] + jnc @f +.overflow: + mov eax, 0xFFFFF000 +@@: + cmp edx, eax + jae @f mov edx, eax - mov [pg_data.pages_count-OS_BASE], eax - shr eax, 3 - mov [pg_data.pagemap_size-OS_BASE], eax +@@: + sub eax, [edi] + mov [edi+8], eax + add esi, eax + jmp .usable +.unusable: + and dword [edi+8], 0 +.usable: + add edi, 20 + loop .calcmax +.calculated: + mov [MEM_AMOUNT-OS_BASE], esi + mov [pg_data.mem_amount-OS_BASE], esi + shr esi, 12 + mov [pg_data.pages_count-OS_BASE], esi - add eax, (sys_pgmap-OS_BASE)+4095 - and eax, not 4095 - mov [tmp_page_tabs], eax + shr edx, 12 + add edx, 31 + and edx, not 31 + shr edx, 3 + mov [pg_data.pagemap_size-OS_BASE], edx + add edx, (sys_pgmap-OS_BASE)+4095 + and edx, not 4095 + mov [tmp_page_tabs], edx + + mov edx, esi + and edx, -1024 cmp edx, (OS_BASE/4096) jbe @F mov edx, (OS_BASE/4096) jmp .set @@: - cmp edx, (HEAP_MIN_SIZE/4096) + cmp edx, (HEAP_BASE+HEAP_MIN_SIZE)/4096 jae .set - mov edx, (HEAP_MIN_SIZE/4096) + mov edx, (HEAP_BASE+HEAP_MIN_SIZE)/4096 .set: mov [pg_data.kernel_pages-OS_BASE], edx shr edx, 10 @@ -130,14 +187,63 @@ endp align 4 proc init_page_map - +; mark all memory as unavailable mov edi, sys_pgmap-OS_BASE mov ecx, [pg_data.pagemap_size-OS_BASE] shr ecx, 2 - or eax, -1 + xor eax, eax cld rep stosd +; scan through memory map and mark free areas as available + mov ebx, BOOT_VAR-OS_BASE + 0x9104 + mov edx, [ebx-4] +.scanmap: + mov ecx, [ebx+8] + shr ecx, 12 ; ecx = number of pages + jz .next + mov edi, [ebx] + shr edi, 12 ; edi = first page + mov eax, edi + neg eax + shr edi, 5 + add edi, sys_pgmap-OS_BASE + and eax, 31 + jz .startok + sub ecx, eax + jbe .onedword + push ecx + mov ecx, eax + xor eax, eax + inc eax + shl eax, cl + dec eax + or [edi], eax + add edi, 4 + pop ecx +.startok: + push ecx + shr ecx, 5 + or eax, -1 + rep stosd + pop ecx + and ecx, 31 + not eax + shl eax, cl + or [edi], eax + jmp .next +.onedword: + add ecx, eax +@@: + dec eax + bts [edi], eax + loop @b +.next: + add ebx, 20 + dec edx + jnz .scanmap + +; mark kernel memory as allocated (unavailable) mov ecx, [tmp_page_tabs] mov edx, [pg_data.pages_count-OS_BASE] shr ecx, 12 @@ -155,7 +261,7 @@ proc init_page_map mov ecx, ebx and ecx, 31 shl eax, cl - mov [edi], eax + and [edi], eax add edi, OS_BASE mov [page_start-OS_BASE], edi; diff --git a/kernel/branches/net/kernel.asm b/kernel/branches/net/kernel.asm index d15e2cf3d0..400c484e27 100644 --- a/kernel/branches/net/kernel.asm +++ b/kernel/branches/net/kernel.asm @@ -59,23 +59,24 @@ include 'macros.inc' $Revision: 1025 $ -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 -debug_com_base equ 0x3f8 ; 0x3f8 is com1, 0x2f8 is com2, 0x3e8 is com3, 0x2e8 is com4, no irq's are used, comment this line out to disable +; 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 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) pci_code_sel equ (pci_code_32-gdts) @@ -113,8 +114,8 @@ 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 @@ -125,10 +126,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 @@ -146,58 +147,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" @@ -206,65 +207,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 - xor edi, edi - mov ecx,0x10000 / 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 @@ -280,45 +281,45 @@ 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 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,bx + 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 + 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 + ; protected-mode 32-bit code segment movzx ecx, word [BOOT_VAR+0x9052] ; real-mode segment base address of - ; protected-mode 16-bit code segment + ; protected-mode 16-bit code segment movzx edx, word [BOOT_VAR+0x9054] ; real-mode segment base address of - ; protected-mode 16-bit data segment + ; protected-mode 16-bit data segment shl eax, 4 mov [dword apm_code_32 + 2], ax @@ -343,241 +344,240 @@ high_code: ; ----------------------------------------- ; 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 + mov al,[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 + 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 esi, BOOT_VAR+0x9080 - movzx ecx, byte [esi-1] - mov [NumBiosDisks], ecx - mov edi, BiosDisksData - rep movsd + 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 + mov 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: ; ----------------------------------------- ; LOAD IDT - call build_interrupt_table - 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 + mov [CURRENT_TASK],dword 1 + mov [TASK_COUNT],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],4095 - stdcall kernel_alloc, [mem_BACKGROUND] - mov [img_background], eax + 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 [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 +593,7 @@ include 'boot/rdload.inc' ; mov [dma_hdd],1 ; CALCULATE FAT CHAIN FOR RAMDISK - call calculatefatchain + call calculatefatchain ; LOAD VMODE DRIVER @@ -602,239 +602,254 @@ include 'vmodeld.inc' ;!!!!!!!!!!!!!!!!!!!!!!! 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: ; 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 + mov edi, 1 + mov eax, 0x00040000 + 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 setwindowdefaults ; 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.fpu_handler], eax - mov dword [SLOT_BASE+APPDATA.sse_handler], 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 + 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 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.fpu_handler], eax - mov dword [SLOT_BASE+256+APPDATA.sse_handler], 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 - ; 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 [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 - call init_cursors + call init_cursors mov eax, [def_cursor] - mov [SLOT_BASE+APPDATA.cursor],eax - mov [SLOT_BASE+APPDATA.cursor+256],eax + mov [SLOT_BASE+APPDATA.cursor],eax + mov [SLOT_BASE+APPDATA.cursor+256],eax ; READ TSC / SECOND - mov esi,boot_tsc - call boot_log - cli - call _rdtsc - mov ecx,eax - mov esi,250 ; wait 1/4 a second - call delay_ms - call _rdtsc - sti - sub eax,ecx - shl eax,2 - mov [CPU_FREQ],eax ; save tsc / sec - mov ebx, 1000000 - div ebx - mov [stall_mcs], eax + 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 +; PRINT CPU FREQUENCY + 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 ; SET VARIABLES - call set_variables + call set_variables ; SET MOUSE - ;call detect_devices - stdcall load_driver, szPS2MDriver - stdcall load_driver, szCOM_MDriver + ;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 + 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 ax,[OS_BASE+0x10000+bx_from_load] + 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 ; 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) + je 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 + je 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 + mov [CURRENT_TASK],dword 1 ; 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 @@ -843,14 +858,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 ] @@ -898,72 +913,72 @@ 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 + mov edx,esi + mov edi,1 + call dtext - mov [novesachecksum],1000 - call checkVga_N13 + mov [novesachecksum],1000 + call checkVga_N13 - popad + popad - ret + ret ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -973,79 +988,51 @@ boot_log: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; align 32 osloop: - call [draw_pointer] - call checkbuttons - call checkwindows + call [draw_pointer] + call checkbuttons + 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 ; ; ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - +align 4 checkidle: - pushad - - cmp [check_idle_semaphore],0 - jne no_idle_state - - call change_task - mov eax,[idlemem] - mov ebx,[timer_ticks] ;[0xfdf0] - cmp eax,ebx - jnz idle_exit - call _rdtsc - mov ecx,eax - idle_loop: - hlt - cmp [check_idle_semaphore],0 - jne idle_loop_exit - mov eax,[timer_ticks] ;[0xfdf0] - cmp ebx,eax - jz idle_loop - idle_loop_exit: - mov [idlemem],eax - call _rdtsc - sub eax,ecx - mov ebx,[idleuse] - add ebx,eax - mov [idleuse],ebx - - popad - ret - - idle_exit: - - mov ebx,[timer_ticks] ;[0xfdf0] - mov [idlemem],ebx - call change_task - - popad - ret - - no_idle_state: - - dec [check_idle_semaphore] - - mov ebx,[timer_ticks] ;[0xfdf0] - mov [idlemem],ebx - call change_task - - popad - ret + 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 + idle_loop_entry: + 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 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 @@ -1068,57 +1055,57 @@ include "kernel32.inc" reserve_irqs_ports: - pushad + pushad - 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 + 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 - 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 + ; 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 - 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 + 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 - 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 + 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 - 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 + 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 - popad - ret + popad + 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 + 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 @@ -1126,49 +1113,48 @@ 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 + mov [MOUSE_BUFF_COUNT],byte 0 ; mouse buffer + mov [KEY_COUNT],byte 0 ; keyboard buffer + mov [BTN_COUNT],byte 0 ; 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 + 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 [next_usage_update], 100 - mov byte [DONT_SWITCH], 0 ; change task if possible + mov byte [DONT_SWITCH], 0 ; change task if possible - ret + 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 + 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 align 4 sys_outport: - mov edi,ebx ; separate flag for read / write + mov edi,ebx ; separate flag for read / write and ebx,65535 mov ecx,[RESERVED_PORTS] @@ -1190,9 +1176,9 @@ sys_outport: cmp edx,[esi+0] jne sopl2 cmp ebx,[esi+4] - jb sopl2 + jb sopl2 cmp ebx,[esi+8] - jg sopl2 + jg sopl2 jmp sopl3 sopl2: @@ -1207,15 +1193,15 @@ sys_outport: test edi,0x80000000 ; read ? jnz sopl4 - mov dx,bx ; write + mov dx,bx ; write out dx,al mov [esp+36],dword 0 ret sopl4: - mov dx,bx ; read - in al,dx + mov dx,bx ; read + in al,dx and eax,0xff mov [esp+36],dword 0 mov [esp+24],eax @@ -1234,18 +1220,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 ? + 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 @@ -1253,7 +1239,7 @@ 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 @@ -1262,7 +1248,7 @@ display_number_force: displnl1: sub esp,64 - cmp ah,0 ; DECIMAL + cmp ah,0 ; DECIMAL jne no_display_desnum shr eax,16 and eax,0xC03f @@ -1290,7 +1276,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,6 +1292,7 @@ display_number_force: xor edx,edx call division_64_bits div ebx + hexletters = __fdo_hexdigits add edx,hexletters mov dl,[edx] mov [edi],dl @@ -1319,7 +1306,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 @@ -1398,9 +1385,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 @@ -1420,7 +1407,7 @@ sys_setup: mov [esp+36],dword 0 - cmp eax,1 ; MIDI + cmp eax,1 ; MIDI jnz nsyse1 cmp ebx,0x100 jb nsyse1 @@ -1439,7 +1426,7 @@ endg nsyse1: - cmp eax,2 ; KEYBOARD + cmp eax,2 ; KEYBOARD jnz nsyse2 cmp ebx,1 jnz kbnobase @@ -1479,7 +1466,7 @@ endg mov [esp+36],dword 1 ret nsyse2: - cmp eax,3 ; CD + cmp eax,3 ; CD jnz nsyse4 test ebx,ebx jz nosesl @@ -1512,13 +1499,13 @@ cd_base db 0 nsyse4: - cmp eax,5 ; SYSTEM LANGUAGE + cmp eax,5 ; SYSTEM LANGUAGE jnz nsyse5 mov [syslang],ebx ret nsyse5: - cmp eax,7 ; HD BASE + cmp eax,7 ; HD BASE jne nsyse7 test ebx,ebx jz nosethd @@ -1556,7 +1543,7 @@ cd_base db 0 call reserve_hd1 call reserve_hd_channel call free_hd_channel - mov [hd1_status],0 ; free + mov [hd1_status],0 ; free nosethd: ret @@ -1566,7 +1553,7 @@ endg nsyse7: - cmp eax,8 ; HD PARTITION + cmp eax,8 ; HD PARTITION jne nsyse8 mov [fat32part],ebx ; call set_FAT32_variables @@ -1576,11 +1563,11 @@ nsyse7: pusha call choice_necessity_partition_1 popa - mov [hd1_status],0 ; free + mov [hd1_status],0 ; free ret nsyse8: - cmp eax,11 ; ENABLE LBA READ + cmp eax,11 ; ENABLE LBA READ jne no_set_lba_read and ebx,1 mov [lba_read_enabled],ebx @@ -1712,10 +1699,10 @@ get_timer_ticks: 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: @@ -1729,107 +1716,107 @@ readmousepos: ; eax=6 delete cursor ; reserved ; eax=7 get mouse_z - cmp eax, 7 - ja msset - jmp [mousefn+eax*4] + cmp eax, 7 + ja msset + jmp [mousefn+eax*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],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],eax + ret msbutton: - movzx eax,byte [BTN_DOWN] - mov [esp+36],eax - ret + movzx eax,byte [BTN_DOWN] + mov [esp+36],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],eax + mov [MOUSE_SCROLL_H],word 0 + mov [MOUSE_SCROLL_V],word 0 + ret @@: - mov [esp+36],dword 0 - ret + mov [esp+36],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 ebx, OS_BASE + jae msset + stdcall load_cursor, ebx, ecx + mov [esp+36], eax + ret app_set_cursor: - stdcall set_cursor, ebx - mov [esp+36], eax - ret + stdcall set_cursor, ebx + mov [esp+36], eax + ret app_delete_cursor: - stdcall delete_cursor, ebx - mov [esp+36], eax - ret + stdcall delete_cursor, ebx + mov [esp+36], 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 @@ -1837,28 +1824,28 @@ setuart: su1: call is_output - cmp al,0 - jnz su1 - mov dx,word [midisp] - mov al,0xff - out dx,al + 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 + mov dx,word [midisp] + mov al,0xff + out dx,al call is_input - cmp al,0 - jnz su2 + cmp al,0 + jnz su2 call get_mpu_in - cmp al,0xfe - jnz su2 + cmp al,0xfe + jnz su2 su3: call is_output - cmp al,0 - jnz su3 - mov dx,word [midisp] - mov al,0x3f - out dx,al + cmp al,0 + jnz su3 + mov dx,word [midisp] + mov al,0x3f + out dx,al ret @@ -1911,7 +1898,7 @@ sys_end: 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 @@ -1919,42 +1906,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 @@ -1971,7 +1958,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] @@ -1985,7 +1972,7 @@ 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 @@ -2000,7 +1987,7 @@ sysfn_terminate2: .table_status: cli cmp [application_table_status],0 - je .stf + je .stf sti call change_task jmp .table_status @@ -2009,7 +1996,7 @@ 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 @@ -2019,10 +2006,10 @@ sysfn_terminate2: 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] @@ -2043,12 +2030,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 @@ -2058,13 +2045,13 @@ sysfn_getcpuclock: ; 18.5 = GET TSC/SEC include 'blkdev/rdsave.inc' ;!!!!!!!!!!!!!!!!!!!!!!!! -sysfn_getactive: ; 18.7 = get active window +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 +sysfn_sound_flag: ; 18.8 = get/set sound_flag cmp ecx,1 jne nogetsoundflag movzx eax,byte [sound_flag] ; get sound_flag @@ -2077,11 +2064,11 @@ sysfn_sound_flag: ; 18.8 = get/set sound_flag 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 +sysfn_getdiskinfo: ; 18.11 = get disk info table cmp ecx,1 jnz full_table small_table: @@ -2103,11 +2090,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 @@ -2125,7 +2112,7 @@ sysfn_waitretrace: ; 18.14 = sys wait retrace and [esp+32],dword 0 ret -sysfn_centermouse: ; 18.15 = mouse centered +sysfn_centermouse: ; 18.15 = mouse centered call mouse_centered and [esp+32],dword 0 ret @@ -2190,14 +2177,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 @@ -2225,7 +2212,7 @@ uglobal screen_workarea RECT ;// mike.dld, 2006-29-01 ] window_minimize db 0 -sound_flag db 0 +sound_flag db 0 endg iglobal @@ -2237,49 +2224,49 @@ 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 -bgrlock db 0 +align 4 bgrlockpid dd 0 +bgrlock db 0 endg sys_background: - cmp ebx,1 ; BACKGROUND SIZE + cmp ebx,1 ; BACKGROUND SIZE jnz nosb1 cmp ecx,0 - je sbgrr + je sbgrr cmp edx,0 - je sbgrr + je sbgrr @@: - mov al, 1 - xchg [bgrlock], al - test al, al - jz @f - call change_task - jmp @b +;;Maxis use atomic bts for mutexes 4.4.2009 + bts dword [bgrlock], 0 + jnc @f + call change_task + jmp @b @@: mov [BgrDataWidth],ecx mov [BgrDataHeight],edx @@ -2287,7 +2274,11 @@ sys_background: pushad ; return memory for old background - stdcall kernel_free, [img_background] + mov eax, [img_background] + cmp eax, static_background_data + jz @f + stdcall kernel_free, eax +@@: ; calculate RAW size xor eax,eax inc eax @@ -2306,38 +2297,52 @@ sys_background: ; get memory for new background stdcall kernel_alloc, eax test eax, eax - jz .exit_mem + jz .memfailed mov [img_background], eax -.exit_mem: + 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 +.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 + cmp eax, static_background_data + jz .ret +@@: mov ebx, [mem_BACKGROUND] add ebx, 4095 and ebx, -4096 sub ebx, 4 cmp ecx, ebx - ja @F + ja .ret - mov eax,[img_background] mov ebx,[eax+ecx] and ebx,0xFF000000 ;255*256*256*256 and edx,0x00FFFFFF ;255*256*256+255*256+255 add edx,ebx mov [eax+ecx],edx -@@: +.ret: ret nosb2: - cmp ebx,3 ; DRAW BACKGROUND + cmp ebx,3 ; DRAW BACKGROUND jnz nosb3 draw_background_temp: ; cmp [bgrchanged],1 ;0 @@ -2351,18 +2356,25 @@ 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 + @@: ; bughere mov eax, ecx mov ebx, edx @@ -2373,85 +2385,86 @@ draw_background_temp: ret nosb5: - cmp ebx, 6 - jnz nosb6 + cmp ebx, 6 + jnz nosb6 +;;Maxis use atomic bts for mutex 4.4.2009 @@: - mov al, 1 - xchg [bgrlock], al - test al, al - jz @f - call change_task - jmp @b + bts dword [bgrlock], 0 + jnc @f + call change_task + jmp @b @@: - mov eax, [CURRENT_TASK] - mov [bgrlockpid], eax - 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 @@: - and dword [page_tabs+eax*4], 0 - mov edx, eax - shl edx, 12 + and dword [page_tabs+eax*4], 0 + mov edx, eax + shl edx, 12 push eax - invlpg [edx] + 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 + 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 @@ -2472,7 +2485,7 @@ align 4 sys_getbackground: - cmp eax,1 ; SIZE + cmp eax,1 ; SIZE jnz nogb1 mov eax,[BgrDataWidth] shl eax,16 @@ -2482,26 +2495,31 @@ sys_getbackground: nogb1: - cmp eax,2 ; PIXEL + cmp eax,2 ; PIXEL jnz nogb2 + mov eax, [img_background] + test ebx, ebx + 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 @F + ja .ret - mov eax,[img_background] mov eax,[ebx+eax] and eax, 0xFFFFFF mov [esp+36],eax -@@: +.ret: ret nogb2: - cmp eax,4 ; TILED / STRETCHED + cmp eax,4 ; TILED / STRETCHED jnz nogb4 mov eax,[BgrDrawMode] nogb4: @@ -2512,71 +2530,71 @@ nogb1: 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 ; } \\ Alver \\ - mov [BTN_COUNT], byte 0 - mov [esp + 32], eax + mov [BTN_COUNT], byte 0 + mov [esp + 32], eax .exit: - ret + ret align 4 @@ -2594,78 +2612,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 @@ -2676,133 +2694,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: @@ -2824,7 +2842,7 @@ 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] @@ -2836,7 +2854,7 @@ sys_drawwindow: ret nosyswII: - cmp al,2 ; type III - new style + cmp al,2 ; type III - new style jne nosyswIII inc [mouse_pause] call [disable_mouse] @@ -2849,9 +2867,9 @@ 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: @@ -2876,180 +2894,180 @@ sys_drawwindow: draw_window_caption: - inc [mouse_pause] - call [disable_mouse] + inc [mouse_pause] + call [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: @@ -3083,41 +3101,39 @@ sys_set_window: call check_window_position - call set_window_clientbox - - 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 @@ -3129,11 +3145,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: - mov [edi+WDATA.fl_redraw],byte 0 ; no redraw + call set_window_clientbox + + mov [edi+WDATA.fl_redraw],byte 0 ; no redraw mov edx,edi ret @@ -3141,18 +3159,18 @@ sys_set_window: syscall_windowsettings: .set_window_caption: - dec eax ; subfunction #1 - set window caption - jnz .get_window_caption + dec eax ; subfunction #1 - set window caption + jnz .get_window_caption - ; 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] @@ -3160,115 +3178,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],ebx + 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 + 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 [dlx],eax ; save for drawlimits + mov [dly],ebx + mov [dlxe],ecx + mov [dlye],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 @@ -3340,22 +3358,22 @@ ret 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 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 - mov eax, esi - wrmsr - ; mov [esp + 36], eax - ; mov [esp + 24], edx ;ret in ebx? + mov eax, esi + wrmsr + ; mov [esp + 36], eax + ; mov [esp + 24], edx ;ret in ebx? @@: ret @@ -3397,27 +3415,27 @@ 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 + mov dl, [eax+edx+display_data] ; 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 @@ -3428,8 +3446,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 @@ -3438,24 +3456,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 @@ -3473,7 +3491,7 @@ nobackgr: ; system shutdown request cmp [SYS_SHUTDOWN],byte 0 - je noshutdown + je noshutdown mov edx,[shutdown_processes] @@ -3494,21 +3512,21 @@ markz: call [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 @@ -3522,152 +3540,144 @@ 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,[dlye] ; 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,[dlxe] ; 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,[dly] ; 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,[dlx] ; 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,[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: - 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,[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 - 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 - ; all black + mov edi,display_data ; set os to use all pixels + mov eax,0x01010101 + mov ecx,1280*1024 / 4 + rep stosd - mov edi, [img_background] ;IMG_BACKGROUND ; set background to black - xor eax, eax - mov ecx, 1023 ;0x0fff00 / 4 - cld - rep stosd + mov byte [REDRAW_BACKGROUND], 0 ; do not draw background! - mov edi,display_data ; set os to use all pixels - mov eax,0x01010101 - mov ecx,1280*1024 / 4 - rep stosd - - mov byte [REDRAW_BACKGROUND], 0 ; do not draw background! - - ret + ret uglobal - imax dd 0x0 + imax dd 0x0 endg @@ -3675,63 +3685,65 @@ 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 [edi + TASKDATA.event_mask], ebx - 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 + pop edx + pop ecx - ret + ret memmove: ; memory move in bytes @@ -3749,14 +3761,14 @@ memmove: ; memory move in bytes 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 @@ -3825,7 +3837,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 @@ -3848,11 +3860,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] @@ -3866,28 +3878,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 @@ -3904,11 +3916,11 @@ 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 @@ -3927,7 +3939,7 @@ set_io_access_rights: ; mov ebx,1 ; shl ebx,cl - cmp ebp,0 ; enable access - ebp = 0 + cmp ebp,0 ; enable access - ebp = 0 jne siar1 ; not ebx @@ -3958,14 +3970,14 @@ r_f_port_area: pushad - cmp ebx,ecx ; beginning > end ? + cmp ebx,ecx ; beginning > end ? ja rpal1 cmp ecx,65536 jae rpal1 mov esi,[RESERVED_PORTS] - test esi,esi ; no reserved areas ? + test esi,esi ; no reserved areas ? je rpal2 - cmp esi,255 ; max reserved + cmp esi,255 ; max reserved jae rpal1 rpal3: mov edi,esi @@ -3993,7 +4005,7 @@ r_f_port_area: ; enable port access at port IO map cli - pushad ; start enable io map + pushad ; start enable io map cmp ecx,65536 ;16384 jae no_unmask_io ; jge @@ -4004,7 +4016,7 @@ r_f_port_area: pushad - xor ebp,ebp ; enable - eax = port + xor ebp,ebp ; enable - eax = port call set_io_access_rights popad @@ -4015,7 +4027,7 @@ r_f_port_area: no_unmask_io: - popad ; end enable io map + popad ; end enable io map sti mov edi,[RESERVED_PORTS] @@ -4075,7 +4087,7 @@ free_port_area: ; disable port access at port IO map - pushad ; start disable io map + pushad ; start disable io map cmp ecx,65536 ;16384 jge no_mask_io @@ -4086,7 +4098,7 @@ free_port_area: pushad - mov ebp,1 ; disable - eax = port + mov ebp,1 ; disable - eax = port call set_io_access_rights popad @@ -4097,7 +4109,7 @@ free_port_area: no_mask_io: - popad ; end disable io map + popad ; end disable io map xor eax, eax ret @@ -4191,7 +4203,7 @@ drawbackground: align 4 -syscall_putimage: ; PutImage +syscall_putimage: ; PutImage sys_putimage: test ecx,0x80008000 jnz .exit @@ -4202,40 +4214,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] @@ -4243,12 +4255,12 @@ 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 @@ -4303,20 +4315,20 @@ sys_putimage_palette: 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 @@ -4335,53 +4347,53 @@ put_4bit_image: 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 @@ -4416,44 +4428,44 @@ putimage_get2bpp: 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: @@ -4500,25 +4512,25 @@ putimage_get16bpp: ; 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] @@ -4533,36 +4545,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 @@ -4572,75 +4584,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 @@ -4648,7 +4660,7 @@ setmouse: ; set mousepicture -pointer ret - +if used _rdtsc _rdtsc: bt [cpu_caps], CAPS_TSC jnc ret_rdtsc @@ -4658,63 +4670,64 @@ _rdtsc: mov edx,0xffffffff mov eax,0xffffffff ret +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: @@ -4736,43 +4749,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 @@ -4784,9 +4797,9 @@ 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 @@ -4814,30 +4827,30 @@ end if 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 @@ -4847,7 +4860,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 @@ -4859,7 +4872,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 @@ -4881,70 +4894,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 @@ -4952,9 +4965,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 @@ -4964,14 +4977,14 @@ 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 @@ -4993,110 +5006,110 @@ 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 [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 eax, 4 + jb .audio + jz .eject + cmp eax, 5 + jnz .ret .load: - call .reserve - call LoadMedium - call .free - ret + call .reserve + call LoadMedium + call .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 + ret .audio: call sys_cd_audio mov [esp+36],eax @@ -5104,39 +5117,39 @@ syscall_cdaudio: ; CD 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, 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 .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 @@ -5152,14 +5165,14 @@ align 4 syscall_getarea: ;eax = 36 -;ebx = pointer to bufer for img BBGGRRBBGGRR... -;ecx = [size x]*65536 + [size y] -;edx = [start x]*65536 + [start y] +;ebx = pointer to bufer for img BBGGRRBBGGRR... +;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 + 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 @@ -5184,22 +5197,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: @@ -5212,50 +5225,50 @@ syscall_getarea: shr ecx,16 mov [ebp+2],cl - pop ecx ebx eax + pop ecx ebx eax 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] + 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 @@ -5273,7 +5286,7 @@ syscall_getirqowner: ; GetIrqOwner align 4 -syscall_reserveportarea: ; ReservePortArea and FreePortArea +syscall_reserveportarea: ; ReservePortArea and FreePortArea call r_f_port_area mov [esp+36],eax @@ -5281,7 +5294,7 @@ syscall_reserveportarea: ; ReservePortArea and FreePortArea align 4 -syscall_threads: ; CreateThreads +syscall_threads: ; CreateThreads call sys_threads mov [esp+36],eax @@ -5290,7 +5303,7 @@ syscall_threads: ; CreateThreads 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 @@ -5305,53 +5318,53 @@ 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 [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 + 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 - popfd - ret + popfd + ret ; --------------- APM --------------------- apm_entry dp 0 -apm_vf dd 0 +apm_vf dd 0 align 4 sys_apm: cmp word [apm_vf], 0 ; Check APM BIOS enable jne @f - or [esp + 56], byte 1 ; error - mov [esp + 36], dword 8 ; 32-bit protected-mode interface not supported + or [esp + 48], byte 1 ; error + mov [esp + 36], dword 8 ; 32-bit protected-mode interface not supported ret @@: @@ -5359,8 +5372,8 @@ sys_apm: xchg ebx, ecx cmp al, 3 - ja @f - and [esp + 56], byte 0xfe ; emulate func 0..3 as func 0 + 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 @@ -5373,9 +5386,9 @@ sys_apm: xchg [master_tab], esi push esi mov edi, cr3 - mov cr3, edi ;flush TLB + 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 @@ -5389,9 +5402,9 @@ sys_apm: mov [esp + 28], edx mov [esp + 32], ecx mov [esp + 36], eax - setc al - and [esp + 56], byte 0xfe - or [esp + 56], al + setc al + and [esp + 48], byte 0xfe + or [esp + 48], al ret @@ -5399,177 +5412,248 @@ sys_apm: 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 1 - mov word [OS_BASE+0x467+0],pr_mode_exit - mov word [OS_BASE+0x467+2],0x1000 +if 0 + 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 + 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 edx, [ebx+48] - test edx, edx - jz .nosmi - mov al, [ebx+52] - out dx, al - mov edx, [ebx+64] + 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] @@: - in ax, dx - test al, 1 - jz @b + 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 +.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 +@@: + 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] +@@: + in ax, dx + test al, 1 + jz @b .nosmi: - mov edx, [ebx+64] - in ax, dx - and ax, 203h - or ax, 3C00h - out dx, ax - mov edx, [ebx+68] - test edx, edx - jz @f - in ax, dx - and ax, 203h - or ax, 3C00h - 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 + 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" @@ -5578,4 +5662,3 @@ __REV__ = __REV uglobals_size = $ - endofcode diff16 "end of kernel code",0,$ - diff --git a/kernel/branches/net/kernel32.inc b/kernel/branches/net/kernel32.inc index 9f3fb3c8f1..c371fca9b1 100644 --- a/kernel/branches/net/kernel32.inc +++ b/kernel/branches/net/kernel32.inc @@ -74,7 +74,7 @@ WSTATE_MAXIMIZED = 00000001b WSTATE_MINIMIZED = 00000010b WSTATE_ROLLEDUP = 00000100b -WSTATE_REDRAW = 00000001b +WSTATE_REDRAW = 00000001b WSTATE_WNDDRAWN = 00000010b WSTYLE_HASCAPTION = 00010000b @@ -83,13 +83,13 @@ WSTYLE_CLIENTRELATIVE = 00100000b struc TASKDATA { .event_mask dd ? - .pid dd ? - dw ? + .pid dd ? + dw ? .state db ? db ? - dw ? + dw ? .wnd_number db ? - db ? + db ? .mem_start dd ? .counter_sum dd ? .counter_add dd ? @@ -101,14 +101,14 @@ end virtual ; structures definition struc WDATA { - .box BOX - .cl_workarea dd ? - .cl_titlebar dd ? - .cl_frames dd ? - .reserved db ? - .fl_wstate db ? - .fl_wdrawn db ? - .fl_redraw db ? + .box BOX + .cl_workarea dd ? + .cl_titlebar dd ? + .cl_frames dd ? + .reserved db ? + .fl_wstate db ? + .fl_wdrawn db ? + .fl_redraw db ? } virtual at 0 WDATA WDATA @@ -117,13 +117,13 @@ label WDATA.fl_wstyle byte at 0x13 struc APPDATA { - .app_name db 11 dup(?) - db 5 dup(?) + .app_name db 11 dup(?) + db 5 dup(?) .fpu_state dd ? ;+16 - .ev_count dd ? ;+20 - .fpu_handler dd ? ;+24 - .sse_handler dd ? ;+28 + .ev_count_ dd ? ;unused ;+20 + .exc_handler dd ? ;+24 + .except_mask dd ? ;+28 .pl0_stack dd ? ;unused ;+32 .heap_base dd ? ;+36 .heap_top dd ? ;+40 @@ -138,22 +138,24 @@ struc APPDATA .cur_dir dd ? ;+80 .wait_timeout dd ? ;+84 .saved_esp0 dd ? ;+88 - - db 36 dup(?) ;+92 + .wait_begin dd ? ;+92 +++ + .wait_test dd ? ;+96 +++ + .wait_param dd ? ;+100 +++ + db 24 dup(?) ;+104 .wnd_shape dd ? ;+128 .wnd_shape_scale dd ? ;+132 dd ? ;+136 .mem_size dd ? ;+140 - .saved_box BOX - .ipc_start dd ? - .ipc_size dd ? - .event_mask dd ? + .saved_box BOX + .ipc_start dd ? + .ipc_size dd ? + .event_mask dd ? .debugger_slot dd ? - dd ? + dd ? .keyboard_mode db ? - db 3 dup(?) - .dir_table dd ? + db 3 dup(?) + .dir_table dd ? .dbg_event_mem dd ? .dbg_regs: .dbg_regs.dr0 dd ? @@ -161,7 +163,7 @@ struc APPDATA .dbg_regs.dr2 dd ? .dbg_regs.dr3 dd ? .dbg_regs.dr7 dd ? - .wnd_caption dd ? + .wnd_caption dd ? .wnd_clientbox BOX } virtual at 0 diff --git a/kernel/branches/net/macros.inc b/kernel/branches/net/macros.inc index 471276dcc7..901c7a7d13 100644 --- a/kernel/branches/net/macros.inc +++ b/kernel/branches/net/macros.inc @@ -98,3 +98,9 @@ if ~ f eq end if } ; \end{diamond}[29.09.2006] + +macro Mov op1,op2,op3 ; op1 = op2 = op3 + { + mov op2,op3 + mov op1,op2 + } diff --git a/kernel/branches/net/makefile b/kernel/branches/net/makefile index e5f89bc4ae..f2d916f767 100644 --- a/kernel/branches/net/makefile +++ b/kernel/branches/net/makefile @@ -1,7 +1,7 @@ FASM=fasm FLAGS=-m 65536 languages=en|ru|ge|et -drivers_src=sound sis infinity ensoniq ps2mouse uart ati2d vmode +drivers_src=sound sis infinity uart ati2d vmode com_mouse skins_src=default .PHONY: all kernel drivers skins clean diff --git a/kernel/branches/net/memmap.inc b/kernel/branches/net/memmap.inc index 53675c3f0c..e54718c0f5 100644 --- a/kernel/branches/net/memmap.inc +++ b/kernel/branches/net/memmap.inc @@ -23,12 +23,17 @@ ; 0x9046 - word - flags ; 0:907F byte number of BIOS hard disks ; 0:9080 Nbytes BIOS hard disks +; 0:9100 word available physical memory map: number of blocks +; 0:9104 available physical memory map: blocks ; ; Runtime: ; ; 0x00000000 -> 0x7FFFFFFF application 2Gb -; 0x80000000 -> 1FFF window_data - 256 entries +; 0x80000000 -> 0FFF physical page zero - do not write +; (used by int 13h in some configurations) +; +; 0x80001000 -> 2FFF window_data - 256 entries ; ; 0000 dword x start ; 0004 dword y start @@ -39,8 +44,6 @@ ; 0018 dword color of frames ; 001C dword window flags, +30 = window drawn, +31 redraw flag ; -; 2000 -> 2FFF free -; ; 3000 -> 4FFF task list - 256 entries ; ; 00 dword process count @@ -70,9 +73,9 @@ ; ; A400 -> B0FF free -; B100 -> B2FF IDT +; B100 -> B307 IDT for int_0x00..int_0x40 -; B300 -> BFFF free +; B308 -> BFFF free ; C000 -> C3FF window stack C000 no of windows - all in words ; C402 -> C7FF window position in stack diff --git a/kernel/branches/net/video/vga.inc b/kernel/branches/net/video/vga.inc index b1e3789370..6253e456d3 100644 --- a/kernel/branches/net/video/vga.inc +++ b/kernel/branches/net/video/vga.inc @@ -113,7 +113,7 @@ palette320x200: loop palnew ret - +align 4 uglobal novesachecksum dd 0x0 EGA_counter db 0 @@ -123,7 +123,7 @@ uglobal temp: .cx dd 0 endg - +align 4 checkVga_N13: cmp [SCR_MODE],dword 0x13