How to print a message in PMode

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
beyondsociety

How to print a message in PMode

Post 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
frank

Re:How to print a message in PMode

Post by frank »

use 0B800h (vidememory, see osd: text for more info)
beyondsociety

Re:How to print a message in PMode

Post 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?
beyondsociety

Re:How to print a message in PMode

Post 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?
frank

Re:How to print a message in PMode

Post 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
Tim

Re:How to print a message in PMode

Post 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'
beyondsociety

Re:How to print a message in PMode

Post 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).
Tom

Re:How to print a message in PMode

Post 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
beyondsociety

Re:How to print a message in PMode

Post 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!
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:How to print a message in PMode

Post 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 ...
beyondsociety

Re:How to print a message in PMode

Post 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.
crazybuddha

Re:How to print a message in PMode

Post 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??
beyondsociety

Re:How to print a message in PMode

Post by beyondsociety »

I'm sorry to ask, but how would I do that?
crazybuddha

Re:How to print a message in PMode

Post 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. .
Post Reply