;* ;* x86_64-bios/fs.inc ;* ;* Copyright (C) 2017 bzt (bztsrc@gitlab) ;* ;* Permission is hereby granted, free of charge, to any person ;* obtaining a copy of this software and associated documentation ;* files (the "Software"), to deal in the Software without ;* restriction, including without limitation the rights to use, copy, ;* modify, merge, publish, distribute, sublicense, and/or sell copies ;* of the Software, and to permit persons to whom the Software is ;* furnished to do so, subject to the following conditions: ;* ;* The above copyright notice and this permission notice shall be ;* included in all copies or substantial portions of the Software. ;* ;* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ;* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ;* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT ;* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, ;* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ;* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER ;* DEALINGS IN THE SOFTWARE. ;* ;* This file is part of the BOOTBOOT Protocol package. ;* @brief Filesystem drivers for initial ramdisk. ;* FSZ_SUPPORT equ 1 ;********************************************************************* ;* File System Drivers * ;********************************************************************* USE32 fsdrivers: if FSZ_SUPPORT eq 1 dw fsz_initrd end if dw cpio_initrd dw tar_initrd dw sfs_initrd dw jamesm_initrd dw 0 if FSZ_SUPPORT eq 1 ; ----------- FS/Z ---------- ; Find the kernel on initrd ; IN: esi: initrd pointer, ecx: initrd end, edi: kernel filename ; OUT: On Success ; esi: pointer to the first byte, ecx: size in bytes ; On Error ; ecx: 0 fsz_initrd: mov ebx, ecx xor ecx, ecx ; FS/Z superblock ; get root dir inode mov eax, dword [esi+560] ; FSZ_SuperBlock.rootdirfid shl eax, 12 add esi, eax cmp dword [esi], 'FSIN' je @f .nolib: mov esi, nolib .err: xor ecx, ecx ret .nocore: mov esi, nocore jmp .err @@: ; it has inlined data? .again: add esi, 1024 ; FSZ_Inode.inlinedata cmp dword [esi], 'FSDR' je .srchdir ; no, locate the data mov ecx, dword [esi] mov eax, dword [esi-1024+448] ; FSZ_Inode.sec shl eax, 12 mov esi, dword [bootboot.initrd_ptr] add esi, eax cmp dword [esi], 'FSDR' je .srchdir ; inlined sector directory or list? shl ecx, 12 mov esi, dword [bootboot.initrd_ptr] add esi, ecx cmp dword [esi], 'FSDR' jne .nolib .srchdir: ; find sys/ mov ecx, dword [esi+16] ; FSZ_DirEntHeader.numentries mov eax, dword [edi] @@: add esi, 128 ; directories than cmp dword [esi+17], eax je @f dec ecx jnz @b jmp .nolib ; found, get it's inode @@: mov eax, dword [esi] shl eax, 12 mov esi, dword [bootboot.initrd_ptr] add esi, eax cmp dword [esi], 'FSIN' jne .nolib ;this is not bullet proof add edi, 4 cmp byte [edi+3], '/' je .again ; it has inlined data? add esi, 1024 ; FSZ_Inode.inlinedata cmp dword [esi], 'FSDR' je .srchcore ; no, locate the data mov ecx, dword [esi] mov eax, dword [esi-1024+448] ; FSZ_Inode.sec shl eax, 12 mov esi, dword [bootboot.initrd_ptr] add esi, eax cmp dword [esi], 'FSDR' je .srchdir ; inlined sector directory or list? shl ecx, 12 mov esi, dword [bootboot.initrd_ptr] add esi, ecx cmp dword [esi], 'FSDR' jne .nolib .srchcore: ; find filename mov ecx, dword [esi+16] ; FSZ_DirEntHeader.numentries ;filename, 8 characters supported mov eax, dword [edi] mov edx, dword [edi+4] @@: add esi, 128 cmp dword [esi+21], edx jne .not cmp dword [esi+17], eax je @f .not: dec ecx jnz @b jmp .nocore ; found, get it's inode @@: mov eax, dword [esi] shl eax, 12 mov esi, dword [bootboot.initrd_ptr] add esi, eax cmp dword [esi], 'FSIN' jne .nocore ; get data mov eax, dword [esi+448] ; FSZ_Inode.sec mov ecx, dword [esi+464] ; FSZ_Inode.size mov bl, byte [esi+492] ; FSZ_Inode.flags ; inline cmp bl, 0FFh ; FSZ_IN_FLAG_INLINE jne @f add esi, 1024 ret ; direct data block @@: or bl, bl ; FSZ_IN_FLAG_DIRECT je .load ; inlined sector directory or sector list @@: cmp bl, 07Fh ; FSZ_IN_FLAG_SDINLINE je @f cmp bl, 080h ; FSZ_IN_FLAG_SECLIST je @f cmp bl, 1 ; FSZ_IN_FLAG_SD jne .nocore shl eax, 12 mov esi, dword [bootboot.initrd_ptr] add esi, eax mov eax, dword [esi] ; first FSZ_SectorList.sec jmp .load @@: add esi, 1024 ; sector directory at esi, file size in ecx mov eax, dword [esi] ; first FSZ_SectorList.sec .load: shl eax, 12 mov esi, dword [bootboot.initrd_ptr] add esi, eax ret end if ; ----------- cpio ---------- ; Find the kernel on initrd ; IN: esi: initrd pointer, ecx: initrd end, edi: kernel filename ; OUT: On Success ; esi: pointer to the first byte, ecx: size in bytes ; On Error ; ecx: 0 cpio_initrd: ; upper bound mov ebx, ecx xor ecx, ecx ; strlen(kernel) mov eax, edi or eax, eax jz .err cmp byte [eax], 0 jz .err xor ecx, ecx @@: inc ecx inc eax cmp byte [eax], 0 jnz @b mov dword [.ks], ecx ; while(ptr.magic=='070707' && ptr