Page 1 of 1

a little problem ?

Posted: Sun Aug 12, 2001 11:00 pm
by Thomas Sendelbach
This programm should switch to protected mode an lode
the kernel which was copyed with int 13h to 0x1000:0 in realmode
but the bootstrap only shows the messages and reboot
code:
______________________________________-
[BITS 16]
[org 0x0]

jmp start
nop
;******************************RESET UND LOAD**************************
reset:
push ds
mov ax, 0
mov dl, [bootdrv]
int 13h
pop ds
jc reset

load:
mov ax, 0x1000
mov es, ax
mov bx, 0
mov ah, 0
mov al, 10 ;sektoren
mov cx, 2
mov dx, 0
int 13h
jc load
retn
;*********************************MESSAGE******************************
message:
lodsb
or al,al
jz done
mov ah,0eh
mov bx,0007
int 0x10
jmp message
done:
ret

;*********************************DATEN**********************************
bootdrv db 0

loadmsg db 'Loading kernel',13,10,0
jumpmsg db 'Jumping to kernel',13,10,0
pmodemsg db 'Entering PMode',13,10,0

gdt:
length dw gdtlength
base dd gdt_table
;***************************************************************************
start:
mov ax, 0x7c0
mov ds, ax
cli
mov ax, 0x9000
mov ss, ax
mov sp, 0xffff
sti

mov [bootdrv], dl
.386
mov si, loadmsg
call message
call load


lgdt [gdt]
mov si, pmodemsg
call message
mov si, jumpmsg
call message
cli
mov eax, cr0
or eax, 1
mov cr0, eax



db 0eah
dw 1000h
dw 14h
;jmp zu desc:offset 0x20:0x1000






;**********************************************************************;
gdt_table:

null_desc:
dw 0
dw 0
db 0
db 00000000b
db 00000000b
db 0

huge_desc_data:
dw 0xFFFF
dw 0000h
db 07h
db 10010010b
db 11001111b
db 00h

huge_desc_code:
dw 0xFFFF
dw 0000h
db 00h
db 10011010b
db 11000000b
db 00h
;**********************************************************************;

gdtlength equ $ -gdt_table -1

times 512-($-$$)-2 db 0
dw 0AA55h

RE:a little problem ?

Posted: Sun Aug 12, 2001 11:00 pm
by Philippo
Hi

I didn't check your code very intensivly, but I think it could be the following error:
When you load the kernel, you are still in real mode. So you load it into memory to 0x1000:0.
Cause it's a realmode-address, this is the phyical memory address of 0x10000 (segment*16+offset)
Then you switch to protected mode and try to jump to the kernel code. So this jump should be
seg:0x10000

don't have the time to try it out, so I hope, i'm not talking nonsense here ;-)

hope this helps

Philippo
[email protected]


>On 2001-08-13 10:06:34, Thomas Sendelbach wrote:
>This programm should switch to protected mode an lode
>the kernel which was copyed with int 13h to 0x1000:0 in realmode
>but the bootstrap only shows the messages and reboot
>code:
>______________________________________-
>[BITS 16]
>[org 0x0]
>
>jmp start
>nop
>;******************************RESET UND LOAD**************************
>reset:
>push ds
>mov ax, 0
>mov dl, [bootdrv]
>int 13h
>pop ds
>jc reset
>
>load:
>mov ax, 0x1000
>mov es, ax
>mov bx, 0
>mov ah, 0
>mov al, 10 ;sektoren
>mov cx, 2
>mov dx, 0
>int 13h
>jc load
>retn
>;*********************************MESSAGE******************************
>message:
> lodsb
> or al,al
> jz done
> mov ah,0eh
> mov bx,0007
> int 0x10
> jmp message
>done:
>ret
>
>;*********************************DATEN**********************************
>bootdrv db 0
>
>loadmsg db 'Loading kernel',13,10,0
>jumpmsg db 'Jumping to kernel',13,10,0
>pmodemsg db 'Entering PMode',13,10,0
>
>gdt:
>length dw gdtlength
>base dd gdt_table
>;***************************************************************************
>start:
>mov ax, 0x7c0
>mov ds, ax
>cli
>mov ax, 0x9000
>mov ss, ax
>mov sp, 0xffff
>sti
>
>mov [bootdrv], dl
>.386
>mov si, loadmsg
>call message
>call load
>
>
>lgdt [gdt]
>mov si, pmodemsg
>call message
>mov si, jumpmsg
>call message
>cli
>mov eax, cr0
>or eax, 1
>mov cr0, eax
>
>
>
>db 0eah
>dw 1000h
>dw 14h
>;jmp zu desc:offset 0x20:0x1000
>
>
>
>
>
>
>;**********************************************************************;
>gdt_table:
>
>null_desc:
>dw 0
>dw 0
>db 0
>db 00000000b
>db 00000000b
>db 0
>
>huge_desc_data:
>dw 0xFFFF
>dw 0000h
>db 07h
>db 10010010b
>db 11001111b
>db 00h
>
>huge_desc_code:
>dw 0xFFFF
>dw 0000h
>db 00h
>db 10011010b
>db 11000000b
>db 00h
>;**********************************************************************;
>
>gdtlength equ $ -gdt_table -1
>
>times 512-($-$$)-2 db 0
>dw 0AA55h

