Ważne! Przeczytaj zanim napiszesz temat

Status
Zamknięty.

jakub007

Nowicjusz
Dołączył
25 Listopad 2006
Posty
6 127
Punkty reakcji
2
  • nie nazywaj tematów "Pomocy", "Proszę o pomoc", "Pytanie" itp. W temacie napisz krótką informację czego dotyczy dany temat.
  • prosimy o pisanie bez błędów i w czytelny sposób
  • pisząc tematy lub posty proszę pamiętać o przedrostach np: "[Delphi] Jak można zrobić ...", [C] Problem z tablicą znaków, [C++] Problem z instrukcjami warunkowymi"
  • kody należy umieszczać w tagach: code
  • przy podawaniu dłuższego kodu umieszczaj go w ramach codebox
[codebox]

;----------------------------------------------------------------------------
; Axion Operating System Code
; Operating System Boot Loader
; This is BSD Licensed and all rights are reserved to the Synapse Operating
; Services Development Team
;----------------------------------------------------------------------------

[bits 16];
[org 7c00h]; put us at boot position

jmp short inicio; Start the code

nop ; The standard boot loader header
db 'Synapse ' ;
dw 512 ;
db 1 ;
dw 1 ;
db 2 ;
dw 224 ;
dw 2880 ;
db 0F0h ;
dw 9 ;
dw 18 ;
dw 2 ;
dd 0 ;
dd 0 ;
db 0 ;
db 0 ;
db 0x29 ;
dd 0x1CE57A7E;
db 'NO NAME ' ;
db 'FAT12 ' ;

inicio:
xor ax, ax; point the segments to zero
mov ds, ax ;
mov es, ax ;
xor dl, dl ;
cli ; disable interruptions
mov ax,0x9000 ;
mov ss,ax ; setup a stack
mov sp,0 ;
sti ; enable interruptions
mov si, mensagemboot ; move para o registrador si, mensagemboot
call mensagem ;
mov si, ponto; Print some messages and start loading the file
call mensagem ;
call carregador;

mensagem:
lodsb ;
cmp al, 0 ;
jz cada ; prints a message using the 0eh service of the BIOS video interruption
mov ah, 0eh ;
mov bh, 1;
int 0x10 ;
jmp mensagem ;
cada:
ret ; return
;-------------------------------------------------------------------------------------------------------------------
erro:
mov si, mensagemerro;
call mensagem; print an error message and hang up
jmp short $;
;-------------------------------------------------------------------------------------------------------------------

carregador:
mov si, ponto;
call mensagem ;
mov bx, alvo ; (ES:BX) is our buffer so we set it to alvo
mov ax, 020Eh ;
mov cx, 0002h ;
xor dl, dl ; read a sector using the BIOS disk interruption
mov dh, 01h ;
int 13h;
jc erro; if carry, print an error message
mov di, alvo; set our destination
mov dx, 224; set up the number of entries in the main directory
procura:
mov cx, 11; our filename contain 11 bytes
mov si, arquivo; si = filename
rep cmpsb; compare what we got with the file name
jz achou; if we found it, go to achou
dec dx; otherwise, loop until we find it, or print an error message
cmp dx, 0;
jz erro;
add di, 32;
;
jmp procura;
achou:
mov si, ponto;
call mensagem ;
mov eax, [di+17]; get the file size
mov [osfile], eax; save in osfile
add eax, 512-1; discover how much sectors he uses
shr eax, 9;
push ax; save it
mov ax, [di+15]; get it´s first cluster
push ax; save ax
mov ax, 209h;
mov bx, alvo;
mov cx, 0002h; load our first FAT
xor dx, dx ;
int 13h;
jnc fat_carregada; if successfull, go to fat_carregada
mov si, ponto;
call mensagem ;
mov ax, 208h;
mov cl, 0bh;
int 13h;
mov ax, 201h; otherwise, try to load the 2nd FAT
mov bx,alvo + 512*8;
mov cl, 01h;
mov dh, 1;
int 13h;
jc erro1; if we had any error, we print an error message
jnc fat_carregada; otherwise jump to fat_carregada
erro1:
jmp erro; go to error
fat_carregada:
mov si, ponto;
call mensagem ;
pop ax; restore ax
pop cx; cx = file size
mov bx, buffer; read it on buffer
mov es, bx;
proximo_cluster:
pusha; save all regs
add ax, 31; get the real position on the floppy
;-------------------------------------------------------------------------------------------------------------------
; Convert to CHS
; CL := (AX MOD 18)+1
; CH := AX DIV 36
; DH := (AX DIV 18) AND 1
; DL := 0 (floppy)
;-------------------------------------------------------------------------------------------------------------------
xor dx, dx ;
mov bx, 18;
div bx;
mov ch, al;
inc dx;
mov cl, dl;
and al, 1;
mov dl, 0;
mov dh, al;
shr ch, 1;
mov ax, 201h; than read the CHS
mov bx, 0;
int 13h;
jc erro1; if error, print an error message and hang
popa; restore the regs
mov bx, ax; multiply per 1,5. If impar, we got the next clust, if par, convert it to the next
shl bx, 1; cluster
add bx, ax;
shr bx, 1;
test ax, 1;
mov ax, [alvo + bx]; move it to the memory
jz cluster_1; and get the next
shr ax, 4; now convert, if par, the number to the next cluster number
cluster_1:
and ax, 000011111111111b; get only 12 bits
cmp ax, 0000h; check if the cluster is empty
jz erro1; if is empty, print an error message and hang
cmp ax, 0ff7h; check if we have a bad cluster
jz erro1; if we have, print an error message and hang
mov bx, es; get the current segment position
add bx, 512/16; point to the next position, to avoid writting above
mov es, bx; reload es
loop proximo_cluster; repete until we finish the file
mov ax, buffer; reload the segments with our target
mov ds, ax;
mov es, ax
mov fs, ax
mov gs, ax
push eax; save eax on stack
jmp buffer:0000h; go to our kernel loader
;-------------------------------------------------------------------------------------------------------------------
; Data
;-------------------------------------------------------------------------------------------------------------------
mensagemboot db 'Booting on Axion Operating System',13,10,0
mensagemerro db 13,10,'Error!',13,10,0
ponto db '.',0
arquivo db 'AXION SYS'
osfile dd 0
buffer equ 0x1000
alvo equ 0x0800

times 510-($-$$) db 0; boot signature
dw 0AA55H; [/codebox]


Uwagi proszę kierować na pw
 
Status
Zamknięty.
Do góry