flat assembler
Message board for the users of flat assembler.

Index > OS Construction > All kinds of error when MOVing in 32-bit mode

Author
Thread Post new topic Reply to topic
l4m2



Joined: 15 Jan 2015
Posts: 674
l4m2 15 Jan 2015, 04:13
Code:
macro align value { rb (value-1)-($+value-1) mod value }
    org 100h
    mov ax,cs
    mov ds,ax
    mov es,ax  
    xor eax,eax
    mov ax,cs;cs?????????  
    shl eax,4;?????????
    add [gdtptr+2],eax
;   add eax,disppmmsg
    mov word [gdt+10],ax
    shr eax,16  
    mov byte [gdt+12],al  
    mov byte [gdt+15],ah  
    lgdt [gdtptr]  
    cli
    in  al, 92h
    or  al, 00000010b  
    out 92h, al
    mov ds,[gdt];0
    mov eax, cr0
    or  eax, 1  
    mov cr0, eax  
      
    jmp dword 8:disppmmsg     ;codeselector
    ;??GDT
    align 16
    gdt:  
    dw 0,0,0,0  
      
    dw 0xffff
    dw 0x0000;???/?        10
    dw 0x9A00;???????      12
    dw 0x00C0;             14
      
    dw 0xffff
    dw 0x8000;??/?  
    dw 0x920B;?????0x0B8000
    dw 0x00C0
      
    codeselector equ 0x08
    videoselector equ 0x10
      
    ;GDTR  
    gdtptr:  
    dw 0x0010  
    dw gdt,0  
    use32
    disppmmsg:
;    xor ebx,ebx
;    mov ax,es
;    mov bx,$b810
;    sub bx,ax
;    shl ebx,4
    ;mov ax,16
    ;mov ds,ax
    mov [$b8000],byte 'A'
    jmp $
    mov ax,videoselector  
    mov gs,ax  
    mov edi,(80*0+0)*2;?????????,????????  
    mov ah,0x0c;??????  
    mov al,'S';??????  
    mov [gs:edi],ax  
    mov edi,(80*0+1)*2  
    mov ah,0x0c  
    mov al,'u'  
    mov [gs:edi],ax  
    mov edi,(80*0+2)*2  
    mov ah,0x0c  
    mov al,'n'  
    mov [gs:edi],ax
    jmp $
    

If I use MOV DS,xxx before MOV [$B8000],x it crashes.Why?[/code]
Post 15 Jan 2015, 04:13
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4354
Location: Now
edfed 15 Jan 2015, 08:56
because you modify the base adress for the B8000h offset, then maybe access invalid location.
Post 15 Jan 2015, 08:56
View user's profile Send private message Visit poster's website Reply with quote
l4m2



Joined: 15 Jan 2015
Posts: 674
l4m2 15 Jan 2015, 12:24
l4m2 wrote:
Code:
macro align value { rb (value-1)-($+value-1) mod value }
    org 100h
    mov ax,cs
    mov ds,ax
    mov es,ax  
    xor eax,eax
    mov ax,cs;cs?????????  
    shl eax,4;?????????
    add [gdtptr+2],eax
;   add eax,disppmmsg
    mov word [gdt+10],ax
    shr eax,16  
    mov byte [gdt+12],al  
    mov byte [gdt+15],ah  
    lgdt [gdtptr]  
    cli
    in  al, 92h
    or  al, 00000010b  
    out 92h, al
    mov ds,[gdt];0
    mov eax, cr0
    or  eax, 1  
    mov cr0, eax  
      
    jmp dword 8:disppmmsg     ;codeselector
    ;??GDT
    align 16
    gdt:  
    dw 0,0,0,0  
      
    dw 0xffff
    dw 0x0000;???/?        10
    dw 0x9A00;???????      12
    dw 0x00C0;             14
      
    dw 0xffff
    dw 0x8000;??/?  
    dw 0x920B;?????0x0B8000
    dw 0x00C0
      
    codeselector equ 0x08
    videoselector equ 0x10
      
    ;GDTR  
    gdtptr:  
    dw 0x0010  
    dw gdt,0  
    use32
    disppmmsg:
