Page 1 of 1

How to print a message in PMode

Posted: Mon Aug 26, 2002 11:30 am
by beyondsociety
I have entered protected mode and want to print a message. How Would I do this in protected mode?

Could I use the same function to print a message in real mode but just change the registers to 32-bit?

ex:

print:

lodsb
or al,al
jz done
mov ah,0eh
mov bx,7
int 10h
jmp print

done:

ret

Re:How to print a message in PMode

Posted: Mon Aug 26, 2002 11:33 am
by frank
use 0B800h (vidememory, see osd: text for more info)

Re:How to print a message in PMode

Posted: Mon Aug 26, 2002 11:38 am
by beyondsociety
You mean like this :

mov ax, 0B800h
mov gs, ax
mov byte [gs:0], '1'

I use this for debuging pmode to see if it worked.
Could I just use this and just change the '1' to my message?

Re:How to print a message in PMode

Posted: Mon Aug 26, 2002 11:51 am
by beyondsociety
Could I just switch to real mode every time I wanted to print a message or would it be easier to print a message in protected mode?

Re:How to print a message in PMode

Posted: Mon Aug 26, 2002 12:03 pm
by frank
Could I just switch to real mode every time I wanted to print a message or would it be easier to print a message in protected mode?
don't! :)
It will be just as hard as doing it in pmode...
You mean like this :

mov ax, 0B800h
mov gs, ax
mov byte [gs:0], '1'

I use this for debuging pmode to see if it worked.
Could I just use this and just change the '1' to my message?
use ds.
should be something like this:
(long time ago that I used ds for printing a message,
search for some info about ds...)

Code: Select all

printmsg:
 mov ax,0B800h 
 mov gs,ax
 mov di,message
 mov cl,byte[ds:di]
 mov byte[gs:si],cl
  inc di
  inc si
 cmp cl,0
 jne printmsg

message db 'frank test 1,2,3'

Best,
Frank

Re:How to print a message in PMode

Posted: Mon Aug 26, 2002 3:48 pm
by Tim

Code: Select all

mov  ax, 0B800h
mov  gs, ax
mov  byte [gs:0], '1'
This won't work in protected mode (it will work in real mode though). Remember that GS (and the other segment registers) contain selectors in protected mode, not segments. B800 isn't a valid selector.

What you need to do is put a flat selector in GS (that is, one whose base address is zero) and write to 0B8000h.

Code: Select all

mov ax, 10h     ; check your GDT for the number to use
mov gs, ax
mov [gs:0B8000h], '1'

Re:How to print a message in PMode

Posted: Mon Aug 26, 2002 5:24 pm
by beyondsociety
This is wear my logic is coming from but thanks for showing me what the selector for gs is.

-----------------------------------------------------------------------
I will assume that your early pmode code does not use GS, and that your display is in text mode and that your display buffer is at B8000. Put the following code well before you switch to pmode:

mov ax, 0B800h
mov gs, ax
mov byte [gs:0], '1'

Now take lines like these:

mov byte [gs:2], '2'
mov byte [gs:4], '3'
mov byte [gs:6], '4'
etc.

and distribute them through the following code. DO NOT WORRY about the fact that GS has a selector that is incompatible with pmode. DO NOT load a pmode compatible selector into GS (until you are sure your GDT etc. work well enough that you probably don't need this debugging aid anymore anyway).

Re:How to print a message in PMode

Posted: Mon Aug 26, 2002 5:43 pm
by Tom
No, you can't use the int instruction in PMode. Your having almost the same prob as me - using int's in PMode. I'm still looking for ways. One way i've herd of is V86 mode. i'm still reading this: http://osdev.berlios.de/v86.html

Re:How to print a message in PMode

Posted: Mon Aug 26, 2002 7:04 pm
by beyondsociety
Thanks for the link. Your site is awsome! It explains everything about how to use v86 mode and also some other key points that I need to work on before I use v86 mode. Thanks for your help!

Re:How to print a message in PMode

Posted: Tue Aug 27, 2002 1:18 am
by Pype.Clicker
beyondsociety wrote: This is wear my logic is coming from but thanks for showing me what the selector for gs is.

-----------------------------------------------------------------------
I will assume that your early pmode code does not use GS, and that your display is in text mode and that your display buffer is at B8000. Put the following code well before you switch to pmode:

mov ax, 0B800h
mov gs, ax
mov byte [gs:0], '1'

Now take lines like these:

mov byte [gs:2], '2'
mov byte [gs:4], '3'
mov byte [gs:6], '4'
etc.

and distribute them through the following code. DO NOT WORRY about the fact that GS has a selector that is incompatible with pmode. DO NOT load a pmode compatible selector into GS (until you are sure your GDT etc. work well enough that you probably don't need this debugging aid anymore anyway).
will this really work ? i wonder ...it seems like an auwful hack to me ...

Re:How to print a message in PMode

Posted: Tue Aug 27, 2002 10:39 am
by beyondsociety
Yes it works! I have used it to see if my pmode code works and it does, even in pmode I don't know why this is so? considering what tom pointed out. I got it from a website on pmode.

Re:How to print a message in PMode

Posted: Tue Aug 27, 2002 10:47 am
by crazybuddha
Maybe I'm missing something, but this seems unnecessary to me. If your pmode "works", then you can reference the video address directly. Why all the shenanigans??

Re:How to print a message in PMode

Posted: Tue Aug 27, 2002 11:07 am
by beyondsociety
I'm sorry to ask, but how would I do that?

Re:How to print a message in PMode

Posted: Tue Aug 27, 2002 11:41 am
by crazybuddha
In a "memory-mapped display", the memory that is on the video adapter is included in the address space of the CPU. In the case of VGA, there are 128k bytes of memory mapped to 0xA0000 - 0xBFFFF. Depending on which "mode" the adapter has been set to, different portions of this memory are accessible in different ways.

For mode 3, the 80x25 text mode, the sequence of bytes starting at 0xB0000 tell the video controller which characters to display and in what colors. Each character is specified by a pair of bytes. The first byte is the attribute. Depending on how the bits are set, you get different foreground/background color combinations. The next byte in memory is the character to display, and this is simply the ASCII value in hex.

The following example prints a blue smiley face in the top left corner of the screen.

mov edi, 0xb8000
mov word [edi], 0x0901   

Strictly speaking, you can use the immediate value(instead of going through the register), but it gives me the willies to look at two constants side by side. .