RE:a little problem ?

Posted: Mon Aug 13, 2001 11:00 pm
by Guest
Hi I changed the programm how you told me..now
I wrote a little sample program:

[bits 32]
[org 0x10:0x10000]
start:
cli
hlt

I tested it with my bootloader it didn´t work where
is the bug! pleas H E L P!

RE:a little problem ?

Posted: Mon Aug 13, 2001 11:00 pm
by Philippo
Hi

I changed your bootsector code, now it's working on my computer.
You can find a comment everywhere I had to change something.

new boot code:

[BITS 16]
[org 0x0]

jmp start
nop
;******************************RESET UND LOAD**************************
reset:
push ds
mov ax, 0
mov dl, [bootdrv]
int 13h
pop ds
jc reset

load:
mov ax, 0x1000
mov es, ax
mov bx, 0
mov ah, 2 ;[Philippo] You want to read, so use function #2
mov al, 10 ;sektoren
mov cx, 2
mov dx, 0
int 13h
jc load
retn
;*********************************MESSAGE******************************
message:
lodsb
or al,al
jz done
mov ah,0eh
mov bx,0007
int 0x10
jmp message
done:
ret

;*********************************DATEN**********************************
bootdrv db 0

loadmsg db 'Loading kernel',13,10,0
jumpmsg db 'Jumping to kernel',13,10,0
pmodemsg db 'Entering PMode',13,10,0

gdt:
length dw gdtlength
base dd gdt_table + 0x7C00 ;[philippo] physical address, must add offset 0x7C00
;***************************************************************************
start:
mov ax, 0x7c0
mov ds, ax
cli
mov ax, 0x9000
mov ss, ax
mov sp, 0xffff
sti

mov [bootdrv], dl
.386
mov si, loadmsg
call message
call load

lgdt [ds:gdt] ;[philippo] you must either add 0x7C00 to offset or use 0x7C0 as segment
mov si, pmodemsg
call message
mov si, jumpmsg
call message
cli
mov eax, cr0
or eax, 1
mov cr0, eax
jmp DWORD 0x10:0x10000 ;[philippo]data descriptor is 0x08, code is 0x10


;**********************************************************************;
gdt_table:

null_desc:
dw 0
dw 0
db 0
db 00000000b
db 00000000b
db 0

huge_desc_data:
dw 0xFFFF
dw 0000h
db 00h ;[philippo] I think this should start at address 0
db 10010010b
db 11001111b
db 00h

huge_desc_code:
dw 0xFFFF
dw 0000h
db 00h
db 10011010b
db 11000000b
db 00h
;**********************************************************************;

gdtlength equ $ -gdt_table -1

times 512-($-$$)-2 db 0
dw 0AA55h



the test "kernel" I used:

[bits 32]
mov ax, 0x8
mov es, ax
mov byte [es:0xB8000+0], 'H'
mov byte [es:0xB8000+2], 'e'
mov byte [es:0xB8000+4], 'l'
mov byte [es:0xB8000+6], 'l'
mov byte [es:0xB8000+8], 'o'

endloop:
jmp endloop



hope it works for you too ;-)
bye

Philippo
[email protected]

RE:a little problem ?

Posted: Tue Aug 14, 2001 11:00 pm
by Thomas Sendelbach
thx! it works

RE:a little problem ?

Posted: Tue Aug 14, 2001 11:00 pm
by Guest
i have a question:
this code doesen´t work, how?
i have compiled with djgpp
gcc -ffreestanding -c -o prog.o prog.c
ld -Ttext 0x10000 --oformat binary -o prog.bin prog.o


void main()
{
int offset;
char *video;
__asm__("
movw $0x8, %ax
movw %ax, %es
");
video=(char*)0xb8000;
video[offset]='H';
video[offset+2]='I';
l: goto l;
}

RE:a little problem ?

Posted: Wed Aug 15, 2001 11:00 pm
by j.weeks
>void main()
>{
>int offset;
>char *video;
>__asm__("
>movw $0x8, %ax
>movw %ax, %es
>");
>video=(char*)0xb8000;
>video[offset]='H';
>video[offset+2]='I';
>l: goto l;
>}

Offest is assumed to be zero here... but it's not.

Offset is undefined on startup.
try "int offset = 0;"

j.weeks