Why it's not possible give args to functions

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
User avatar
Karlosoft
Member
Member
Posts: 277
Joined: Thu Feb 14, 2008 10:46 am
Location: Italy
Contact:

Why it's not possible give args to functions

Post 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 :)
Attachments
smile.zip
(12.02 KiB) Downloaded 170 times
montrom
Member
Member
Posts: 86
Joined: Thu May 13, 2010 1:45 pm

Re: Why it's not possible give args to functions

Post by montrom »

In which file would this be taking place? Just post some of the relevant code here and leave the rest attached. ;)
Visit the Montrom user page for more info.
User avatar
Karlosoft
Member
Member
Posts: 277
Joined: Thu Feb 14, 2008 10:46 am
Location: Italy
Contact:

Re: Why it's not possible give args to functions

Post 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...
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Why it's not possible give args to functions

Post 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
If a trainstation is where trains stop, what is a workstation ?
User avatar
Karlosoft
Member
Member
Posts: 277
Joined: Thu Feb 14, 2008 10:46 am
Location: Italy
Contact:

Re: Why it's not possible give args to functions

Post 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....
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Why it's not possible give args to functions

Post by Combuster »

Have you checked what ESP is pointing to?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Re: Why it's not possible give args to functions

Post 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
User avatar
Karlosoft
Member
Member
Posts: 277
Joined: Thu Feb 14, 2008 10:46 am
Location: Italy
Contact:

Re: Why it's not possible give args to functions

Post 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
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Why it's not possible give args to functions

Post 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 $
If a trainstation is where trains stop, what is a workstation ?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Why it's not possible give args to functions

Post by Combuster »

Ok, you must be kidding me.
link.ld wrote:phys = 0xFF800000;
Your kernel, in the BIOS area? :shock:
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Karlosoft
Member
Member
Posts: 277
Joined: Thu Feb 14, 2008 10:46 am
Location: Italy
Contact:

Re: Why it's not possible give args to functions

Post 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
User avatar
Karlosoft
Member
Member
Posts: 277
Joined: Thu Feb 14, 2008 10:46 am
Location: Italy
Contact:

Re: Why it's not possible give args to functions

Post 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?
User avatar
Karlosoft
Member
Member
Posts: 277
Joined: Thu Feb 14, 2008 10:46 am
Location: Italy
Contact:

Re: Why it's not possible give args to functions

Post 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 :)
Post Reply