blkdev.asm
ostin-project_ostin-kernel/kernel/blkdev/blkdev.asm
;;======================================================================================================================
;;///// blkdev.asm ///////////////////////////////////////////////////////////////////////////////////////// GPLv2 /////
;;======================================================================================================================
;; (c) 2011-2012 Ostin project <http://ostin.googlecode.com/>
;;======================================================================================================================
;; 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 the Free Software Foundation, either version 2 of the License, or (at your option) any later
;; version.
;;
;; This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
;; warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License along with this program. If not, see
;; <http://www.gnu.org/licenses/>.
;;======================================================================================================================

iglobal
  blkdev_list dd blkdev_list, blkdev_list ; linked_list_t
endg

;-----------------------------------------------------------------------------------------------------------------------
kproc blk.set_device_name ;/////////////////////////////////////////////////////////////////////////////////////////////
;-----------------------------------------------------------------------------------------------------------------------
;> eax ^= name prefix
;> ebx ^= blk.device_t
;> ecx #= device number
;-----------------------------------------------------------------------------------------------------------------------
        push    esi edi

        mov     esi, eax
        lea     edi, [ebx + blk.device_t._.name]

    @@: lodsb
        test    al, al
        jz      @f
        stosb
        jmp     @b

    @@: ; TODO: int2str
        lea     eax, [ecx + '0']
        stosb

        mov     byte[edi], 0

        pop     edi esi
        ret
kendp

;-----------------------------------------------------------------------------------------------------------------------
kproc blk.read ;////////////////////////////////////////////////////////////////////////////////////////////////////////
;-----------------------------------------------------------------------------------------------------------------------
;> edi ^= buffer
;> ecx #= buffer size (number of blocks to read)
;> edx:eax #= offset (in blocks)
;> ebx ^= blk.device_t
;-----------------------------------------------------------------------------------------------------------------------
;< eax #= error code
;-----------------------------------------------------------------------------------------------------------------------
        push    ebx esi

        mov     esi, [ebx + blk.device_t._.vftbl]
        call    [esi + blk.device_vftbl_t.read]

        pop     esi ebx
        ret
kendp

;-----------------------------------------------------------------------------------------------------------------------
kproc blk.write ;///////////////////////////////////////////////////////////////////////////////////////////////////////
;-----------------------------------------------------------------------------------------------------------------------
;> esi ^= buffer
;> ecx #= buffer size (number of blocks to write)
;> edx:eax #= offset (in blocks)
;> ebx ^= blk.device_t
;-----------------------------------------------------------------------------------------------------------------------
;< eax #= error code
;-----------------------------------------------------------------------------------------------------------------------
        push    ebx edi

        mov     edi, [ebx + blk.device_t._.vftbl]
        call    [edi + blk.device_vftbl_t.write]

        pop     edi ebx
        ret
kendp

;-----------------------------------------------------------------------------------------------------------------------
kproc blk.not_implemented ;/////////////////////////////////////////////////////////////////////////////////////////////
;-----------------------------------------------------------------------------------------------------------------------
        MovStk  eax, ERROR_NOT_IMPLEMENTED
        ret
kendp
