feat: ajout des fonctions de debug par GDB

This commit is contained in:
Nicolas Hordé 2019-07-13 13:33:26 +02:00
parent 53b445a652
commit 2a7798dfd3
5 changed files with 220 additions and 188 deletions

View File

@ -7,199 +7,216 @@ include "..\include\divers.h"
org 7C00h
jmp boot
jmp Boot
bootsec bootinfo "COS2000A","COS2000 ","FAT12 "
errorloading db " [Erreur]",0dh,0ah,0
okloading db "Recherche noyau ",0Dh,0ah," -"
sys db "SYSTEME SYS",0
syst db " [ Ok ]",0dh,0ah,"Chargement ",0
dot db ".",0
Boot_Message db "Cos2000",0
Entre_Message db "Search",0
Loading_Message db "Load",0
System_File db "As",0,"y",0,"s",0,"t",0,"e",0,0x0F,0,0x38,"m",0,"e",0,".",0,"s",0,"y",0,"s",0,0,0,0,0,0xFF,0xFF
Is_Ok db " [ OK ]",0x0A,0x0D,0
Is_Failed db " [ERROR]",0x0A,0x0D,0
The_Dot db '.',0
errorboot:
mov si,errorloading
call showstr
mov ah,0
int 16h
int 19h
Boot_Error:
mov si,Is_Failed
call ShowString
xor ax,ax
int 0x16
int 0x19
boot:
mov [bootsec.bootdrive],dl
cli
mov ax,09000h
mov ss,ax
mov sp,0FFFFh
sti
boot2:
push cs
push cs
pop es
pop ds
xor ax,ax
mov dl,[bootsec.bootdrive]
int 13h
jc errorboot
mov si,okloading
call showstr
mov cx,[bootsec.reservedsectors]
add cx,[bootsec.hiddensectorsh]
adc cx,[bootsec.hiddensectorsl]
push cx
mov bx,[bootsec.sectorsperfat]
mov di,bufferfat
Boot_Ok:
mov si,Is_Ok
call ShowString
ret
Boot:
push cs
push cs
pop es
pop ds
mov [bootsec.bootdrive],dl
cli
mov ax,0x9000
mov ss,ax
mov sp,0xFFFF
sti
mov si,Boot_Message
call ShowString
xor ax,ax
int 0x13
jc Boot_Error
mov cx,[bootsec.reservedsectors]
add cx,[bootsec.hiddensectorsh]
adc cx,[bootsec.hiddensectorsl]
mov bx,[bootsec.sectorsperfat]
mov di,bufferfat
push bx
push cx
readfat:
call readsector
jc errorboot
inc cx
add di,[bootsec.sectorsize]
dec bx
jnz readfat
pop cx
xor ax,ax
mov al,[bootsec.fatsperdrive]
mov bx,[bootsec.sectorsperfat]
mul bx
add cx,ax
mov ax,32
mul [bootsec.directorysize]
div [bootsec.sectorsize]
add ax,cx
sub ax,2
mov word [bootsec.reservedfornt],ax
xor dx,dx
checkroot:
mov di,buffer
call readsector
jc errorboot
xor bx,bx
findnext:
cmp byte [di],0
je errorboot
cmp byte [di],0E5h
je no
cmp byte [di],041h
je no
mov si,dot
call showstr
push di cx
mov si,sys
mov cx,11
rep cmpsb
pop cx di
je oksystem
no:
add di,32
add bx,32
inc dx
cmp dx,[bootsec.directorysize]
ja errorboot
cmp bx,[bootsec.sectorsize]
jb findnext
inc cx
jmp checkroot
oksystem:
mov si,syst
call showstr
mov cx,[di+26]
mov ax,8000h
mov es,ax
push es
mov di,0000h
push 0010h
mov si,dot
xor ax,ax
fatagain:
cmp cx,0FF0h
jae finishload
push cx
add cx,word [bootsec.reservedfornt]
call readsector
pop cx
jc errorboot
inc ax
call showstr
add di,[bootsec.sectorsize]
call getfat
jnc fatagain
finishload:
retf
call ReadSector
jc Boot_Error
inc cx
add di,[bootsec.sectorsize]
dec bx
jnz readfat
pop cx
pop bx
xor ax,ax
mov al,[bootsec.fatsperdrive]
mul bx
add cx,ax
mov ax,32
mul word [bootsec.directorysize]
div word [bootsec.sectorsize]
add ax,cx
sub ax,2
mov word [bootsec.reservedfornt],ax
xor dx,dx
call Boot_Ok
mov si,Loading_Message
call ShowString
Find_System:
mov di,buffer
call ReadSector
jc Near Boot_Error
xor bx,bx
Next_Root_Entrie:
cmp byte [di],0
je near Boot_Error
push di
push cx
mov si,System_File
mov cx,32
rep cmpsb
pop cx
pop di
je System_Found
add di,32
add bx,32
inc dx
cmp dx,[bootsec.directorysize]
ja near Boot_Error
cmp bx,[bootsec.sectorsize]
jb Next_Root_Entrie
inc cx
jmp Find_System
System_Found:
call Boot_Ok
mov si,Entre_Message
call ShowString
mov cx,[di+26+32]
mov ax,0x8000
mov es,ax
push es
mov di,0x0
push 0x10
mov si,The_Dot
Resume_Loading:
cmp cx,0x0FF0
jae Finish_Loading
push cx
add cx,word [bootsec.reservedfornt]
call ReadSector
pop cx
jc near Boot_Error
call ShowString
add di,[bootsec.sectorsize]
call NextFatGroup
jc near Boot_Error
jmp Resume_Loading
Finish_Loading:
call Boot_Ok
retf
;=============READSECTOR (Fonction 01H)===============
;Lit le secteur CX et le met en es:di
;-> AH=1
;====================READSECTOR=======================
;Lit le secteur logique LBA CX et le met en es:di
;-> CX (limité à 65536 secteurs, soit 32 Mo avec secteur 512 octets)
;<- Flag Carry si erreur
;=====================================================
readsector:
push ax bx cx dx si
mov ax,cx
xor dx,dx
div [bootsec.sectorspertrack]
inc dl
mov bl,dl
xor dx,dx
div [bootsec.headsperdrive]
xchg dl,dh
mov cx,ax
xchg cl,ch
shl cl,6
or cl, bl
mov bx,di
mov si, 4
mov al, 1
tryagain:
mov ah, 2
mov dl,[bootsec.bootdrive]
int 13h
jnc done
dec si
jnz tryagain
done:
pop si dx cx bx ax
ret
getfat:
push ax bx dx di
mov di,bufferfat
mov ax,cx
mov bx,ax
and bx,0000000000000001b
shr ax,1
mov cx,3
mul cx
add di,ax
cmp bx,0h
jnz evenfat
oddfat:
mov dx,[di]
and dx,0FFFh
mov cx,dx
jmp endfat
evenfat:
mov dx,[di+1]
and dx,0FFF0h
shr dx,4
mov cx,dx
endfat:
pop di dx bx ax
ReadSector:
pusha
mov ax,cx
xor dx,dx
div word [bootsec.sectorspertrack]
inc dl
mov bl,dl
xor dx,dx
div word [bootsec.headsperdrive]
mov dh, [bootsec.bootdrive]
xchg dl,dh
mov cx,ax
xchg cl,ch
shl cl,6
or cl, bl
mov bx,di
mov si, 4
mov al, 1
Read_Again:
mov ah, 2
int 0x13
jnc Read_Done
dec si
jnz Read_Again
Read_Done:
popa
ret
showstr:
push ax bx si
again:
;===================NEXTFATGROUP======================
;Renvoie en CX le groupe qui succède dans la FAT le groupe CX
;-> CX
;<-
;=====================================================
NextFatGroup:
push bx
push dx
push di
mov ax,cx
mov bx,ax
and bx,0000000000000001b
shr ax,1
mov cx,3
mul cx
mov di,bufferfat
add di,ax
cmp bx,0
jnz Even_Group
Odd_Group:
mov dx,[di]
and dx,0x0FFF
mov cx,dx
jmp Next_Group_Found
Even_Group:
mov dx,[di+1]
and dx,0xFFF0
shr dx,4
mov cx,dx
Next_Group_Found:
pop di
pop dx
pop bx
ret
;======================SHOWSTR========================
;Affiche la chaine de caractère pointé par ds:si à l'écran
;-> DS, SI
;<- Flag Carry si erreur
;=====================================================
ShowString:
pusha
Next_Char:
lodsb
or al,al
jz fin
mov ah,0Eh
mov bx,07h
int 10h
jmp again
fin:
pop si bx ax
or al,al
jz End_Show
mov ah,0x0E
mov bx,0x07
int 0x10
jmp Next_Char
End_Show:
popa
ret
rb 7C00h+512-2-$
db 055h,0AAh
@ -209,4 +226,3 @@ buffer:
rb 7C00h+512+2048-$
bufferfat:
rb 7C00h+512+4096-$

