Bona Fide OS Developer
View unanswered posts | View active topics It is currently Tue Mar 19, 2024 2:13 am



Post new topic Reply to topic  [ 8 posts ] 
 .img size problem, using Gregor Brunmar solution 
Author Message

Joined: Thu Jan 13, 2011 10:56 am
Posts: 13
Location: Costa Rica
Post .img size problem, using Gregor Brunmar solution
Hi, the file a.img has a size bound?

when i compile my source code it weights 30 kb and works fine, but when i add more
code to the a.img, it weights 34 kb and the OS crashes.

In the attachment files when i uncomment the function:
"void llenarPantallaHileraAux(char* hilera,byte elColorChar,byte elColorFondo,int residuo)" in the video.cpp
file, lines 319-354 it halts when i run it.

I am using Oracle VM VirtualBox 3.2.12, windows xp 32-bits sp2, the built-utils of Mingw from CodeBlocks 10.05.
I have tried Qemu but nothing.

a_babel.img and a_cuadrado.img are examples of image files that works fine for me.

Sorry for my english, Thanks!

_________________
"De veras hijo: Todas las estrellas han partido, pero nunca se pone más oscuro que cuando va a amanecer" - Isaac Felipe Azofeifa


Thu Jan 13, 2011 11:04 am
Profile YIM WWW

Joined: Thu Jan 13, 2011 10:56 am
Posts: 13
Location: Costa Rica
Post Re: .img size problem, using Gregor Brunmar solution
Sorry but i can not load files!, neither .zip, .tar, .7z, .h, .asm?

_________________
"De veras hijo: Todas las estrellas han partido, pero nunca se pone más oscuro que cuando va a amanecer" - Isaac Felipe Azofeifa


Thu Jan 13, 2011 11:12 am
Profile YIM WWW

Joined: Thu Jan 13, 2011 10:56 am
Posts: 13
Location: Costa Rica
Post Re: .img size problem, using Gregor Brunmar solution
Ok i used this bootloader.asm code from Brunmar:

Code:
;CREDITOS: Gregor Brunmar, www.osdever.net/tutorials/brunmar/tutorial_03.php

section .text
   
[BITS 16]       ; We need 16-bit intructions for Real mode

[ORG 0x7C00]    ; The BIOS loads the boot sector into memory fixed location 0x7C00

reset_drive:
        mov ah, 0               ; RESET-command
        int 13h                 ; Call interrupt 13h
        or ah, ah               ; Check for error code
        jnz reset_drive         ; Try again if ah != 0

        mov ax, 0
        mov es, ax
        mov bx, 0x1000          ; Destination address = 0000:1000

        mov ah, 02h             ; READ SECTOR-command
        mov al, 19h             ; Number of sectors to read = 1   
        mov ch, 0               ; Cylinder = 0
        mov cl, 02h             ; Sector = 2
        mov dh, 0               ; Head = 0
        int 13h                 ; Call interrupt 13h
        or ah, ah               ; Check for error code
        jnz reset_drive         ; Try again if ah != 0
      
      ;CAMBIAMOS A MODO GRAFICO, no hay retorno a modo texto con la implementacion actual...
      ;mov al,13h   ;320*200, 256 colores
      mov ax,0012h ;640*480, 16 colores
      int 10h
      ;
      
        cli                     ; Disable interrupts, we want to be alone
      
        xor ax, ax
        mov ds, ax              ; Set DS-register to 0 - used by lgdt

        lgdt [gdt_desc]         ; Load the GDT descriptor

        mov eax, cr0            ; Copy the contents of CR0 into EAX
        or eax, 1               ; Set bit 0
        mov cr0, eax            ; Copy the contents of EAX into CR0

        jmp 08h:clear_pipe      ; Jump to code segment, offset clear_pipe
      
[BITS 32]                       ; We now need 32-bit instructions
clear_pipe:
        mov ax, 10h             ; Save data segment identifyer
        mov ds, ax              ; Move a valid data segment into the data segment register
        mov ss, ax              ; Move a valid data segment into the stack segment register
        mov esp, 090000h        ; Move the stack pointer to 090000h

        jmp 08h:01000h          ; Jump to section 08h (code), offset 01000h
      
gdt:                    ; Address for the GDT

gdt_null:               ; Null Segment
        dd 0
        dd 0

gdt_code:               ; Code segment, read/execute, nonconforming
        dw 0FFFFh
        dw 0
        db 0
        db 10011010b
        db 11001111b
        db 0

gdt_data:               ; Data segment, read/write, expand down
        dw 0FFFFh
        dw 0
        db 0
        db 10010010b
        db 11001111b
        db 0

gdt_end:                ; Used to calculate the size of the GDT



