Boot loader does not load more than 52 Kb

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
AlexanderSilvaB
Posts: 12
Joined: Tue May 08, 2012 6:19 am

Boot loader does not load more than 52 Kb

Post by AlexanderSilvaB »

Hi, i'm having a problem with my Operational System, I have the boot loader that load a file called SET32 that basically set the 32 bit mode, active a20 keyboard and load the 32 bit kernel. The problem is that if the kernel file have more than 52 Kb of size, it is never loaded and the system stop. Please, help me if you can.

Here is the code of SET32 file.

Code: Select all

SET32 - Souce code
-----------------------------

; *********************************************
; Carregador 32 bit
; Lemon X OS
; *********************************************

; Esse arquivo irá carregar o kernel de 32 bits

bits 16 								; Estaremos no modo real

org 0x500

jmp principal

; -------------------------------------
; Diretivas do processador
; -------------------------------------


%include "stdio.inc"					; Rotinas i/o basicas
%include "Gdt.inc"						; Rotinas Gdt
%include "A20.inc"						; A20
%include "Fat12.inc"                    ; Drive FAT12
%include "common.inc"   

; -------------------------------------
; Secao de dados
; -------------------------------------


msgCarregando db 0x0D, 0x0A, "Prepando para carregar o sistema...", 0x00
msgFalha db 0x0D, 0x0A, "Erro! Kernel inexistente ou corrompido. Pressione uma tecla para reiniciar.", 0x0D, 0x0A, 0x0A, 0x00
msgPergunta db 0x0D, 0x0A, "Deseja habilitar o modo grafico? 1 = SIM", 0x00

setVideo:
		mov ah, 00h
		mov al, 13h
		int 10h
		;mov ax, 4f02h
		;mov bx, 101h
		;int 10h
		ret

principal:
	cli									; Limpar interruptores
	xor ax, ax							; Segmentos nulos
	mov ds, ax
	mov es, ax
	mov ax, 0x9000						; Pilha comecando em 0x9000-0xffff
	mov ss, ax
	mov sp, 0xFFFF
	sti
	
	; Instalando Gdt
	call InstallGDT
	
	; Ativar A20
	
	call EnableA20_KKbrd_Out
	
	; Mensagem
	mov si, msgCarregando
	call Puts16
	
	;-------------------------------;
	; Iniciando sistema de arquivos ;
	;-------------------------------;

	call    LoadRoot                ; Carregando tabela root

	;-------------------------------;
	; Carregando Kernel              ;
	;-------------------------------;

	mov     ebx, 0                  
	mov     bp, IMAGE_RMODE_BASE
	mov     si, ImageName           ; Arquivo a ser carregado
	call    LoadFile                ; Carregando arquivo
	mov     dword [ImageSize], ecx  ; salvando tamanho do kernel
	cmp     ax, 0                   ; Teste de sucesso
	je      EntrarEstagio3          ; Sim - entre em estagio 3
	mov     si, msgFalha            ; Nao - Mostrar msg erro
	call    Puts16
	mov     ah, 0
	int     0x16                    ; Esperar tecla
	jmp 0FFFFh:0000h                ; reiniciar
	cli                             
	hlt

	
	; Ir a modo protegido
	EntrarEstagio3:
		mov si, msgPergunta
		call Puts16
		mov ah, 00h
		int 16h
		push ax
		mov ah, 0eh
		int 10h
		pop ax
		cmp al, '1'
		jnz pularSetVideo
		call setVideo
		pularSetVideo:
		cli									; Limpar interruptores
		mov eax, cr0						; Colocar 0 em cr0 -- Entrar em modo protegido
		or eax, 1
		mov cr0, eax
		
		jmp CODE_DESC:Estagio3					;Pulo longo para consertar Cs. Lembre-se que o seletor de codigo e 0x8
	
	; Nota: Não reabilitar interruptores
	; Isso sera feito no estagio 32
	
; ---------------------------
; Estagio 3
; ---------------------------
	
; Iniciando sistema de 32 bits
	
bits 32