8
debug/boot.txt Normal file
View File

@ -0,0 +1,8 @@
target remote localhost:1234
set disassembly-flavor intel
set architecture i8086
display/20i $pc+$cs*16
break *0x7c00
cont
clear *0x7c00

9
debug/system.txt Normal file
View File

@ -0,0 +1,9 @@
target remote localhost:1234
set disassembly-flavor intel
set architecture i386
display/20i $pc+$cs*16
break *0x80010
cont
clear *0x80010

View File

@ -3,14 +3,13 @@ all: cos2000.img
cos2000.img:
(dd if=/dev/zero of=cos2000.img count=2880 bs=512)
(mkfs.msdos -F 12 -n "COS2000" cos2000.img)
(fusefat cos2000.img ./mnt -o rw+)
(fusermount ./mnt -u;mkdir -p ./mnt;rm -rf ./mnt/*;fusefat cos2000.img ./mnt -o rw+)
(cp ../noyau/systeme.sys ./mnt/)
(cp ../noyau/systeme.ini ./mnt/)
(cp ../programs/*.ce ./mnt/)
(cp ../programs/*.lib ./mnt/)
(cp ../programs/*.rip ./mnt/)
(cp ../lib/*.lib ./mnt/)
(cp ../system/system.sys ./mnt/;sync)
(sync)
(fusermount ./mnt -u)
(dd if=../boot/boot12.bin of=cos2000.img seek=0 count=1 conv=notrunc;sync)

View File

@ -20,15 +20,15 @@ copy:
test: all copy qemu
view:
view: final/cos2000.img
(hexdump -C ./final/cos2000.img|head -c10000)
view2: boot/boot12.bin
(objdump -D -b binary -mi386 -Maddr16,data16 ./boot/boot12.bin)
debug-boot: all copy qemu-debug
(sleep 2;cgdb -x ./debug/boot.txt)
debug-loader: all copy qemu-debug
(sleep 2;cgdb -x ./debug/loader.txt)
debug-system: all copy qemu-debug
(sleep 2;cgdb -x ./debug/system.txt)