Page 2 of 3
Re:problem in printf stuff
Posted: Mon Nov 11, 2002 9:02 pm
by Tom
I think it could be a GDT thing because how you setup your GDT either lets you write messages to RAM ( what your doing ) or not. )
Re:problem in printf stuff
Posted: Mon Nov 11, 2002 9:07 pm
by _adeelmahmood
well i have sorted out the problem
thanx for ur help ;D
Re:problem in printf stuff
Posted: Mon Nov 11, 2002 9:14 pm
by Tom
what was wrong with your code?
Re:problem in printf stuff
Posted: Mon Nov 11, 2002 9:29 pm
by adeelmahmood1
i dont know i just put a
void start(){
c_main();
}
in the start of my kernel and it started working .. i read something about this in Tim Robinson tutorial that the literal strings comes to the top after compiling and hence the computer crashes so this was the suggestion in the tutorial to write a method in the start and call main ..
by the way thanx for ur help
Re:problem in printf stuff
Posted: Tue Nov 12, 2002 10:32 am
by Tom
huh? usually you can just type in what ever function you like...at least with my code
Re:problem in printf stuff
Posted: Tue Nov 12, 2002 10:33 am
by Tom
OH...ADD this to the top of your code:
asm( "jmp <your main function>" );
Re:problem in printf stuff
Posted: Tue Nov 12, 2002 10:49 am
by Pype.Clicker
Tom wrote:
OH...ADD this to the top of your code:
asm( "jmp <your main function>" );
hmm ... and pray for the linker to keep it on top ... i prefer well-defined entry points ...
Re:problem in printf stuff
Posted: Tue Nov 12, 2002 11:09 am
by Tom
you could do this:
#pragma startup asm( "sti" ) 64 // OOPS edited this, needs to be 64
Re:problem in printf stuff
Posted: Tue Nov 12, 2002 11:42 am
by Tim
I think Tom is asking for trouble there.
The best thing to do is to write a separate .asm file which calls your C entry point (you will also want to set up the stack etc. too). If you put that file first on the linker command line then it is virtually guaranteed to get put in the right place.
Of course, if you're not using flat binary, then it doesn't matter where your entry point is -- you can even start straight into your C function.
Re:problem in printf stuff
Posted: Tue Nov 12, 2002 11:55 am
by Tom
I don't know how that asm function got changed to "sti"
but...I ment to do:
...asm( "jmp start" )...
Re:problem in printf stuff
Posted: Tue Nov 12, 2002 1:10 pm
by adeelmahmood1
well actually Tim i m already using a 2nd stage loader to load this c kernel at 00005000 thats why i was avoiding another asm file in between them coz then i will load that file at this place and then again from that file jump to this kernel at some other place ..
well thanx for everyone help
Re:problem in printf stuff
Posted: Wed Nov 13, 2002 12:50 am
by adeelmahmood1
ok now i have a few more questions:
1. for the printf function i m thinking that if my printf has to print some variable value how does it works then..
coz it should be a general one for all data types mean it should print int , char or string whatever comes in its way .. so if i pass first argument of aprintf , the printed string and second argument, that variable which can either be an int or a char or something else..
so what should be that 2nd argument which can a char or int or anything else..is there a way to do something like that.. hope u understood it
2. i need a getCursor funtion which could return the current cursor position .. if u give me the code plz explain it
thanx
Re:problem in printf stuff
Posted: Wed Nov 13, 2002 2:02 pm
by adeelmahmood1
helooooo? i reallly need help in this .. plz help
Re:problem in printf stuff
Posted: Wed Nov 13, 2002 2:54 pm
by Tom
look at my fstdio.h in pk0.6...include it and my other files and test this:
void <your main>()
{
start_textmode();
printf( "Gettting Cursor:\n" );
printf( "x=%d, y=%d", cur_cursorX, cur_cursorY );
Freeze();
}
Re:problem in printf stuff
Posted: Wed Nov 13, 2002 4:24 pm
by adeelmahmood1
well Tom thanx but actually i have ur code and when i checked it i didnt understood it thats why i posted the message here .. first u have this in ur code
Code: Select all
static int printf( char *msg, ... )
i have no idea how does this 2nd argument "..." works. plz explain these 3 dots
after that
what is this va_list.. to check this i went to stdarg.h and to tell u the truth i didnt understood a single word of it
now comes the cursor thing..
Code: Select all
// cursor LOW port to vga INDEX register
outportb( 0x3D4, 0x0F );
outportb( 0x3D5, ( UCHAR ) ( position & 0xFF ) );
// cursor HIGH port to vga INDEX register
outportb( 0x3D4, 0x0E );
outportb( 0x3D5, ( UCHAR ) ( ( position >> 8 ) & 0xFF ) );
plz can u explain this and how do u know that sending 0x0f to 0x3D4 works in this way and similarly for the 2nd one .. i mean from where do u get to know this
i know these are alot of questions but plz if u have time explain them in detail or if some one else could do it
thanx for ur help
hey i have one more thing to ask .. like if i m loading my kernel code at 00005000 then i use
jmp dword CODE_SEG:0x5000;
but what if i load it at 50000000??