flat assembler
Message board for the users of flat assembler.

Index > OS Construction > Can't display text on screen !

Author
Thread Post new topic Reply to topic
milind



Joined: 15 Feb 2004
Posts: 33
milind 14 Mar 2004, 15:53
Hello I have tried the following code(this is loaded by my boot sector to location 8C00 and executed):


Code:
        use32
        org     8C00h

        mov ax, 0B800h
        mov gs, ax

        mov byte [gs:0h], 'M'
        mov byte [gs:1h], 7h           
        jmp $
    



But it does not display the character 'M' The bootloader works fine till the end and it is reaching the code here because if I add a display of a string using an int 10h in the code above (after the 'M' displaying statements) the string is displayed, so I know the code is getting executed.
I then checked the memeory map using the int 15h ax = e820h routine and here is what I get:

Quote:


INDEX BASE SIZE TYPE
0 00000000:00000000 00000000:0009FC00 1
1 00000000:0009FC00 00000000:00000400 2
2 00000000:000F0000 00000000:00010000 2
3 00000000:00100000 00000000:0FEEC000 1
4 00000000:0FFEC000 00000000:00003000 3
5 00000000:0FFEF000 00000000:00010000 2
6 00000000:0FFFF000 00000000:00001000 4
7 00000000:FEC00000 00000000:00001000 2
8 00000000:FEE00000 00000000:00001000 2
9 00000000:FFFF0000 00000000:00010000 2


This shows that there is no memory present at address 000B8000h, so how can I display text? Please help.
Post 14 Mar 2004, 15:53
View user's profile Send private message Visit poster's website Yahoo Messenger Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 14 Mar 2004, 16:18
At first, you have to use "use16" for bootloader, because in the time of boot, processor is in real mode.

Regards
Post 14 Mar 2004, 16:18
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
milind



Joined: 15 Feb 2004
Posts: 33
milind 14 Mar 2004, 16:33
Yes I know that and my bootloader uses 'use16' this is the program that is loaded by the bootloader so its using use32. My main problem is how do I display a character on the screen from this program if I load it from the 1MB mark since from there I don't think the BIOS interrupts (int 10h) will work to display on screen.
Post 14 Mar 2004, 16:33
View user's profile Send private message Visit poster's website Yahoo Messenger Reply with quote
asmdemon



Joined: 18 Jan 2004
Posts: 97
Location: Virginia Beach, VA
asmdemon 14 Mar 2004, 16:59
did you load into protected mode? cuz only protected mode can execute 32bit instructions

_________________
It is better to be on the right side of the devil than in his path.
Post 14 Mar 2004, 16:59
View user's profile Send private message Visit poster's website Reply with quote
milind



Joined: 15 Feb 2004
Posts: 33
milind 14 Mar 2004, 17:37
I am not in protected mode, but I am not executing any instruction that is exclusive to protected mode yet. Only the addresses are 32 bit, so I think this should not be a problem.
Post 14 Mar 2004, 17:37
View user's profile Send private message Visit poster's website Yahoo Messenger Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 14 Mar 2004, 17:50
milind wrote:
I am not in protected mode, but I am not executing any instruction that is exclusive to protected mode yet. Only the addresses are 32 bit, so I think this should not be a problem.


If you are not in protected mode, you can't use 32bit addresses. (Even if you want it, the CPU doesn't know what you want). OTOH, if you ARE in protected mode, you can't use "mov ax, $b800 mov es, $b800", there are another segments.
I think you should read more about real and protected mode. I can't explain it in one post only.

Regards.
Post 14 Mar 2004, 17:50
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
milind



Joined: 15 Feb 2004
Posts: 33
milind 14 Mar 2004, 19:50
JohnFound wrote:

If you are not in protected mode, you can't use 32bit addresses. (Even if you want it, the CPU doesn't know what you want). OTOH, if you ARE in protected mode, you can't use "mov ax, $b800 mov es, $b800", there are another segments.


Ok 1st of all 32 bit offsets and addresses can be used in Protected mode as the Intel manual says:

Quote:

The 32-bit address prefix can be used in real-address mode programs, allowing 32-bit
offsets.


The only limitation is that if the 32 bit offset is not in the range 0 to FFFFh then it generates a pseudo-protection faults (interrupt 12 or 13). But as u can see in the code above the offset never goes above FFFF. Also B8000h is an address below 1MB and can be generated in Real mode.
So if I replace use32 by use16 will the code work??
Post 14 Mar 2004, 19:50
View user's profile Send private message Visit poster's website Yahoo Messenger Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 14 Mar 2004, 20:01
milind wrote:
So if I replace use32 by use16 will the code work??


