default bit 
Author Message
 default bit

hello

    When i set the default bit to zero , does it mean it work just 16bit and
it doesn't work with the 32bit instruction like mov eax,1234h ?

    I made a little program that can get into protected mode and do the
interrupt but when i set the default bit to zero ,even i use use16 or use32
segment for store interrupt handler, it never comes prefer ? For example ,
if i set D bit to zero and i use use32 segment for the interrupt handler and
i have an instruction mov eax,1234h , it will cause a reboot ? And i set D
bit to one and i use use32 segment , it doesn't work because a 66h prefix is
before the instruction iret . Do you have a prefer way to do that?

thank you
here is my code:

.model tiny
main_start      segment
.386p
        .startup
        mov     ax,cs
        shl     eax,4
        mov     os_code_base1,ax   ;os code base
        shr     eax,8
        mov     os_code_base2,ah

        mov     eax,cs
        shl     eax,4
        add     eax,offset dummy
        mov     dword ptr GDT_address,eax   ;GDTR address

        mov     eax,cs
        shl     eax,4
        add     eax,offset interrupt
        mov     dword ptr IDT_address,eax   ;IDTR address

        cli
        lgdt    fword ptr cs:gdt_limit
        lidt    fword ptr cs:idt_limit

 ;get into protected mode
        mov     eax,cr0         ; get CR0 into EAX
        or      al,1            ; set Protected Mode bit
        mov     cr0,eax
        db      0eah
        dw      offset  start32,8
start32:
        int     0
        hlt
;build GDT
        ;null descriptor
        dummy dw 0
        dw 0
        dw 0
        dw 0

        ;308
        dw 0ffffh
        os_code_base1   dw 0000h
        os_code_base2   db 0
        db 9ah
        db 9fh
        db 0

        ;310
        ;GDTR
        gdt_limit       dw 0fh
        gdt_address     dd 0h

        ;316
        ;build IDT
        ;int     0
        interrupt       dw near ptr int0_handler      ;offset
        dw 8h ;selector
        db 0 ;reserved
        db 8eh ;type
        dw 0 ;offset

        ;31e
        ;IDTR
        idt_limit      dw 0fh
        idt_address    dd 0h

        ;324
main_start      ends

int0    segment use32
        org     178h
        int0_handler:
        mov     ax,1234h
        mov     eax,1234h
        iret
int0    ends
end



Thu, 01 Aug 2002 03:00:00 GMT  
 default bit

Quote:
> hello

>     When i set the default bit to zero , does it mean it work just
16bit and
> it doesn't work with the 32bit instruction like mov eax,1234h ?

   No, default bit means that the default operand size is 16 bit and
default addressing is 8086-style, wherever applicable. Prefix 66h
switchs default operand size to the opposite and prefix 67h switches
address size.

Quote:
>     I made a little program that can get into protected mode and do
the
> interrupt but when i set the default bit to zero ,even i use use16 or
use32
> segment for store interrupt handler, it never comes prefer ? For
example ,
> if i set D bit to zero and i use use32 segment for the interrupt
handler and
> i have an instruction mov eax,1234h , it will cause a reboot ? And i
set D
> bit to one and i use use32 segment , it doesn't work because a 66h
prefix is
> before the instruction iret . Do you have a prefer way to do that?

   USE32 directive tells _assembler_ (compiler) that the code must be
assembled with 32-bit defaults, USE16 tells it to assemble with 16 bit
defaults. Setting default bits tells _processor_ that the binary stream
hereafter must be executed using 32-bit defaults (clearing it tells CPU
to work with 16 bit defaults).

   You have to set manually D = 1 for code segments assembled as USE32
and D = 0 for segments assembled as USE16. Doing otherwise won't work.

[code snipped].

-- http://bphantom.hypermart.net --

-- Too many flames with too much to burn
And life's only made of paper --

Sent via Deja.com http://www.deja.com/
Before you buy.



Thu, 01 Aug 2002 03:00:00 GMT  
 default bit
Quote:
>    When i set the default bit to zero , does it mean it work just 16bit
and
>it doesn't work with the 32bit instruction like mov eax,1234h ?

It appears to me that you still doesn't get the idea right.

The 'D' bit is the _actual_ default.
The assembler doesn't know what the default will be, therefor you have to
tell him using the 'use16' and 'use32' directives.

So, if you use a default of 32-bit ('D'-bit = 1), then you have to use
the 'use32' directive to all your (code) segments which are used with
this default.

In any mode, the i386 and your assembler can handle _both_ 16-bit
and 32-bit instructions.
The .8086 and .386 directives will tell the assembler which instruction
set it is allowed to recognise. As the 8086 being a 16-bit CPU, the
.8086 directive will tell the assembler not only to reject all 32-bit
instructions,
but also some 'newer' 16-bit instructions, such as protected mode,
immediate multiply and shift, and the enter/leave instructions.

H



Sat, 03 Aug 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Segment descriptor DEFAULT and BIG bit

2. Default value of array attributes for zero length (bit)string literals

3. Segment descriptor DEFAULT and BIG bit

4. Division 32-Bit/32-Bit with 16-Bit Register

5. dict.get(key, default): conditional default evaluation

6. *default-pathname-defaults* ?

7. 31 bit vs 24 bit - two easy questions

8. Bit-by-bit ASM disk copier

9. 32 bit ST communicating with 16 bit VB

10. How to use SE at any color resolution (256, 16-bit, 32-bit)

11. Can I use 16 bit DLL and 32-bit exe together

12. Changing from 16-bit to 32-bit makes zillion duplicate symbols

 

 
Powered by phpBB® Forum Software