Estagio3:
	; Setar registradores
	mov ax, DATA_DESC						; Setar segmentos de dados para seletor de dados 0x10
	mov ds, ax
	mov ss, ax
	mov es, ax
	mov esp, 90000h						; Iniciando pilha em 90000h
	

	call ClrScr32

	;-------------------------------;
	; Copiar kernel para 1MB            ;
	;-------------------------------;

	CopiarImagem:
			 mov    eax, dword [ImageSize]
			 movzx  ebx, word [bpbBytesPerSector]
			 mul    ebx
			 mov    ebx, 4
			 div    ebx
			 cld
			 mov    esi, IMAGE_RMODE_BASE
			 mov    edi, IMAGE_PMODE_BASE
			 mov    ecx, eax
			 rep    movsd                  ; copiar imagem ao endereco protegido

			;---------------------------------------;
			;   Executar Kernel                      ;
			;---------------------------------------;

			jmp     CODE_DESC:IMAGE_PMODE_BASE; Ir para Kernel
	
	; Parar
	
	cli
	hlt								; Retornar


Cammon.inc - Source code
---------------------


%ifndef _COMMON_INC_INCLUDED
%define _COMMON_INC_INCLUDED

; where the kernel is to be loaded to in protected mode
%define IMAGE_PMODE_BASE 0x100000

; where the kernel is to be loaded to in real mode
%define IMAGE_RMODE_BASE 0x3000

; kernel name (Must be 11 bytes)
ImageName     db "KERNEL  LMS"

; size of kernel image in bytes
ImageSize     dw 0

%endif
--------------------------------------------------------------------
Thank you.


edit:
added code tags
JAAman
Lemon X OS
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Boot loader does not load more than 52 Kb

Post by Combuster »

Code tags, please?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: Boot loader does not load more than 52 Kb

Post by Solar »

Commenting in English is also a nice feat.
Every good solution is obvious once you've found it.
User avatar
JAAman
Member
Member
Posts: 879
Joined: Wed Oct 27, 2004 11:00 pm
Location: WA

Re: Boot loader does not load more than 52 Kb

Post by JAAman »

i added code tags for you, this time, but please use them yourself in the future
AlexanderSilvaB
Posts: 12
Joined: Tue May 08, 2012 6:19 am

Re: Boot loader does not load more than 52 Kb

Post by AlexanderSilvaB »

Sorry for not posting the code with comments in English. It is that this is not my native language, so I just copied my code, so a thousand apologies. The source code above is from the Stage2 of Operating System Development Series (http://www.brokenthorn.com/Resources/OSDevIndex.html). Thank you.
Lemon X OS
User avatar
Griwes
Member
Member
Posts: 374
Joined: Sat Jul 30, 2011 10:07 am
Libera.chat IRC: Griwes
Location: Wrocław/Racibórz, Poland
Contact:

Re: Boot loader does not load more than 52 Kb

Post by Griwes »

The obvious reason seems to be that after loading 52 KiB of data using interrupts, you tell BIOS "load my data above the highest address you can address". AFAIR, this limit varies between BIOSes. The solution is to load it chunk-by-chunk, jumping between real mode and protected mode, and copying it at some higher address, where it will be used after final jump to protected mode.
Reaver Project :: Repository :: Ohloh project page
<klange> This is a horror story about what happens when you need a hammer and all you have is the skulls of the damned.
<drake1> as long as the lock is read and modified by atomic operations
AlexanderSilvaB
Posts: 12
Joined: Tue May 08, 2012 6:19 am

Re: Boot loader does not load more than 52 Kb

Post by AlexanderSilvaB »

Thank Griwes, I understood what he meant. I decided to use Grub as my boot loader, so my system can run in Multiboot ... But anyway thank you guys ...
Lemon X OS
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: Boot loader does not load more than 52 Kb

Post by egos »

- Move even value into sp.
- Don't destroy EBDA.

Look for details:
Loading Large Kernel's
Bootsector problem(need help)
Problems with a beginner bootloader.

- Use well done stage 1.

If you use FAT12 on the floppy (image) 2x80x18 you can take my old boot loader for the floppy. It can load two files starting from address 8000h and up to top of available base memory (~600 kb).
If you have seen bad English in my words, tell me what's wrong, please.
AlexanderSilvaB
Posts: 12
Joined: Tue May 08, 2012 6:19 am

Re: Boot loader does not load more than 52 Kb

Post by AlexanderSilvaB »

Thank you egos... :D
Lemon X OS
Post Reply