↑ Back to main site.

EPOS

Experimental Protected-mode Operating System

access.asm
; EPOS
; http://www.atanaslaskov.com/epos/
;
; FILE:         access.asm
; DESCRIPTION:  Low-level operations for IA32 processors
;
; BSD LICENSE
; Copyright (c) 2006, Atanas Laskov
; All rights reserved.
; Redistribution and use in source and binary forms, with or without
; modification, are permitted provided that the following conditions are met:
;   1. Redistributions of source code must retain the above copyright notice,
;   this list of conditions and the following disclaimer.
;   2. Redistributions in binary form must reproduce the above copyright notice,
;   this list of conditions and the following disclaimer in the documentation
;   and/or other materials provided with the distribution.
; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
; DISCLAIMED. IN NO EVENT SHALL ATANAS LASKOV BE LIABLE FOR ANY
; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
; ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;

;-------------- Acessing the "ancestor" process ( the initialization process )
;
extern KRN_BOOTUP_MDEIUM
extern KPR_ANCESTOR_START_SEG
extern KPR_ANCESTOR_START_OFS
extern KPR_ANCESTOR_END_SEG
extern KPR_ANCESTOR_END_OFS

global _access_get_bootup_medium
_access_get_bootup_medium:
    xor eax, eax
    mov ax, [KRN_BOOTUP_MDEIUM]
ret

global _access_get_ancestor_start_ofs
_access_get_ancestor_start_ofs:
    xor eax, eax
    mov ax, [KPR_ANCESTOR_START_OFS]
ret

global _access_get_ancestor_start_seg
_access_get_ancestor_start_seg:
    xor eax, eax
    mov ax, [KPR_ANCESTOR_START_SEG]
ret

global _access_get_ancestor_end_ofs
_access_get_ancestor_end_ofs:
    xor eax, eax
    mov ax, [KPR_ANCESTOR_END_OFS]
ret

global _access_get_ancestor_end_seg
_access_get_ancestor_end_seg:
    xor eax, eax
    mov ax, [KPR_ANCESTOR_END_SEG]
ret

;------------------------------- Getting the OS Version
extern _NAME
extern _MAJOR
extern _MINOR
extern _BUILD

global _access_get_name
_access_get_name:       ;char* access_get_name();
    mov eax, _NAME
ret

global _access_get_major
_access_get_major:      ;unsigned short access_get_major();
    mov ax, [_MAJOR]
ret

global _access_get_minor
_access_get_minor:      ;unsigned short access_get_minor();
    mov ax, [_MINOR]
ret

global _access_get_build
_access_get_build:      ;unsigned short access_get_build();
    mov ax, [_BUILD]
ret

;----------------------------- Special processor registers

global _access_cs
_access_cs:             ;unsigned short access_cs();
    mov ax, cs
ret

global _access_ss
_access_ss:             ;unsigned short access_ss();
    mov ax, ss
ret

global _access_esp
_access_esp:            ;unsigned long access_esp();
    mov eax, esp
ret

;----------------------------- Paging registers

global _access_enablePaging
_access_enablePaging:        ;void access_enablePaging();
    push eax
    mov eax, cr0
    or  eax, 1 << 31
    mov cr0, eax   
    ;jmp    near .near
    ;.near
    pop eax
ret

global _access_loadPDBR
_access_loadPDBR:            ;void access_loadPDBR(void *dwBase)
    push    ebp
    mov ebp,esp

    push eax
    mov eax, [ebp+8]
    and eax, 0xfffff000
    mov cr3,eax
    pop eax

    pop ebp
ret

;------------------------------- Accessing ports
global _access_in
_access_in:            ;char access_in(unsigned short port);
    push ebp
    mov ebp, esp

    push edx
    mov edx, [ebp+8]
    in al, dx
    pop edx

    push cx
    mov cx, 0FFh
    _access_in_wait:
    dec cx
    cmp cx, 0
    jne _access_in_wait
    pop cx

    pop ebp
ret

global _access_out
_access_out:         ;void access_out(unsigned short port, unsigned char data);
    push ebp
    mov ebp, esp

    push eax
    push edx
    mov edx, [ebp+8]
    mov al, [ebp+12]
    out dx, al
    pop edx
    pop eax

    push cx
    mov cx, 0FFh
    _access_out_wait:
    dec cx
    cmp cx, 0
    jne _access_out_wait
    pop cx

    pop ebp
ret