outdated/kerpack: Post-SVN tidy
Some checks failed
Build system / Check kernel codestyle (pull_request) Successful in 42s
Build system / Build (pull_request) Failing after 6m27s

- Move source code from `trunk` into root directory.
- Checked build files and ASM include paths.
This commit is contained in:
2025-08-12 00:43:43 +01:00
parent b14f77c304
commit 7ccd4288f5
9 changed files with 421 additions and 418 deletions

View File

@@ -1,4 +1,4 @@
You should really be using the kpack program instead of kerpack. You should really be using the kpack program instead of kerpack.
It also builds nicely on Linux. It also builds nicely on Linux.
kpack can be found in $SVN/programs/other/kpack kpack can be found in programs/other/kpack

View File

@@ -1,417 +1,420 @@
; Kolibri kernel packer ; SPDX-License-Identifier: NOASSERTION
; (C) copyright diamond 2006, 2007 ;
;
; Disassemled and corrected in 2010 specially for FASM ; Kolibri kernel packer
; by Marat Zakiyanov aka Mario79, aka Mario ; (C) copyright diamond 2006, 2007
; ;
; This program is free software; you can redistribute it and/or modify ; Disassemled and corrected in 2010 specially for FASM
; it under the terms of the GNU General Public License as published by ; by Marat Zakiyanov aka Mario79, aka Mario
; the Free Software Foundation; either version 2 of the License, or ;
; (at your option) any later version. ; This program is free software; you can redistribute it and/or modify
; ; it under the terms of the GNU General Public License as published by
; This program is distributed in the hope that it will be useful, ; the Free Software Foundation; either version 2 of the License, or
; but WITHOUT ANY WARRANTY; without even the implied warranty of ; (at your option) any later version.
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;
; GNU General Public License for more details. ; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; Uses LZMA compression library by Igor Pavlov ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; (for more information on LZMA and 7-Zip visit http://www.7-zip.org) ; GNU General Public License for more details.
; (plain-C packer is ported by diamond)
; Uses LZMA compression library by Igor Pavlov
;--------------------------------------------------------------------- ; (for more information on LZMA and 7-Zip visit http://www.7-zip.org)
use32 ; (plain-C packer is ported by diamond)
org 0
;---------------------------------------------------------------------
db 'MENUET01' use32
dd 1 org 0
dd START
dd IM_END db 'MENUET01'
dd I_END dd 1
dd stacktop dd START
dd 0 ;params dd IM_END
dd 0 ;cur_dir_path dd I_END
;--------------------------------------------------------------------- dd stacktop
include '../../../../macros.inc' dd 0 ;params
; do not touch "purge mov"!!! dd 0 ;cur_dir_path
purge mov ; for the correct patch of loader ;---------------------------------------------------------------------
; do not touch "purge mov"!!! include '../../../macros.inc'
;********************************************************************* ; do not touch "purge mov"!!!
die_with_err: purge mov ; for the correct patch of loader
pop esi ; do not touch "purge mov"!!!
@@: ;*********************************************************************
lodsb die_with_err:
test al,al pop esi
jz @f @@:
lodsb
mov cl,al test al,al
mcall 63,1 jz @f
jmp @b
;********************************************************************* mov cl,al
@@: mcall 63,1
mcall 63,,13 jmp @b
mcall ,,10 ;*********************************************************************
mcall -1 @@:
;********************************************************************* mcall 63,,13
START: mcall ,,10
mcall 70,fn70_read mcall -1
cmp eax,6 ;*********************************************************************
jz read_ok START:
;-------------------------------------- mcall 70,fn70_read
read_err: cmp eax,6
call die_with_err jz read_ok
db 'KerPack: cannot load kernel.mnt',0 ;--------------------------------------
;********************************************************************* read_err:
read_ok: call die_with_err
push 18 db 'KerPack: cannot load kernel.mnt',0
call lzma_set_dict_size ;*********************************************************************
; find jump to 32-bit code read_ok:
mov edi,infile - 1 push 18
;-------------------------------------- call lzma_set_dict_size
@@: ; find jump to 32-bit code
inc edi mov edi,infile - 1
cmp dword [edi],0xE88EE08E ; mov fs,ax/mov gs,ax ;--------------------------------------
jnz @b @@:
inc edi
cmp dword [edi+4],0x00BCD08E ; mov ss,ax/mov esp,00xxxxxx cmp dword [edi],0xE88EE08E ; mov fs,ax/mov gs,ax
jnz @b jnz @b
add edi,11 cmp dword [edi+4],0x00BCD08E ; mov ss,ax/mov esp,00xxxxxx
mov [inptr],edi jnz @b
sub edi, infile
mov [indelta],edi add edi,11
lea eax,[ebx+0x10000] mov [inptr],edi
mov dword [loader_patch3+2],eax sub edi, infile
sub ebx,edi mov [indelta],edi
mov [insize],ebx lea eax,[ebx+0x10000]
call preprocess_calltrick2 mov dword [loader_patch3+2],eax
sub ebx,edi
mov al,[cti] mov [insize],ebx
mov [loader_patch5-1],al call preprocess_calltrick2
mov eax,[ctn]
mov [loader_patch4+1],eax mov al,[cti]
mov eax,[inptr] mov [loader_patch5-1],al
add eax, outfile - infile + loader_size - 5 mov eax,[ctn]
push workmem mov [loader_patch4+1],eax
push [insize] mov eax,[inptr]
push eax add eax, outfile - infile + loader_size - 5
push [inptr] push workmem
call lzma_compress push [insize]
push eax
add eax, loader_size-5 push [inptr]
mov [loader_patch1+6],eax call lzma_compress
add eax,[indelta]
mov [outsize],eax add eax, loader_size-5
mov eax,[indelta] mov [loader_patch1+6],eax
mov ecx,dword [eax + outfile + loader_size - 4] add eax,[indelta]
bswap ecx mov [outsize],eax
mov [loader_patch2+4],ecx mov eax,[indelta]
add eax, 0x10000 mov ecx,dword [eax + outfile + loader_size - 4]
mov [loader_patch1+1],eax bswap ecx
mov esi,infile mov [loader_patch2+4],ecx
mov edi,outfile add eax, 0x10000
mov ecx,[indelta] mov [loader_patch1+1],eax
rep movsb mov esi,infile
mov edi,outfile
mov esi,loader_start mov ecx,[indelta]
mov ecx,loader_size rep movsb
rep movsb
mov esi,loader_start
mcall 70,fn70_write mov ecx,loader_size
test eax,eax rep movsb
jz @f
mcall 70,fn70_write
call die_with_err test eax,eax
db 'KerPack: cannot save kernel.mnt',0 jz @f
;*********************************************************************
@@: call die_with_err
call die_with_err db 'KerPack: cannot save kernel.mnt',0
db 'KerPack: all is OK',0 ;*********************************************************************
;********************************************************************* @@:
preprocess_calltrick2: call die_with_err
; input preprocessing db 'KerPack: all is OK',0
mov edi,ct1 ;*********************************************************************
xor eax,eax preprocess_calltrick2:
push edi ; input preprocessing
mov ecx,256/4 mov edi,ct1
rep stosd xor eax,eax
push edi
pop edi mov ecx,256/4
mov ecx,ebx rep stosd
mov esi,[inptr]
mov ebx,inbuftmp pop edi
xchg eax,edx mov ecx,ebx
;-------------------------------------- mov esi,[inptr]
input_pre2: mov ebx,inbuftmp
lodsb xchg eax,edx
;-------------------------------------- ;--------------------------------------
@@: input_pre2:
cmp al,0Fh lodsb
jnz ip1 ;--------------------------------------
@@:
dec ecx cmp al,0Fh
jz input_pre_done2 jnz ip1
lodsb dec ecx
cmp al,80h jz input_pre_done2
jb @b
lodsb
cmp al,90h cmp al,80h
jb @f jb @b
;--------------------------------------
ip1: cmp al,90h
sub al,0E8h jb @f
cmp al,1 ;--------------------------------------
ja input_pre_cont2 ip1:
;-------------------------------------- sub al,0E8h
@@: cmp al,1
cmp ecx,5 ja input_pre_cont2
jb input_pre_done2 ;--------------------------------------
@@:
lodsd cmp ecx,5
add eax,esi jb input_pre_done2
sub eax,[inptr]
cmp eax,[insize] lodsd
jae xxx2 add eax,esi
sub eax,[inptr]
cmp eax,1000000h cmp eax,[insize]
jae xxx2 jae xxx2
sub ecx,4 cmp eax,1000000h
xchg al,ah jae xxx2
rol eax,16
xchg al,ah sub ecx,4
mov [esi-4],eax xchg al,ah
inc edx rol eax,16
mov [ebx],esi xchg al,ah
add ebx,4 mov [esi-4],eax
jmp input_pre_cont2 inc edx
;********************************************************************* mov [ebx],esi
xxx2: add ebx,4
sub esi,4 jmp input_pre_cont2
movzx eax,byte [esi] ;*********************************************************************
mov byte [eax+edi],1 xxx2:
;-------------------------------------- sub esi,4
input_pre_cont2: movzx eax,byte [esi]
loop input_pre2 mov byte [eax+edi],1
;-------------------------------------- ;--------------------------------------
input_pre_done2: input_pre_cont2:
mov [ctn],edx loop input_pre2
xor eax,eax ;--------------------------------------
mov ecx,256 input_pre_done2:
repnz scasb mov [ctn],edx
jnz pack_calltrick_done xor eax,eax
mov ecx,256
not cl repnz scasb
mov [cti],cl jnz pack_calltrick_done
;--------------------------------------
@@: not cl
cmp ebx,inbuftmp mov [cti],cl
jz pack_calltrick_done ;--------------------------------------
@@:
sub ebx,4 cmp ebx,inbuftmp
mov eax,[ebx] jz pack_calltrick_done
mov [eax-4],cl
jmp @b sub ebx,4
;********************************************************************* mov eax,[ebx]
pack_calltrick_done: mov [eax-4],cl
ret jmp @b
;********************************************************************* ;*********************************************************************
;lzma_compress: pack_calltrick_done:
include 'lzma_compress.inc' ret
;--------------------------------------------------------------------- ;*********************************************************************
;lzma_set_dict_size: ;lzma_compress:
include 'lzma_set_dict_size.inc' include 'lzma_compress.inc'
;--------------------------------------------------------------------- ;---------------------------------------------------------------------
; ;lzma_set_dict_size:
include 'loader_lzma.inc' include 'lzma_set_dict_size.inc'
;********************************************************************* ;---------------------------------------------------------------------
fn70_read: ;
dd 0 include 'loader_lzma.inc'
dd 0 ;*********************************************************************
dd 0 fn70_read:
dd 200*1024 dd 0
dd infile dd 0
filename db '/sys/kernel.mnt',0 dd 0
dd 200*1024
fn70_write: dd infile
dd 2 filename db '/sys/kernel.mnt',0
dd 0
dd 0 fn70_write:
outsize dd ? dd 2
dd outfile dd 0
db 0 dd 0
dd filename outsize dd ?
;--------------------------------------------------------------------- dd outfile
align 4 db 0
LiteralNextStates: dd filename
db 0,0,0,0,1,2,3,4,5,6,4,5 ;---------------------------------------------------------------------
MatchNextStates: align 4
db 7,7,7,7,7,7,7,10,10,10,10,10 LiteralNextStates:
RepNextStates: db 0,0,0,0,1,2,3,4,5,6,4,5
db 8,8,8,8,8,8,8,11,11,11,11,11 MatchNextStates:
ShortRepNextStates: db 7,7,7,7,7,7,7,10,10,10,10,10
db 9,9,9,9,9,9,9,11,11,11,11,11 RepNextStates:
;--------------------------------------------------------------------- db 8,8,8,8,8,8,8,11,11,11,11,11
;********************************************************************* ShortRepNextStates:
IM_END: db 9,9,9,9,9,9,9,11,11,11,11,11
;********************************************************************* ;---------------------------------------------------------------------
;params: ;*********************************************************************
; rb 256 IM_END:
;--------------------------------------------------------------------- ;*********************************************************************
;cur_dir_path: ;params:
; rb 4096 ; rb 256
;--------------------------------------------------------------------- ;---------------------------------------------------------------------
align 4 ;cur_dir_path:
rb 4096 ; rb 4096
stacktop: ;---------------------------------------------------------------------
;--------------------------------------------------------------------- align 4
align 4 rb 4096
inptr dd ? stacktop:
indelta dd ? ;---------------------------------------------------------------------
insize dd ? align 4
ct1 rb 256 inptr dd ?
ctn dd ? indelta dd ?
cti db ? insize dd ?
ct1 rb 256
infile rb 200*1024 ctn dd ?
inbuftmp rb 200*1024 cti db ?
outfile rb 200*1024
workmem rb 6A8000h infile rb 200*1024
;--------------------------------------------------------------------- inbuftmp rb 200*1024
; Compress data area start outfile rb 200*1024
;--------------------------------------------------------------------- workmem rb 6A8000h
align 4 ;---------------------------------------------------------------------
_lenEncoder: ; Compress data area start
rd 8451 ;---------------------------------------------------------------------
;----------------------------------------------------- align 4
_prices: _lenEncoder:
rd 4384 rd 8451
rd 17 ;-----------------------------------------------------
;----------------------------------------------------- _prices:
_finished: rb 1 rd 4384
_writeEndMark: rb 1 rd 17
_longestMatchWasFound: rb 1 ;-----------------------------------------------------
_previousByte: rb 1 _finished: rb 1
_longestMatchLength: rd 1 _writeEndMark: rb 1
;----------------------------------------------------- _longestMatchWasFound: rb 1
g_FastPos: _previousByte: rb 1
rb 1024 _longestMatchLength: rd 1
;----------------------------------------------------- ;-----------------------------------------------------
_posSlotPrices: g_FastPos:
rd 256 rb 1024
;----------------------------------------------------- ;-----------------------------------------------------
_isRep0Long: _posSlotPrices:
rd 192 rd 256
;----------------------------------------------------- ;-----------------------------------------------------
distances: _isRep0Long:
rd 274 rd 192
;----------------------------------------------------- ;-----------------------------------------------------
_optimumCurrentIndex: rd 1 distances:
_additionalOffset: rd 1 rd 274
;----------------------------------------------------- ;-----------------------------------------------------
_isRepG1: _optimumCurrentIndex: rd 1
rd 12 _additionalOffset: rd 1
;----------------------------------------------------- ;-----------------------------------------------------
_isMatch: _isRepG1:
rd 192 rd 12
;----------------------------------------------------- ;-----------------------------------------------------
_alignPriceCount: rd 1 _isMatch:
_numLiteralContextBits: rd 1 rd 192
;----------------------------------------------------- ;-----------------------------------------------------
_literalEncoder: _alignPriceCount: rd 1
rd 114 _numLiteralContextBits: rd 1
;----------------------------------------------------- ;-----------------------------------------------------
nowPos64: _literalEncoder:
rd 2 rd 114
;----------------------------------------------------- ;-----------------------------------------------------
_distancesPrices: nowPos64:
rd 512 rd 2
;----------------------------------------------------- ;-----------------------------------------------------
_repDistances: _distancesPrices:
rd 4 rd 512
;----------------------------------------------------- ;-----------------------------------------------------
_posSlotEncoder: _repDistances:
rd 1028 rd 4
;----------------------------------------------------- ;-----------------------------------------------------
lastPosSlotFillingPos: _posSlotEncoder:
rd 2 rd 1028
;----------------------------------------------------- ;-----------------------------------------------------
_numFastBytes: rd 1 lastPosSlotFillingPos:
_posStateMask: rd 1 rd 2
;----------------------------------------------------- ;-----------------------------------------------------
_isRepG0: _numFastBytes: rd 1
rd 12 _posStateMask: rd 1
;----------------------------------------------------- ;-----------------------------------------------------
_repMatchLenEncoder: _isRepG0:
rd 8451 rd 12
rd 4384 ;-----------------------------------------------------
rd 17 _repMatchLenEncoder:
;----------------------------------------------------- rd 8451
_isRepG2: rd 4384
rd 12 rd 17
;----------------------------------------------------- ;-----------------------------------------------------
_dictionarySize: rd 1 _isRepG2:
_numLiteralPosStateBits: rd 1 rd 12
_distTableSize: rd 1 ;-----------------------------------------------------
_optimumEndIndex: rd 1 _dictionarySize: rd 1
;----------------------------------------------------- _numLiteralPosStateBits: rd 1
;static CState state _distTableSize: rd 1
state.State: rb 1 _optimumEndIndex: rd 1
state.Prev1IsChar: rb 1 ;-----------------------------------------------------
state.Prev2: rb 2 ;static CState state
state.PosPrev2: rd 1 state.State: rb 1
state.BackPrev2: rd 1 state.Prev1IsChar: rb 1
state.Price: rd 1 state.Prev2: rb 2
state.PosPrev: rd 1 state.PosPrev2: rd 1
state.BackPrev: rd 1 state.BackPrev2: rd 1
state.Backs: state.Price: rd 1
rd 4 state.PosPrev: rd 1
;---------------------------------------------------- state.BackPrev: rd 1
rd 40950 state.Backs:
;----------------------------------------------------- rd 4
_alignPrices: ;----------------------------------------------------
rd 16 rd 40950
;----------------------------------------------------- ;-----------------------------------------------------
_isRep: _alignPrices:
rd 12 rd 16
;----------------------------------------------------- ;-----------------------------------------------------
_posAlignEncoder: _isRep:
rd 256 rd 12
;----------------------------------------------------- ;-----------------------------------------------------
i_01: rd 1 _posAlignEncoder:
;----------------------------------------------------- rd 256
_state: rb 1 ;-----------------------------------------------------
_cache: rb 1 i_01: rd 1
_state.Prev2: rb 2 ;-----------------------------------------------------
_posEncoders: rd 1 _state: rb 1
_numPrevBits: rd 1 _cache: rb 1
_numPosBits: rd 1 _state.Prev2: rb 2
_posMask: rd 1 _posEncoders: rd 1
_posStateBits: rd 1 _numPrevBits: rd 1
_range: rd 1 _numPosBits: rd 1
_cacheSize: rd 1 _posMask: rd 1
_cyclicBufferSize: rd 1 _posStateBits: rd 1
;----------------------------------------------------- _range: rd 1
low: _cacheSize: rd 1
rd 2 _cyclicBufferSize: rd 1
;----------------------------------------------------- ;-----------------------------------------------------
Models: low:
rd 512 rd 2
;----------------------------------------------------- ;-----------------------------------------------------
_matchMaxLen: rd 1 Models:
pack_pos: rd 1 rd 512
_cutValue: rd 1 ;-----------------------------------------------------
_hash: rd 1 _matchMaxLen: rd 1
;----------------------------------------------------- pack_pos: rd 1
crc_table: _cutValue: rd 1
rd 256 _hash: rd 1
;----------------------------------------------------- ;-----------------------------------------------------
_buffer: rd 1 crc_table:
_pos: rd 1 rd 256
_streamPos: rd 1 ;-----------------------------------------------------
pack_length: rd 1 _buffer: rd 1
;--------------------------------------------------------------------- _pos: rd 1
; Compress data area end _streamPos: rd 1
;--------------------------------------------------------------------- pack_length: rd 1
I_END: ;---------------------------------------------------------------------
;--------------------------------------------------------------------- ; Compress data area end
;---------------------------------------------------------------------
I_END:
;---------------------------------------------------------------------