;    xor ebx,ebx
;    mov ax,es
;    mov bx,$b810
;    sub bx,ax
;    shl ebx,4
    ;mov ax,16
    ;mov ds,ax
    mov [$b8000],byte 'A'
    jmp $
    mov ax,videoselector  
    mov gs,ax  
    mov edi,(80*0+0)*2;?????????,????????  
    mov ah,0x0c;??????  
    mov al,'S';??????  
    mov [gs:edi],ax  
    mov edi,(80*0+1)*2  
    mov ah,0x0c  
    mov al,'u'  
    mov [gs:edi],ax  
    mov edi,(80*0+2)*2  
    mov ah,0x0c  
    mov al,'n'  
    mov [gs:edi],ax
    jmp $
    

If I use MOV DS,xxx before MOV [$B8000],x it crashes.Why?[/code]

If i delete the first "jmp $"what should be done next
Post 15 Jan 2015, 12:24
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4354
Location: Now
edfed 15 Jan 2015, 16:09
i suggest you to try this thread and adapt to your code Smile
http://board.flatassembler.net/topic.php?t=11512
Post 15 Jan 2015, 16:09
View user's profile Send private message Visit poster's website Reply with quote
l4m2



Joined: 15 Jan 2015
Posts: 674
l4m2 16 Jan 2015, 05:26
l4m2 wrote:

If i delete the first "jmp $"what should be done next

Thanks.I'll see it.
Post 16 Jan 2015, 05:26
View user's profile Send private message Reply with quote
l4m2



Joined: 15 Jan 2015
Posts: 674
l4m2 16 Jan 2015, 05:40
l4m2 wrote:
l4m2 wrote:
Code:
macro align value { rb (value-1)-($+value-1) mod value }
    org 100h
    mov ax,cs
    mov ds,ax
    mov es,ax  
    xor eax,eax
    mov ax,cs;cs?????????  
    shl eax,4;?????????
    add [gdtptr+2],eax
;   add eax,disppmmsg
    mov word [gdt+10],ax
    shr eax,16  
    mov byte [gdt+12],al  
    mov byte [gdt+15],ah  
    lgdt [gdtptr]  
    cli
    in  al, 92h
    or  al, 00000010b  
    out 92h, al
    mov ds,[gdt];0
    mov eax, cr0
    or  eax, 1  
    mov cr0, eax  
      
    jmp dword 8:disppmmsg     ;codeselector
    ;??GDT
    align 16
    gdt:  
    dw 0,0,0,0  
      
    dw 0xffff
    dw 0x0000;???/?        10
    dw 0x9A00;???????      12
    dw 0x00C0;             14
      
    dw 0xffff
    dw 0x8000;??/?  
    dw 0x920B;?????0x0B8000
    dw 0x00C0
      
    codeselector equ 0x08
    videoselector equ 0x10
      
    ;GDTR  
    gdtptr:  
    dw 0x0010  
    dw gdt,0  
    use32
    disppmmsg:
;    xor ebx,ebx
;    mov ax,es
;    mov bx,$b810
;    sub bx,ax
;    shl ebx,4
    ;mov ax,16
    ;mov ds,ax
    mov [$b8000],byte 'A'
    jmp $
    mov ax,videoselector  
    mov gs,ax  
    mov edi,(80*0+0)*2;?????????,????????  
    mov ah,0x0c;??????  
    mov al,'S';??????  
    mov [gs:edi],ax  
    mov edi,(80*0+1)*2  
    mov ah,0x0c  
    mov al,'u'  
    mov [gs:edi],ax  
    mov edi,(80*0+2)*2  
    mov ah,0x0c  
    mov al,'n'  
    mov [gs:edi],ax
    jmp $
    

If I use MOV DS,xxx before MOV [$B8000],x it crashes.Why?[/code]

If i delete the first "jmp $"what should be done next

Yes it did well when booting but unable to run in dos mode.Maybe cs is wrong.I'll test it.
Post 16 Jan 2015, 05:40
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.