Documente Academic
Documente Profesional
Documente Cultură
Raport
La Sisteme de Operare: Mecanisme interne i principii de proiectare
A efectuat:
A verificat:
lect. asist.Ostapenco S.
Chiinu 2015
Scopul lucrrii
De a studia cauzele finisrii execuiei unui proces i a crea procedura de lansare i
terminare a execuiei nucleului.
Obiective
De a prezenta n mod UI, procedurile de lansare a nucleului.
Condiii
Prin procedur se subnelege rularea unui proces ce va avea ca scop tratarea
evenimentului de citire a nucleului (byte by byte) i ncrcarea lui n memorie, care va avea o
form de reprezentare conform imaginilor de mai jos. (vezi condiiile conform baremului)
La fel, de aceast procedur se va trata n mod obligatoriu :
-
Mersul lucrrii
Lucrarea de laborator const din trei pari: elaborarea preloaderului, bootloader-ului i
elaborarea kernel-ului. Acestea trebuie nscrise pe sectorul de boot, sectorul 2 i respectiv pe
sectorul 9 (conform variantei).
n bootloader i n kernel am folosit urmtoarele proceduri:
-
Delay procedur de realizeare a unei reineri de 5 secunde , care folosete funcia 0x86
a ntreruperii 0x15.
Fig. 5 Kernel-ul
Concluzii
n urma efecturii lucrrii de laborator am consolidat cunotinele n lucrul cu softul
EMU 8086 i cu particularitile limbajului de asamblare pentru acest emulator. Am cptat
abiliti practice n realizarea unui bootloader i kernel , am studiat ntreruperile BIOS 10h, 12h,
13h, 16h i diverse funcii ale acestora, care le-am folosit pentru realizarea sarcinii de afiare
dinamic a mesajelor, tratarea erorilor i citire de pe sectorul dischetei.
Bibliografie
1. dreamincode. [ASM] Load Kernel From Bootloader. [Resurs electronic].- Regim de
acces :
http://www.dreamincode.net/forums/topic/262898-asm- load-kernel- from-bootloader/
2. Asmcommunity. Looping in NASM. [Resurs electronic].- Regim de acces :
http://www.asmcommunity.net/forums/topic/?id=30742
3. Nasm.us. The Netwide Assembler: NASM . [Resurs electronic].- Regim de acces:
http://www.nasm.us/doc/nasmdoc4.html
4. Stackoverflow. Basic NASM bootstrap. [Resurs electronic].- Regim de acces :
http://stackoverflow.com/questions/10853425/basic- nasm-bootstrap
5. Codenet. BIOS - INT 10H: . [Resurs electronic].- Regim de
acces : http://www.codenet.ru/progr/dos/int_0009.php
6. Codenet. BIOS - INT 13H: -. [Resurs electronic ].Regim de acces : http://www.codenet.ru/progr/dos/int_0012.php
7. Codenet. BIOS - INT 12H: . [Resurs
electronic].- Regim de acces : http://www.codenet.ru/progr/dos/int_0011.php
Anex
Anexa A. Codul surs a preloader-ului
#make_boot#
ORG 0x7C00
;Origin, tell the assembler that where the code will be in memory after it
is been loaded
jmp main
WriteString:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;
;;
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov ah, 13h ; Codul functiei de afisare a unui sir
mov al, 1
; Modul de afisare
ret
WriteMessages:
push ax
; ? Salvam continutul
push bx
; | registrelor in starea
push cx
push dx
; L apelarea functiei
call WriteString
mov bp, str2
call WriteString
pop dx
; ? Restabilim
pop cx
; | continutul
pop bx
; | registrelor
pop ax
ret
Delay:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;
;;
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
push ax
;Salvam
push cx
;continutul
push dx
;registrelor
; Codul functiei
; in dx bitul inferior
(800 milisecunde)
pop dx
; Restabilim
pop cx
; continutul
pop ax
; registrelor
ret
beep:
mov ah, 02h
mov dl, 07h
int 21h
ret
ReadSector:
push ax
push bx
push cx
push dx
call beep
call Delay
pop dx
pop cx
pop bx
pop ax
mov ah, 02h
mov al, 1
mov ch, 0
mov cl, 9
mov dh, 0
;mov dl, 0
mov bx, 0800h
mov es, bx
mov bx, 0
int 13h
; integrity check:
;cmp
;je
integrity_check_ok:
; pass control to kernel:
jmp
0800h:0000h
ret
;;;;;;;;;;;;;;;;;;;;;;;;;FUNCTIA PRINCIPALA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
main:
call WriteMessages
mov ah , 00h
int 16h
cmp al, 1bh
jnz here
int 19h
here:
cmp al,13
je ReadSector
;Data
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;
;;
;;
;;
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
str1 db 'Restart-ESC', 0
str1_len dw 11
str1_x db 34
str2 db 'Load kernel-ENTER' ,0
str2_len dw 17
str2_x db 34
TIMES 510 - ($ - $$) db 0
DW 0xAA55
WriteString1:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;
;;
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov ah, 0x13 ; Codul functiei de afisare a unui sir
mov al, 1
; Modul de afisare
ret
Delay1:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;
push ax
;Salvam
push cx
;continutul
push dx
;registrelor
; Codul functiei
; in dx bitul inferior
(800 milisecunde)
int 0x15
pop dx
; Restabilim
pop cx
; continutul
pop ax
; registrelor
ClearScreen1:
; Ecranul are dimensiunea de 24x79 pixeli
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;
;;
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
push ax
; Salvam continutul
push bx
; | registrelor in starea
push cx
push dx
; L apelarea functiei
; Codul functiei
; Numarul de rinduri care vor fi scroll-ate (al=0 -curata ecranul)
; Setarile grafice (culoarea fundalului pentru liniile curatate)
mov ch, 0
mov cl, 0
mov dh, 24
mov dl, 79
int 0x10
pop dx
; Restabilim
pop cx
; | continutul
pop bx
; | registrelor
pop ax
ret
WriteMessage:
push ax
; Salvam continutul
push bx
; | registrelor in starea
push cx
push dx
; L apelarea functiei
call WriteString1
mov bp, str2
mov bl, 4
call WriteString1
mov bl, 4
mov dl, 27
call WriteString1
pop dx
; Restabilim
pop cx
; | continutul
pop bx
; | registrelor
pop ax
ret
;;;;;;;;;;;;;;;;;;;;;;;FUNCTIA PRINCIPALA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
main:
call ClearScreen1
call WriteMessage
call Delay1
cmp byte[color], 15
jne et
mov byte[color], 0
et:
inc byte[color]
jmp main
;Data
; Afisam mesajele
#make_bin#
#AX=0000h#
#BX=0000h#
#CX=0000h#
#DX=0000h#
#SI=0000h#
#DI=0000h#
#BP=0000h#
mov ax,0800h
mov ds, ax
jmp main
Delay1:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;
;;
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
push ax
;Salvam
push bx
push cx
;continutul
push dx
;registrelor
; Codul functiei
; in dx bitul inferior
(800 milisecunde)
int 0x15
pop dx
; Restabilim
pop cx
; continutul
pop bx
pop ax
; registrelor
ret
DrawBar:
push ax
push bx
push cx
push dx
mov bp, offset bar
mov bl, 15
; Modul de afisare
; Modul de afisare
pop dx
pop cx
pop bx
pop ax
ret
DrawBox:
push ax
push bx
push cx
push dx
mov bp, offset symbol
mov bl, ds:[color]
; Modul de afisare
;cursorul
int 10h
pop dx
pop cx
pop bx
pop ax
ret
DrawPercent:
push ax
push bx
push cx
push dx
mov bp, offset percent
mov bl, 15
; Modul de afisare
pop ax
ret
ReadSector:
mov ah, 02h
mov al, 1
mov ch, 0
mov cl, 9
mov dh, 0
mov bx, 0600h
mov es, bx
mov bx, 0
int 13h
; pass control to kernel:
jmp
0600h:0000h
ret
CheckSector:
push ax
push bx
push cx
push dx
mov ah, 02h
mov al, 1
mov ch, 0
mov cl, 9
mov dh, 0
Error:
push ax
push bx
push cx
push dx
mov bp, offset err_msg
mov bl, 4
; Modul de afisare
; Modul de afisare
Message:
push ax
push bx
push cx
push dx
mov bp, offset msg
mov bl, 15
; Modul de afisare
LoadMess:
push ax
push bx
push cx
push dx
;mov bp, offset load25+si
mov bl, 15
mov dl, 44
; Modul de afisare
pop dx
pop cx
pop bx
pop ax
ret
LoadComplete:
push ax
push bx
push cx
push dx
mov bp, offset load100
mov bl, 15
; Modul de afisare
int 10h
pop dx
pop cx
pop bx
pop ax
ret
PrintRAM:
push ax
push bx
push cx
push dx
mov bp, offset ram_mess
mov bl, 2
mov cx, 17
mov dh, 0
mov dl, 0
int 0x10
mov ah, 01h
mov cx, 2607h
int 10h
pop dx
pop cx
pop bx
pop ax
ret
DisplayRAM:
push ax
push bx
push cx
push dx
int 12h
mov bl,10
div bl
or ah, 30h
mov di,offset result
mov byte ptr[di+2],ah
xor ah, ah
div bl
or ah, 30h
mov di,offset result
mov dh, 0
mov dl, 12
; Modul de afisare
main:
call PrintRAM
call DisplayRAM
call DrawBar
call Message
call DrawPercent
l:
call CheckSector
push bp
;desenam un element
call Delay1
pop bp
mov ax, cx
;restabilim continutul bp
;incarcam contorul in ax pentru impartirea ulterioara
mov bl, 4
div bl
cmp ah, 0
jnz et2
;impartim la 4
;verificam daca restul inmpartirii este 0
;daca da incrementam culoarea si offsetul pentru valoarea
call LoadComplete
call Delay1
call ReadSector
jmp $
bar db 124
x db 34
y db 10
symbol db 222, 0
msg db 'Loading ',48,0
percent db 37, 0
load25 db 50,53,0
load50 db 53,48,0
load75 db 55,53,0
load100 db 49,48,48,0
ram_mess db 'Memory size: KB',0
color db 1
result db 0,0,0,0,0
err_msg db 'ERROR: Floppy disk not found!',0
reb db 'Enter disk and press [ESC] to reboot',0
;DW 0xAA55