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.
p0s1x
Posts: 18 Joined: Thu Mar 21, 2013 8:37 am
Post
by p0s1x » Thu Mar 21, 2013 8:44 am
Hello world, I have a question, how to make basic printf or scanf functions on OS?
I use this:
Code: Select all
void write_string( int colour, const char *string )
{
volatile char *video = (volatile char*)0xB8000;
while( *string != 0 )
{
*video++ = *string++;
*video++ = colour;
}
};
but this can't print any string or character. Console pointer goes crazy. Can you help? Thanks.
//Sorry for bad English
MDenham
Member
Posts: 62 Joined: Sat Nov 10, 2012 1:16 pm
Post
by MDenham » Thu Mar 21, 2013 10:20 am
Are you sure you're operating in real mode when this function is called?
p0s1x
Posts: 18 Joined: Thu Mar 21, 2013 8:37 am
Post
by p0s1x » Thu Mar 21, 2013 10:23 am
MDenham wrote: Are you sure you're operating in real mode when this function is called?
I use bare bones from
here . I not sure.
p0s1x
Posts: 18 Joined: Thu Mar 21, 2013 8:37 am
Post
by p0s1x » Thu Mar 21, 2013 10:45 am
I use this (My code :3):
Code: Select all
void printf(char *string )
{
asm(
"mov %si, string \n"
"call DisplayMessage \n"
"DisplayMessage: \n"
"lodsb \n"
"or %al, %al \n"
"jz .DONE \n"
"mov %ah, 0x0E \n"
"mov %bh, 0x00 \n"
"mov %bl, 0x07 \n"
"int $0x10 \n"
"jmp DisplayMessage \n"
".DONE: \n"
"ret \n");
};
And have linker error:
Code: Select all
kernel.o:kernel.c:(.text+0x40): undefined reference to `string'
How to use C variables in inline assembler?
bluemoon
Member
Posts: 1761 Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong
Post
by bluemoon » Thu Mar 21, 2013 11:36 am
If you follow the bare bone tutorial, I assume you're on gcc.
inline assembly with gcc uses input/output/clobber lists instead of putting variable names directly in assembly instruction (aka old visual c++ style), I suggest you read the gcc inline assembly manual.
By the way, string is a really bad variable name.
Gigasoft
Member
Posts: 856 Joined: Sat Nov 21, 2009 5:11 pm
Post
by Gigasoft » Thu Mar 21, 2013 11:58 am
If your GCC program is running, then the processor must not be in real mode. Otherwise, you would not be able to run your program. Therefore, you can not call BIOS functions.
iansjack
Member
Posts: 4711 Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK
Post
by iansjack » Thu Mar 21, 2013 4:15 pm
In your original program you are assuming that
char *video = (volatile char*)0xB8000;
points to video memory. I'd say that is quite a large assumption; it may depend upon what value you have placed in DS.
p0s1x
Posts: 18 Joined: Thu Mar 21, 2013 8:37 am
Post
by p0s1x » Fri Mar 22, 2013 5:14 am
How to move CPU in Real Time Mode?
Brendan
Member
Posts: 8561 Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:
Post
by Brendan » Fri Mar 22, 2013 7:48 am
Hi,
p0s1x wrote: How to move CPU in Real Time Mode?
Do you mean: How do you move data (using the CPU) while in Real Mode?
If this is what you're asking, then my favourite is "rep movsd".
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
p0s1x
Posts: 18 Joined: Thu Mar 21, 2013 8:37 am
Post
by p0s1x » Fri Mar 22, 2013 9:55 am
Bare Bones switch CPU to Real or Protected mode?
Mikemk
Member
Posts: 409 Joined: Sat Oct 22, 2011 12:27 pm
Post
by Mikemk » Fri Mar 22, 2013 11:27 am
p0s1x wrote: Bare Bones switch CPU to Real or Protected mode?
You want to switch from real mode to pmode, then immediately back to real mode?
Programming is 80% Math, 20% Grammar, and 10% Creativity <--- Do not make fun of my joke!
If you're new, check
this out.
p0s1x
Posts: 18 Joined: Thu Mar 21, 2013 8:37 am
Post
by p0s1x » Fri Mar 22, 2013 11:49 am
I want to switch CPU to protected mode for access video memory
Mikemk
Member
Posts: 409 Joined: Sat Oct 22, 2011 12:27 pm
Post
by Mikemk » Fri Mar 22, 2013 1:05 pm
Here is a code sample. Let's see if you can implement it.
BTW, I don't know c++, so you or somebody will have to translate.
From real mode (assuming string index passed in ds:si, and color in al):
Code: Select all
print:
mov bx, 0xb800
mov es, bx
xor bx, bx
.loop:
mov ah, [si]
cmp ah, 0
je .endi
mov [es:bx], ax
add bx, 2
inc si
jmp .loop
.endi:
pmode:
Code: Select all
print:
mov bx, [i]selector[/i]
mov es, bx
mov ebx, 0xb8000
.loop:
mov ah, [esi]
cmp ah, 0
je .endi
mov [es:ebx], ax
add ebx, 2
inc esi
jmp .loop
.endi:
Programming is 80% Math, 20% Grammar, and 10% Creativity <--- Do not make fun of my joke!
If you're new, check
this out.
p0s1x
Posts: 18 Joined: Thu Mar 21, 2013 8:37 am
Post
by p0s1x » Fri Mar 22, 2013 11:34 pm
My friend send me code:
"That code enter system to pmode", really?
Nessphoro
Member
Posts: 308 Joined: Sat Apr 30, 2011 12:50 am
Post
by Nessphoro » Fri Mar 22, 2013 11:40 pm
p0s1x wrote: My friend send me code:
"That code enter system to pmode", really?
Attachments
1302143491780.jpg (6.77 KiB) Viewed 2874 times