
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

Code: Select all
OUTPUT_FORMAT("binary")
ENTRY(main)
SECTIONS
{
.text 0x1000 : {
*(.text)
}
.data : {
*(.data)
}
.bss : {
*(.bss)
}
}
Code: Select all
gcc -c main.c -o main.o
ld -T link.ld main.o -o main
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 warningIsn't &xyz means " &(&xyz[0])"????
Code: Select all
char xyz[10];
char *a1 = &xyz;
Code: Select all
char xyz[10];
char (*a2)[] = &xyz;
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
Code: Select all
OUTPUT_FORMAT("binary")
ENTRY(start)
SECTIONS
{
.text 0x1000 : {
*(.text)
}
.data : {
*(.data)
}
.bss : {
*(.bss)
}
}