How to print a message in protected mode
How to print a message in protected mode
I originaly posted this same topic a long time ago, but anyways I back. I have entered protected mode and am finally ready to print a message in protected mode.
I don't know where to start. Could I use the original print code but change it to 32 bit code?
IF anybody could help me out I would appreciate it, either some links or some examples in assembly would really help.
I don't know where to start. Could I use the original print code but change it to 32 bit code?
IF anybody could help me out I would appreciate it, either some links or some examples in assembly would really help.
Re:How to print a message in protected mode
You have several options.
1) Switch from pmode to rmode and use your old *16 BIT* routine that calls BIOS.
2) Implement your own console driver, wrting to 0xB800
3) use V86 or unreal mode and call BIOS.
either way, try to stay out of mixing 16/32 bit codes unless you know what you're doing.
some C example code (i think i took it from some other post here):
#define MSG "Hello, world"
int main(void)
{
char *str = MSG, *ch;
unsigned short *vidmem = (unsigned short*) 0xb8000;
unsigned i; for (ch = str, i = 0; *ch; ch++, i++)
vidmem = (unsigned char) *ch | 0x0700;
for (;;)
;
}
1) Switch from pmode to rmode and use your old *16 BIT* routine that calls BIOS.
2) Implement your own console driver, wrting to 0xB800
3) use V86 or unreal mode and call BIOS.
either way, try to stay out of mixing 16/32 bit codes unless you know what you're doing.
some C example code (i think i took it from some other post here):
#define MSG "Hello, world"
int main(void)
{
char *str = MSG, *ch;
unsigned short *vidmem = (unsigned short*) 0xb8000;
unsigned i; for (ch = str, i = 0; *ch; ch++, i++)
vidmem = (unsigned char) *ch | 0x0700;
for (;;)
;
}
Re:How to print a message in protected mode
Examples should be in assembly and not c, c+ or c++.
Could you re-write your high-level language code in assembly.
Could you re-write your high-level language code in assembly.
Re:How to print a message in protected mode
How would I implement my own console driver for the video?
I am not ready to use v86 mode and I could use unreal mode but it would be like switching to real mode and back everytime I wanted to print a message?
Is there another way?
I am not ready to use v86 mode and I could use unreal mode but it would be like switching to real mode and back everytime I wanted to print a message?
Is there another way?
Re:How to print a message in protected mode
You didn't say anything specific about it, so I couldn't know what were you looking for. I guess any example is better than no examples at all, right?
anyway, the example is pretty easy to understand for yourself.
If you know how addressing modes work in assembly + how to make a simply loop, it is easy.
otherwise just grab gdb
what you need to know is that the video buffer for a 80x25 console is at 0xB8000 and you can poke characters directly there (one byte for the character and one byte as an attribute character), there are plenty of examples on the web.
good luck
anyway, the example is pretty easy to understand for yourself.
If you know how addressing modes work in assembly + how to make a simply loop, it is easy.
otherwise just grab gdb
what you need to know is that the video buffer for a 80x25 console is at 0xB8000 and you can poke characters directly there (one byte for the character and one byte as an attribute character), there are plenty of examples on the web.
good luck
Re:How to print a message in protected mode
and you WILL need to change to real mode unless you "roll-your-own" video/ide/all-32-bits drivers
Re:How to print a message in protected mode
By the way, what type of addressing mode are you using in your example code?
Re:How to print a message in protected mode
You can do this using indirect mode if you INC your counter starting from 0xB800 and then MOVe the content there.
Or, the most probable if you compile this with gcc, a base-offset displacement, like:
/*
* dl = the byte you want to write
* bx = your last cursor location
*/
movw $0xB800, %ax
pushw %ax
popw %es
movw %dl, %es:(%bx)
inc %bx
movw %dl, %es:(%bx)
you could write something like 'movw %dl, %esN(%bx)
where 'N' is a displacement withing that base-offset
see:
http://www.gnu.org/manual/gas/html_chapter/as_16.html
anyway, the syntax depends on your asm compiler. at&t is better (for me) because you can play with parameters like base index and scale easier.
Or, the most probable if you compile this with gcc, a base-offset displacement, like:
/*
* dl = the byte you want to write
* bx = your last cursor location
*/
movw $0xB800, %ax
pushw %ax
popw %es
movw %dl, %es:(%bx)
inc %bx
movw %dl, %es:(%bx)
you could write something like 'movw %dl, %esN(%bx)
where 'N' is a displacement withing that base-offset
see:
http://www.gnu.org/manual/gas/html_chapter/as_16.html
anyway, the syntax depends on your asm compiler. at&t is better (for me) because you can play with parameters like base index and scale easier.
Re:How to print a message in protected mode
I using the Intel syntax and nasm as my assember. You are using AT&t syntax so I can't really use your examples. Thanks for the help anyways.
I have re-written it in intel syntax, heres what it looks like in nasm:
mov 0xB800,ax
push ax
pop es
mov dl,es:bx
inc bx
mov dl,es:bx
I have re-written it in intel syntax, heres what it looks like in nasm:
mov 0xB800,ax
push ax
pop es
mov dl,es:bx
inc bx
mov dl,es:bx
Re:How to print a message in protected mode
one of the major differences between at&t and intel syntax is the order
of the operands, so:
mov $0x0, %ax
becomes
mov ax, 0
now for indirect mode addressing in intel syntax:
mov byte [es:bx], dl
versus the at&t syntax
movb %dl, %es:(%bx)
remember that this code is 16 bits!! also remember that you should write 2-byte words instead of bytes because of the additional attribute
byte.
regards
of the operands, so:
mov $0x0, %ax
becomes
mov ax, 0
now for indirect mode addressing in intel syntax:
mov byte [es:bx], dl
versus the at&t syntax
movb %dl, %es:(%bx)
remember that this code is 16 bits!! also remember that you should write 2-byte words instead of bytes because of the additional attribute
byte.
regards
Re:How to print a message in protected mode
hi,
first your video pointer should be
video ptr=0xb8000 - segment base
segment baze = 0 video ptr = 0xb8000
segment baze = X video ptr = 0xb8000 - X
so if your sements are not zero based then you have to do this
also change
mov eax,[esi] ; String char to AL
lea esi,[esi+1] ; Advance one byte into string
cmp al,0
jne dochar ; Else, we're done
add byte [ypos],1 ; Down one row
mov byte [xpos],0 ; Back to left
ret
to
mov eax,[esi] ; String char to AL
inc esi ; Advance one byte into string
mov al,[esi]
cmp al,0
jne dochar ; Else, we're done
add byte [ypos],1 ; Down one row
mov byte [xpos],0 ; Back to left
ret
...
...
...
see if that helps
first your video pointer should be
video ptr=0xb8000 - segment base
segment baze = 0 video ptr = 0xb8000
segment baze = X video ptr = 0xb8000 - X
so if your sements are not zero based then you have to do this
also change
mov eax,[esi] ; String char to AL
lea esi,[esi+1] ; Advance one byte into string
cmp al,0
jne dochar ; Else, we're done
add byte [ypos],1 ; Down one row
mov byte [xpos],0 ; Back to left
ret
to
mov eax,[esi] ; String char to AL
inc esi ; Advance one byte into string
mov al,[esi]
cmp al,0
jne dochar ; Else, we're done
add byte [ypos],1 ; Down one row
mov byte [xpos],0 ; Back to left
ret
...
...
...
see if that helps