gdt_desc:                       ; The GDT descriptor
        dw gdt_end - gdt - 1    ; Limit (size)
        dd gdt                  ; Address of the GDT



times 510-($-$$) db 0           ; Fill up the file with zeros //RELLENA LOS 512 CON CEROS

        dw 0AA55h                ; Boot sector identifyer



and this .bat file:

Code:
@echo off

::codigo ensamblador

nasm -f bin bootsect.asm -o bootsect.bin
nasm funcionesAsm.asm -f win32 -o funcionesAsm.o

::codigo c/c++

gcc -w makeboot.c -o makeboot.exe
g++ -c main.cpp -o main.o
g++ -c ports.cpp -o ports.o -masm=intel
g++ -c video.cpp -o video.o
g++ -c sonido.cpp -o sonido.o

::linkeamos
ld -e __Z9principalv -share -Ttext 0x01000 -o kernel.o main.o video.o ports.o sonido.o funcionesAsm.o

::otros

objcopy -R .note -R .comment -S -O binary kernel.o kernel.bin
makeboot a.img bootsect.bin kernel.bin
pause


I know that because my kernel.bin is 33kb long it could be overlaping the bootloader at 0x7c00, to solve it i tried change the place in ram where the kernel is loaded from 0x1000 to 0xFFFFF (where te bios ram space end) in both: the bootloader.asm and the .bat file. But nothing.

_________________
"De veras hijo: Todas las estrellas han partido, pero nunca se pone más oscuro que cuando va a amanecer" - Isaac Felipe Azofeifa


Fri Jan 14, 2011 10:48 am
Profile YIM WWW

Joined: Wed Oct 14, 2009 9:39 am
Posts: 198
Location: United States
Post Re: .img size problem, using Gregor Brunmar solution
What is the size of the floppy image file? It should be 1.44MB.

_________________
Charles Timko
push %esp ;Musings of a computer addict


Fri Jan 14, 2011 11:51 am
Profile WWW

Joined: Thu Jan 13, 2011 10:56 am
Posts: 13
Location: Costa Rica
Post Re: .img size problem, using Gregor Brunmar solution
Well, the current size of the .img file is 34 kb, I have compiled smallest ones and they have work before with Virtual Box. them.

_________________
"De veras hijo: Todas las estrellas han partido, pero nunca se pone más oscuro que cuando va a amanecer" - Isaac Felipe Azofeifa


Fri Jan 14, 2011 12:43 pm
Profile YIM WWW

Joined: Thu Jan 13, 2011 10:56 am
Posts: 13
Location: Costa Rica
Post Re: .img size problem, using Gregor Brunmar solution
Well, I realize that i can load the kernel after the boot loader, this is my plan:

+-------------------+
| 0x7c00: bootstrap |
+-------------------+
| 0xa000: kernel |
+-------------------+
| 0x90000: stack |
+-------------------+

so i modified the previous code into this:

Bootsect.asm

Code:
;CREDITOS: Gregor Brunmar, www.osdever.net/tutorials/brunmar/tutorial_03.php
   