Smile Simply try it. Smile No joking, this is one of the most powerfull assembler techniques.

Regards.
Post 14 Mar 2004, 20:01
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
hawk



Joined: 16 Mar 2004
Posts: 3
hawk 17 Mar 2004, 07:35
Well, since I begun the same way (trying to write on the screen w/o help from BIOS) I'll post here the code for both 16bit and 32bit versions of a so called "print" routines.
Please note that the routines can probably be improved, however since they worked I left them in the original state. Hope those would be of some help.

32 bit procedure expects pointer to null terminated string on stack, gets/sets cursor position from video card registers and doesn't take care of the processor registers.

Code:
proc print_tty,lpsz
        xor edx,edx
        xor ebx,ebx
; ---- CURSOR PROBLEMS ----
; ---- GET VGA (/CGA/EGA) CURSOR POSITION
        mov dx,3d4h
        mov al,0eh
        out dx,al
        mov dx,3d5h
        in      al,dx
        mov bl,al
        mov dx,3d4h
        mov al,0fh
        out dx,al
        mov dx,3d5h
        in      al,dx
        shl bx,8
        mov bl,al

       shl ebx,1
   mov edi,0b8000h
     add edi,ebx
 mov esi,[lpsz]

  @@:
             lodsb
               cmp al,0
            jz @f
               cmp al,10
           jnz not_lf
                  add edi,160
                 jmp @b
              not_lf:
         cmp al,13
           jnz not_cr
                  mov edx,0
                   mov eax,edi
                 sub eax,0b8000h
                     xor edx,edx
                 mov ebx,160
                 div ebx
                     sub edi,edx
                 jmp @b
              not_cr:
         stosb
               inc edi
             jmp @b
      @@:
        mov ebx,edi
        sub ebx,0b8000h
        shr ebx,1

  
        mov dx,3d4h
        mov al,0fh
        out dx,al
        mov dx,3d5h
        mov al,bl
        out dx,al
        mov dx,3d4h
        mov al,0eh
        out dx,al
        mov dx,3d5h
        shr bx,8
        mov al,bl
        out dx,al

return
    


16bit version is only for the boot loader, thus more simple, w/o hardware cursor positioning - uses a variable to store cursor position; pointer to null terminated string in si

Code:
cursor           dw      0

print16_msg:

mov ax,0b800h
mov es,ax
mov di,[cursor]
shl di,1
@@:
       mov al,[si]
 cmp al,0
    jz @f
       cmp al,10
   jnz @@not_lf
                add di,160
          inc si
              jmp @b
      @@not_lf:
       cmp al,13
   jnz @@not_cr
                mov dx,0
            mov ax,di
           mov bx,160
          div bx
              mov dx,0
            mul bx
              mov di,ax
           inc si
              jmp @b
      @@not_cr:
       stosb
       inc di
      inc si
      jmp @b
@@:
shr di,1
mov [cursor],di
ret
    


One more thing: Video memory starts at segment B800h for CGA/EGA/VGA compatible cards. Very OLD video cards (like Hercules Mono and MDA) start at segment B000h. However I don't think that would be your problem. I tested my loader and routines on various configurations and all seem to work.

And yet another: I don't handle scrolling, so if you hit the bottom of the screen it is YOUR problem Twisted Evil
But I will, and if anyone is interrested I'll post the updated routine here.

_________________
Always begining something
Post 17 Mar 2004, 07:35
View user's profile Send private message Reply with quote
Cas



Joined: 26 Feb 2004
Posts: 82
Location: Argentina
Cas 05 Apr 2004, 05:41
Look, if you write this:

use16
mov ax,0b800h
mov ds,ax

it is coded as normal. Now, if you use 32 bit instructions, but then run the code in 16 bit mode (that is, in real mode in this case), these instructions:

use32
mov ax,0b800h
mov ds,ax

will be interpreted as if you had written this:

use16
mov eax,08e66b800h

That is, a completely different instruction. I would expect the computer to hang almost immediately after that. Confused

_________________
«Earth is my country; science is my religion» - Christian Huygens
Post 05 Apr 2004, 05:41
View user's profile Send private message Yahoo Messenger MSN Messenger Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 05 Apr 2004, 18:45
why dont you use 32bit real mode (used by FASM DOS version for example?)
Post 05 Apr 2004, 18:45
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number 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.