C++ kernel, increasing KSIZE in the bootloader crash the os

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
jeandaniel
Posts: 14
Joined: Wed Nov 14, 2007 3:26 pm
Location: Paris, France

C++ kernel, increasing KSIZE in the bootloader crash the os

Post by jeandaniel »

Hello, we are two student who make a C++ kernel.
We have already make Threads, New / Delete, STL integration ...
When we want to add more code, we need to increase the KSIZE variable in our bootsect.asm.
This is the code

Code: Select all

%define CS_ACCES        10011011b
%define DS_ACCES        10010011b
%define	BASE	0x100
%define KSIZE	44

[BITS 16]
[ORG 0x0]

jmp start

%include "GDT.INC"

start:
	mov [bootdrv],dl	; recuparation de l'unite de boot

; initialisation des segments en 0x07C0
	mov ax,0x07C0
	mov ds,ax
	mov es,ax
	mov ax,0x8000	; stack en 0xFFFF
	mov ss,ax
	mov sp, 0xf000

; charger le noyau
	xor ax,ax
	int 0x13

	push es
	mov ax,BASE
	mov es,ax
	mov bx,0
	
	mov ah,2
	mov al,KSIZE
	mov ch,0
	mov cl,2
	mov dh,0
	mov dl,[bootdrv]
	int 0x13
	pop es


; initialisation de la GDT
; descInit base(32),limite(20/32),acces(8),flags(4/8),adresse(16)
	descInit 0,0xFFFFF,CS_ACCES,1101b,gdt_cs
	descInit 0,0xFFFFF,DS_ACCES,1101b,gdt_ds

; initialisation du pointeur sur la GDT
	mov ax,gdtend	; calcule la limite de GDT
	mov bx,gdt
	sub ax,bx
	mov word [gdtptr],ax

	xor eax,eax		; calcule l'adresse lineaire de GDT
	mov ax,ds
	mov bx,gdt
	call calcadr
	mov dword [gdtptr+2],ecx

; passage en modep
	cli
	lgdt [gdtptr]	; charge la gdt
	mov eax,cr0
	or	ax,1
	mov cr0,eax		; PE mis a 1 (CR0)

	jmp next
next:
	mov ax,0x10		; segment de donne
	mov ds,ax
	mov fs,ax
	mov gs,ax
	mov es,ax
	mov ss,ax
	mov esp,0x9F000	

	jmp dword 0x8:0x1000

end:
	jmp end

gdt:
gdt_null:
	dw 0,0,0,0
gdt_cs:
	dw 0,0,0,0
gdt_ds:
	dw 0,0,0,0
gdtend:

gdtptr:
	dw	0x0000		; limite
	dd	0			; base

bootdrv: db 0


;--------------------------------------------------------------------
;; NOP jusqu'a 510
times 510-($-$$) db 144
dw 0xAA55
:(

our kernel size is 22658 Ko
any idea ? :/
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post by AJ »

Hi,

Your Kernel starts from memory location 0x0100:0x0000 and has reached 0x5800 bytes long (last address is 0x6800). Your boot loader is at 0x7C00, which means you are 0x1400 bytes away from disaster anyway, assuming a 512b sector size. I would suggest loading the kernel at a higher location.

Also, I would suggest using int 0x13 with AX=0x0201 and using a loop to load your sectors. By increasing ES by 0x20 on each pass, you do not risk segment overruns. I believe that the maximum value acceptable by AL on this function also varies from BIOS to BIOS.

Cheers,
Adam
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post by AJ »

Oh - while we're on the topic, it would be better long term to use a file system on the disk so that you don't need to manually update the boot loader each tie you recompile the kernel.

HTH,
Adam
jeandaniel
Posts: 14
Joined: Wed Nov 14, 2007 3:26 pm
Location: Paris, France

Post by jeandaniel »

thank you a lot it works :)
i put my kernel at 0x8000
Post Reply