Page 1 of 1
Can't modify segment register in PM.
Posted: Sun Jul 15, 2001 11:00 pm
by mj
Hi,
I have tried the below code, but after going into PM, if I mov one valid selector to any segment, the computer will reboot(So I could not use far jump).
(I use MASM 6.11)
Any suggestion is appreciated.
.386p
code segment use16
boot:
cli
mov ax, 7c0h
mov ds, ax
mov es, ax
mov ss,ax
mov sp, 100h
mov al,0D1h
out 64h,al
mov al,0DFh
out 60h,al
mov al,2
out 92h,al
mov al,80h
out 70h,al
in al,71h
mov al,0FFh
out 21h,al
out 0A1h,al
lgdt fword ptr gdtr
lidt fword ptr idtr
mov eax, cr0
or al, 1
mov cr0,eax
jmp short $+2
mov ax,08
; jmp $ ; uncomment this, then can stop
mov cs, ax ;this line cause the computer reboot
jmp $
;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
align 8
idtr:
dw 0
dd 0
align 8
gdtr:
dw 17h
dd 7c00h+gdt-boot
align 8
gdt:
dd 0,0
dw 0FFFFh,0
db 0,10011010b,11001111b,0
dw 0FFFFh,0
db 0,10010011b,11001111b,0
org 510
dw 0AA55h
code ends
end boot
RE:Can't modify segment register in PM.
Posted: Sun Jul 15, 2001 11:00 pm
by J. Weeks
> jmp short $+2
> mov ax,08
>
>; jmp $ ; uncomment this, then can stop
> mov cs, ax ;this line cause the computer reboot
Yep, sure would
I'm surprised that even assembled...
didn't think you could set the code segment
explicitly.
Well, assuming that instruction works and doesn't
produce an invalid opcode... it doesn't change
the instruction pointer (ip), and no doubt
jumps to unknown code.
That's a guess, anyway... I didn't decode
your descriptors to see where they're pointing, but
that's probably what's wrong.
I'd use a jmp, with both segment and offset:
jmp 0x10:offset
offset:
; 32 bit code starts here
Either that, or:
db 0x66
db 0xea
dd offset
dw 0x10
offset:
; 32 bit code starts here
; the above both assume your code segment is
; 0x10... sorry, force of habit... that's what
; my code segment is
j.weeks
RE:Can't modify segment register in PM.
Posted: Sun Jul 15, 2001 11:00 pm
by Chase
>On 2001-07-16 07:02:16, mj wrote:
>Hi,
>
>I have tried the below code, but after going into PM, if I mov one valid selector to any segment, the computer will reboot(So I could not use far jump).
>(I use MASM 6.11)
>Any suggestion is appreciated.
First off it's very hard to fit good pmode initialization code in a boot sector.
If your a20 code is working, you'll still find some machines that
it won't work on. But I've done it all in a boot sector before too.
I've never used MASM so I can suggest some things that you might have to
look up.
> mov eax, cr0
> or al, 1
> mov cr0,eax
Do a cli and then to start pmode you must do a long jmp to clear the prefetch.
In your code segment descriptor you specify that your code segment is 32bits.
Assumming the use16 meant 16bit code you need a use32 here.
I'm also assuming that MASM lets you use mixed size code in a single source.
> dw 0FFFFh,0
> db 0,10011010b,11001111b,0
When doing everthing all in a single boot sector I always
set my start of the segments to match the real mode segment starts. (0x7c00)
That way you doen't run into problems when jumping to labels.
Hope this helps.
-Chase
RE:Can't modify segment register in PM.
Posted: Wed Aug 29, 2001 11:00 pm
by Guest
>On 2001-07-16 07:02:16, mj wrote:
>Hi,
>
>I have tried the below code, but after going into PM, if I mov one valid selector to any segment, the computer will reboot(So I could not use far jump).
>(I use MASM 6.11)
>Any suggestion is appreciated.
>
>.386p
>
>code segment use16
>boot:
> cli
> mov ax, 7c0h
> mov ds, ax
> mov es, ax
> mov ss,ax
> mov sp, 100h
>
> mov al,0D1h
> out 64h,al
> mov al,0DFh
> out 60h,al
> mov al,2
> out 92h,al
>
> mov al,80h
> out 70h,al
> in al,71h
>
> mov al,0FFh
> out 21h,al
> out 0A1h,al
>
> lgdt fword ptr gdtr
> lidt fword ptr idtr
>
> mov eax, cr0
> or al, 1
> mov cr0,eax
>
> jmp short $+2
> mov ax,08
>
>; jmp $ ; uncomment this, then can stop
> mov cs, ax ;this line cause the computer reboot
>
> jmp $
>
>;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
>align 8
>idtr:
> dw 0
> dd 0
>
>align 8
>gdtr:
> dw 17h
> dd 7c00h+gdt-boot
>
>align 8
>gdt:
> dd 0,0
>
> dw 0FFFFh,0
> db 0,10011010b,11001111b,0
>
> dw 0FFFFh,0
> db 0,10010011b,11001111b,0
>
>org 510
>dw 0AA55h
>
>code ends
> end boot
RE:Can't modify segment register in PM.
Posted: Wed Aug 29, 2001 11:00 pm
by Vitaly CHIPOUNOV
>On 2001-07-16 07:02:16, mj wrote:
>Hi,
>
>I have tried the below code, but after going into PM, if I mov one valid selector to any segment, the computer will reboot(So I could not use far jump).
>(I use MASM 6.11)
>Any suggestion is appreciated.
>
>.386p
>
>code segment use16
>boot:
> cli
> mov ax, 7c0h
> mov ds, ax
> mov es, ax
> mov ss,ax
> mov sp, 100h ;use 0xFFFF instead, you'll
;have more stack space (it's
;what I do
>
> mov al,0D1h
> out 64h,al
> mov al,0DFh
> out 60h,al
> mov al,2
> out 92h,al
>
> mov al,80h
> out 70h,al
> in al,71h
>
> mov al,0FFh
> out 21h,al
> out 0A1h,al
>
> lgdt fword ptr gdtr
> lidt fword ptr idtr
>
> mov eax, cr0
> or al, 1
> mov cr0,eax
>
> jmp short $+2
> mov ax,08
>
>; jmp $ ; uncomment this, then can stop
> mov cs, ax ;this line cause the computer reboot
;Didn't you learn that you can't modify directly
;cs nor eip ? Use a far jump with selector:offset
;instead. It will have the same result.
;call, jmp... are the only instructions allowed
;to modify code regs...
;I hope it will help you
>
> jmp $
>
>;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
>align 8
>idtr:
> dw 0
> dd 0
>
>align 8
>gdtr:
> dw 17h
> dd 7c00h+gdt-boot
>
>align 8
>gdt:
> dd 0,0
>
> dw 0FFFFh,0
> db 0,10011010b,11001111b,0
>
> dw 0FFFFh,0
> db 0,10010011b,11001111b,0
>
>org 510
>dw 0AA55h
>
>code ends
> end boot