[SOS] Secteur de boot
Chris
uid0 at free.fr
Sam 8 Jan 15:06:04 CET 2005
Salut,
Je suis en train de faire un secteur de boot qui passe en mode protégé
mais j'ai des problèmes (reboot après 3 exceptions cf. Bochs output).
Est-ce que qqun pourrait me dire ce qui ne va pas ? Le problème survient
au jump vers l'OS. Je suis un peu pressé par le temps (projet à terminer
assez vite).
Merci d'avance.
Christian Vincenot
************************myboot.asm******************************
[ORG 7C00h]
[BITS 16]
;------------------DEFS--------------------------------------;
BIOS_DROP equ 0x07C0 ; Where the BIOS dropped us
KSTART equ 2 ;
KSIZE equ 1 ;
KSEG equ 1000h ; Where we'll throw the kernel
;-----------------CODE---------------------------------------;
;Set up our stack
;mov ax, BIOS_DROP ;
;mov ds, ax ;AX = DS = ES = BIOS_DROP
;mov es, ax ;
;mov ax, 0x8000
;mov ss, ax ; let's set up our stack from 0x8000
;mov sp, 0xf000 ; to 0xf000
mov si,takeoff
call bprint ; Greetings !!
;Copy the kernel
mov ax, 0x200 + KSIZE ; service: AH=0x2 (copy), AL=KERNEL_SIZE sectors
;mov es, word [KSEG]
push word KSEG ; ES <- KERNEL_SEG (copy destination)
pop es ;
xor bx, bx ; BX <- 0 (dunno if that has to be...)
mov cx, KSTART ; CX <- KERNEL_START (copy source)
xor dx, dx ; DX <- 0
int 13h
jnc done
mov si, error ; error
call bprint
jmp $
done:
mov si, success
call bprint
cli ; Disable interrupts
xor ax, ax ; ax = ds = 0 (used by lgdt)
mov ds, ax
lgdt [gdtr] ; Load the GDT (segmentation)
mov eax, cr0
or al, 1 ; Protected mode bit <- 0
mov cr0, eax
;jmp $
jmp SYS_CODE_SEL:clear_pipe
;---------------------- PM--------------------------------------------;
[BITS 32]
clear_pipe:
mov ax, SYS_DATA_SEL ; Update DATA Segment
mov ds, ax
mov ss, ax
mov esp, 9000h
k_launch:
;jmp $ ; Uncomment this for testing
;jmp KSEG:0 ; give the hand to the kernel
jmp 1000h
;-----------------VARS---------------------------------------------------;
takeoff db "HI !!",13,10,0
success db "Bootsector: Kernel copy successful !!",13,10,0
error db "Bootsector: Kernel copy error >O<",13,10,0
;GDT Table Definition for segmentation
[BITS 32]
gdtr:
dw gdt_end - gdt - 1 ; GDT limit
dd gdt ; GDT base
gdt:
times 8 db 0 ; NULL Descriptor
SYS_CODE_SEL equ $-gdt
dw 0xFFFF ; limit 15:0
dw 0 ; base 15:0
db 0 ; base 23:16
db 0x9A ; type = present, ring 0, code, non-conforming, readable
db 0xCF ; page granular, 32-bit
db 0 ; base 31:24
SYS_DATA_SEL equ $-gdt
dw 0xFFFF ; limit 15:0
dw 0 ; base 15:0
db 0 ; base 23:16
db 0x92 ; type = present, ring 0, data, expand-up, writable
db 0xCF ; page granular, 32-bit
db 0 ; base 31:24
gdt_end:
;-------------------MISC
FUNCS-------------------------------------------;
;Very simplified print in real mode
bprint:
push ax
push bx
.next:
lodsb ; Load ds:si word to al
cmp al, 0 ; if 0x0 => end of string
jz .end
mov ah, 0x0E ; 0x0e BIOS service -> print to screen
mov bx, 0x0004 ; bx -> attribut (red), al -> caractere ascii
int 0x10 ; INT !!
jmp .next
.end:
pop bx
pop ax
ret
;-------------------Boot sector
signature-------------------------------;
times 510 - ($ - $$) db 0
dw 0xAA55
******************************kern.c****************
void main(void) {
for (;;);
}
******************************BOCHS output**********
00300095414e[CPU ] exception(): 3rd (13) exception with no resolution,
shutdow
Plus d'informations sur la liste de diffusion Sos