section .text
   [BITS 16]       ; We need 16-bit intructions for Real mode
   [ORG 0x7C00]    ; The BIOS loads the boot sector into memory fixed location 0x7C00

   main:
      call imprimir
      call reset_drive
      call copiarFloppyAMemoria
      
      ;CAMBIAMOS A MODO GRAFICO, no hay retorno a modo texto con la implementacion actual...
      mov ax,0012h ;640*480, 16 colores
      int 10h
      
        cli                     ; Disable interrupts, we want to be alone
      
        xor ax, ax
        mov ds, ax              ; Set DS-register to 0 - used by lgdt

        lgdt [gdt_desc]         ; Load the GDT descriptor

        mov eax, cr0            ; Copy the contents of CR0 into EAX
        or eax, 1               ; Set bit 0
        mov cr0, eax            ; Copy the contents of EAX into CR0

        jmp 08h:clear_pipe      ; Jump to code segment, offset clear_pipe
      
      [BITS 32]                       ; We now need 32-bit instructions
      clear_pipe:
            mov ax, 10h             ; Save data segment identifyer
            mov ds, ax              ; Move a valid data segment into the data segment register
            mov ss, ax              ; Move a valid data segment into the stack segment register
            mov esp, 090000h        ; Move the stack pointer to 090000h

            jmp 08h:0a000h           ; Jump to section 08h (code), offset 01000h, sin retorno
   
   ;imprimir cadena en ds:dx
   imprimir:
      pusha
      
      mov ah,0Ah
      mov al,'a'
      mov bh,0
      mov bl,07h
      mov cx,1
      int 10h
      
      popa
      ret
   
   reset_drive:
      pusha
        mov ah, 0               ; RESET-command
        int 13h                 ; Call interrupt 13h
        or ah, ah               ; Check for error code
        jnz reset_drive         ; Try again if ah != 0
      popa
      ret
   
   copiarFloppyAMemoria:
      pusha
      ;inicializamos segmento(es):desplazamiento(bx)
      mov ax, 0
        mov es, ax
        mov bx,0a000h          ; Destination address = xxxx:xxxx, 7C00h + (18d*512d) = A000
      
      ;inicializamos cilindro(ch) y cabeza (dh)
      mov ch,byte 1   ;el cilindro 0 (de 18 sectores) pertenece al bootstrap
      mov dh,0      ;basta con una cara del plato ((80-1) pistas * 18 sectores = 711Kbytes)
      
      ;especificamos funcion ah=2, int13h
      mov ah, 2   ; READ SECTOR-command
      mov al, 1   ; Number of sectors to read
      mov dl, 0   ; usar el floppy
      
      elFor1:
         mov cl,0   ;sector actual
         
         elFor2:
            int 13h
            or ah,ah               ; Check for error code
            jz comprobarDesplazamiento    ; ah=0 si no hubo errores
            ;sino reseteamos floppy
            call reset_drive
            
            comprobarDesplazamiento:
               ;incrementamos desplazamiento en 512 bytes y aumentamos # de sector
               add bx,512d
               inc cl
               ;comprobamos que bx<65536 sino hacemos bx=0 y es++
               cmp bx,word 65535d
               jle finElFor2
               ;sino
               xor bx,bx
               
               pusha
               mov ax,es
               inc ax
               mov es,ax
               popa
               
         finElFor2:
            cmp cl,18d
            jl elFor2
      
      finElFor1:
         cmp ch,80d
         jl elFor2
      
      ;salimos
      popa
      ret
   
   gdt:                    ; Address for the GDT

   gdt_null:               ; Null Segment
         dd 0
         dd 0

   gdt_code:               ; Code segment, read/execute, nonconforming
         dw 0FFFFh
         dw 0
         db 0
         db 10011010b
         db 11001111b
         db 0

   gdt_data:               ; Data segment, read/write, expand down
         dw 0FFFFh
         dw 0
         db 0
         db 10010010b
         db 11001111b
         db 0

   gdt_end:                ; Used to calculate the size of the GDT

   gdt_desc:                       ; The GDT descriptor
         dw gdt_end - gdt - 1    ; Limit (size)
         dd gdt                  ; Address of the GDT

   times 510-($-$$) db 0           ; Fill up the file with zeros //RELLENA LOS 512 CON CEROS

         dw 0AA55h                ; Boot sector identifyer


.bat

Code:
@echo off

nasm -f bin bootsect.asm -o bootsect.bin
nasm funcionesAsm.asm -f win32 -o funcionesAsm.o

::codigo c/c++

gcc -w makeboot.c -o makeboot.exe
g++ -c main.cpp -o main.o
g++ -c ports.cpp -o ports.o -masm=intel
g++ -c video.cpp -o video.o
g++ -c sonido.cpp -o sonido.o

ld -e __Z9principalv -share -Ttext 0xA000 -o kernel.o main.o video.o ports.o sonido.o funcionesAsm.o

objcopy -R .note -R .comment -S -O binary kernel.o kernel.bin
makeboot a.img bootsect.bin kernel.bin



But without success, I can't even see the 'a' in the screen, any ideas would be appreciated.

_________________
"De veras hijo: Todas las estrellas han partido, pero nunca se pone más oscuro que cuando va a amanecer" - Isaac Felipe Azofeifa


Mon Jan 17, 2011 12:04 am
Profile YIM WWW

Joined: Thu Jan 13, 2011 10:56 am
Posts: 13
Location: Costa Rica
Post Re: .img size problem, using Gregor Brunmar solution
Sorry, pulse of idiocy... i changed into video mode after printing in screen the 'A'.

_________________
"De veras hijo: Todas las estrellas han partido, pero nunca se pone más oscuro que cuando va a amanecer" - Isaac Felipe Azofeifa


Mon Jan 17, 2011 10:48 am
Profile YIM WWW

Joined: Thu Jan 13, 2011 10:56 am
Posts: 13
Location: Costa Rica
Post Re: .img size problem, using Gregor Brunmar solution
Of course, "ret" does not function here, i have to implement it using jmp's and label's.

_________________
"De veras hijo: Todas las estrellas han partido, pero nunca se pone más oscuro que cuando va a amanecer" - Isaac Felipe Azofeifa


Mon Jan 17, 2011 11:48 am
Profile YIM WWW
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by Vjacheslav Trushkin and tweaked by the BF Team.