Page 2 of 2

Re: Bootsector problem(need help)

Posted: Fri Jul 23, 2010 6:13 am
by achal11
Yippeee It worked :)

thanks gerryg400 thanks egos

@ gerryg400

yes i forgot to initialize es

@egos

enablea20 is wrking fine on my pc
actually i was getting black on black screen
i added ah=7(white on black)
it worked.

first phase over :)

Re: Bootsector problem(need help)

Posted: Fri Jul 23, 2010 6:24 am
by achal11
boot loader is working fine, but when it jumps to c code it resets.

what i m doing is:

gcc -c main.c -o main.o

ld -T link.ld main.o -o main

link.ld:

Code: Select all

OUTPUT_FORMAT("binary")
ENTRY(main)
SECTIONS
{
  .text  0x1000 : {
    *(.text)
  }
  .data  : {
    *(.data)
  }
  .bss  :  { 					
    *(.bss)
  }
}

I'm getting the warning: cannot find entry symbol main ;defaulting to 00001000
( main.bin get created anyways, i m using this file - but it didnt work )

so now i m trying different approach :
i will call another assembly file from bootsector and that file will call main.

I want to know is there any way i can jump to main.c directly???

Re: Bootsector problem(need help)

Posted: Fri Jul 23, 2010 6:39 am
by gerryg400

Code: Select all

gcc -c main.c -o main.o

ld -T link.ld main.o -o main
Think about your tools. When you run these commands you are building a program for your native OS. This includes the startup code. You need to pass some options like -nostdlib to make sure that no native libraries are linked. You also need to supply your own startup code to initialise the C environment and call main. In many cases the startup code is trivial. The startup code will contain the 'start' entry point. Remember you had that warning ?

Re: Bootsector problem(need help)

Posted: Sun Jul 25, 2010 7:13 am
by achal11
well it worked with another asm file .
yes, that entry point will be of second .asm file and it will call main .
thanx



well an all together conceptual question:
suppose there is an array = xyz[10]

now , xyz and &xyz[0] will represent the same thing : address of first element of array

what does " &xyz " mean
I checked by running a program it comes equal to xyz. hws that possible???
Isn't &xyz means " &(&xyz[0])"????

Re: Bootsector problem(need help)

Posted: Sun Jul 25, 2010 10:03 am
by gerryg400
Isn't &xyz means " &(&xyz[0])"????
They have the same value but NO, xyz means the address of the first element but &xyz means the address of the entire array. It's a different type. If you do this you will get a warning

Code: Select all

	char xyz[10];
	char *a1 = &xyz;
This will be okay

Code: Select all

	char xyz[10];
	char (*a2)[] = &xyz;

Re: Bootsector problem(need help)

Posted: Mon Jul 26, 2010 11:08 am
by achal11
Got it !
thanks :)

Re: Bootsector problem(need help)

Posted: Thu Jul 29, 2010 2:03 am
by DrYap
Hi achal11,

I'm having a similar problem, could you lease post your code (the bootloader, kernel, and linker file) so I can go through and compare.

Thanks in advance.

Re: Bootsector problem(need help)

Posted: Tue Aug 03, 2010 10:55 am
by achal11

Code: Select all


[BITS 16]
[ORG 0x7c00]
    
   jmp 0:start 
   driveno db 0
a  db 'welcome to boot sector', 13,10,0 
b  db 'downloaded sector 2,3 at 1000h', 13,10,0
c db  'helloo a20',13,10,0  
 
 start:
       
        mov ax,0
        mov ds ,ax
        
        mov ss,ax
        mov sp,0x9000
        mov [driveno],dl
        cld
        mov si,a
       call message 
     
       push ax
       call enable_a20
       pop ax 
       mov ax ,0
       mov es,ax
       mov bx,0x1000
                         
      
read_kn:
      
      call read_sector
                   
       mov si,a
       call message
                    
       mov si ,b
       call message 
       
        cli   
        mov ax,0
        mov ds , ax
          lgdt [GDT]
     ;;turn on protected mode 
         mov eax,cr0
         or eax,1
         mov cr0,eax

     jmp      0x08: protected_mode
       
enable_a20:
           mov ax,0x2401       ; enable a20 is wrking
           int 0x15 
               ;jc .abc       
                                 
               ;mov si ,c
               ;call message
           
       .abc: ret   
 
[BITS 32]

g db 'protected mode',0

protected_mode:
        mov ax,0x10
        mov ds,ax
        mov ss,ax
        mov es,ax
        mov esp,0x200000  
        mov ah ,7
        mov esi , g            ;;this is not shown on output         
        call PutStr_32
        jmp  0x08:0x1000
        hlt

PutStr_32:     
    mov edi, [PutStr_Ptr]
.nextchar:
    cld
    lodsb
    test al, al         
    jz .end     
    stosw
    jmp .nextchar 
  .end:
    mov [PutStr_Ptr], edi
    ret 


PutStr_Ptr dd 0xb8000


[BITS 16]
read_sector:  
             push ax
             push cx
              push dx
             
                        
                        ;inc ax
            mov cx,2    ; ch= cylinder cl= sector 
           xor dx,dx    ; dh= head= 0
                        
          mov dl,[driveno]  ; dl = drive no   
                      
          mov al,1    ;no of sectors
           mov ah,2
         int 0x13
          pop dx
          pop cx 
          pop ax
          ret  
message:                        ; Dump ds:si to screen.
                lodsb                   ; load byte at ds:si into al
                or al,al                ; test if character is 0 (end)
                jz done
                mov ah,0eh              ; put character
                mov bx,0007             ; attribute
                int 0x10                ; call BIOS
                jmp message
        done:
                ret

GDT:		dw gdt_limit ; null segment, used to store GDT metadata
		dd GDT
		dw 0

	.cseg:	dd 0x0000FFFF, 0x00CF9a00 ; code segment, 32-bit, 0  ;4GB
	.dseg:	dd 0x0000FFFF, 0x00CF9200 ; data segment, 32-bit, 0 ;to 4GB

	gdt_limit equ $-GDT-1


; --------------------------
; boot seal
; --------------------------
[bits 16]
times 512-($-$$)-2	db	0x00
	dw	0xaa55

linker file :

Code: Select all

OUTPUT_FORMAT("binary")
ENTRY(start)
SECTIONS
{
  .text  0x1000 : {
    *(.text)
  }
  .data  : {
    *(.data)
  }
  .bss  :  { 					
    *(.bss)
  }
}