Page 1 of 1
Why it's not possible give args to functions
Posted: Thu May 27, 2010 1:10 pm
by Karlosoft
I'm in the way to become crazy, in the attempt to understand why the values I give to the functions args are simply ignored
Thanks to everyone will reply
Re: Why it's not possible give args to functions
Posted: Thu May 27, 2010 1:42 pm
by montrom
In which file would this be taking place? Just post some of the relevant code here and leave the rest attached.
Re: Why it's not possible give args to functions
Posted: Thu May 27, 2010 2:02 pm
by Karlosoft
char* vga=(char*)0xb8000;
uint32 counter=0;
void putc(const char c){
vga[counter]=(char)c;
vga[counter+1]=66;
counter+=2;
};
and when i call putc from main no value to the function has been given...
Re: Why it's not possible give args to functions
Posted: Thu May 27, 2010 7:58 pm
by gerryg400
and when i call putc from main no value to the function has been given...
How do you know this ? Do you know for sure that main is reached ? I suspect that it is not. start.asm looks incomplete.
- gerryg400
Re: Why it's not possible give args to functions
Posted: Fri May 28, 2010 2:14 am
by Karlosoft
Sure, main is called by the start routine in start.asm. The problem is the value I assign to the arg. I don't know the reason. If I change the putc function with somethink like
void putc(const char c){
vga[counter]='g'; //Any other direct value
vga[counter+1]=66;
counter+=2;
};
It works....
Re: Why it's not possible give args to functions
Posted: Fri May 28, 2010 2:31 am
by Combuster
Have you checked what ESP is pointing to?
Re: Why it's not possible give args to functions
Posted: Fri May 28, 2010 5:29 am
by jal
Karlosoft wrote:and when i call putc from main no value to the function has been given...
The values are transferred via the stack, there is no such thing as "no value" on the stack. Your function will (try to) access the stack no matter what. As Combuster implied, you probably have a stack problem.
JAL
Re: Why it's not possible give args to functions
Posted: Fri May 28, 2010 7:59 am
by Karlosoft
The value is always set 0...
mov esp, _sys_stack ; This points the stack to our new stack area
Is the third line of start.asm, the only place where I directly change the address of esp
Re: Why it's not possible give args to functions
Posted: Fri May 28, 2010 8:13 am
by gerryg400
Dunno if it matters but you are calling the kn function before the dtors stuff. You should be calling kn from near the jmp $
Re: Why it's not possible give args to functions
Posted: Fri May 28, 2010 8:17 am
by Combuster
Ok, you must be kidding me.
link.ld wrote:phys = 0xFF800000;
Your kernel, in the BIOS area?
Re: Why it's not possible give args to functions
Posted: Fri May 28, 2010 8:50 am
by Karlosoft
I just used the address where bootf jumps to
It use a little strange gtd where the first mb is defined with that address... I think -.-
mov CR3, eax ;Set up page directory
mov eax, CR0 ;Turn on paging and protected mode
or eax, 0x80000001
mov CR0, eax
mov cl, flat_data ;Setup ds and es
push cx ;{5}
pop ds
mov es, cx
jmp dword 8:0xFF800000 ;Go
A piece of code of bootf
Re: Why it's not possible give args to functions
Posted: Fri May 28, 2010 11:48 am
by Karlosoft
The bug seem to be just in the data space, because the code works fine. It's possible that the problem is linked to the paging enabled by bootloader?
Re: Why it's not possible give args to functions
Posted: Fri May 28, 2010 2:26 pm
by Karlosoft
MOV AX, 0x10 ; 0x10 points at the new data selector
MOV DS, AX
MOV ES, AX
MOV FS, AX
MOV GS, AX
MOV SS, AX
I had to add these few lines in start.asm ^_^ now it runs good