Hi,
i wrote a test function to check if pointers work, but with this function pointers do not work, only stupid values back, why ?
Here is my function:
void test(int *a)
{
*a = *a >> 1;
}
void main(void)
{
int i = 8;
test(&i);
// my function to print to screen
writeln(inttostr(i));
}
Why do pointer not work in my os ?
Re:Why do pointer not work in my os ?
Are you sure that your inttostr() function is working properly?
Re:Why do pointer not work in my os ?
Hi,
thanks for your help, yes my writeln() function works perfect. do i need a memory management for using pointers ?
bye
matze
thanks for your help, yes my writeln() function works perfect. do i need a memory management for using pointers ?
bye
matze
Re:Why do pointer not work in my os ?
no, but you will need pmode or v86 mode to make flat addresses work...
but if you're sure your writeln() function is working, then your pointers are working (you pass a char* to writeln(), aren't you?)
So maybe the problem is something else, like your data segment being wrong or something like that. why don't you tell us something more about your code?
p.s: do you know what is your stack doing at the moment??
but if you're sure your writeln() function is working, then your pointers are working (you pass a char* to writeln(), aren't you?)
So maybe the problem is something else, like your data segment being wrong or something like that. why don't you tell us something more about your code?
p.s: do you know what is your stack doing at the moment??
Re:Why do pointer not work in my os ?
gcc works fine
00000000 55 push ebp
00000001 89E5 mov ebp,esp
00000003 8B5508 mov edx,[ebp+0x8]
00000006 8B4508 mov eax,[ebp+0x8]
00000009 8B00 mov eax,[eax]
0000000B D1F8 sar eax,1
0000000D 8902 mov [edx],eax
0000000F 5D pop ebp
00000010 C3 ret
00000011 90 nop
00000012 55 push ebp
00000013 89E5 mov ebp,esp
00000015 83EC08 sub esp,byte +0x8
00000018 83E4F0 and esp,byte -0x10
0000001B B800000000 mov eax,0x0
00000020 29C4 sub esp,eax
00000022 C745FC08000000 mov dword [ebp-0x4],0x8
00000029 83EC0C sub esp,byte +0xc
0000002C 8D45FC lea eax,[ebp-0x4]
0000002F 50 push eax
00000030 E8CBFFFFFF call 0x0
00000035 83C410 add esp,byte +0x10
00000038 C9 leave
00000039 C3 ret
00000000 55 push ebp
00000001 89E5 mov ebp,esp
00000003 8B5508 mov edx,[ebp+0x8]
00000006 8B4508 mov eax,[ebp+0x8]
00000009 8B00 mov eax,[eax]
0000000B D1F8 sar eax,1
0000000D 8902 mov [edx],eax
0000000F 5D pop ebp
00000010 C3 ret
00000011 90 nop
00000012 55 push ebp
00000013 89E5 mov ebp,esp
00000015 83EC08 sub esp,byte +0x8
00000018 83E4F0 and esp,byte -0x10
0000001B B800000000 mov eax,0x0
00000020 29C4 sub esp,eax
00000022 C745FC08000000 mov dword [ebp-0x4],0x8
00000029 83EC0C sub esp,byte +0xc
0000002C 8D45FC lea eax,[ebp-0x4]
0000002F 50 push eax
00000030 E8CBFFFFFF call 0x0
00000035 83C410 add esp,byte +0x10
00000038 C9 leave
00000039 C3 ret
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Why do pointer not work in my os ?
the only non-trivial (i mean, not a bug in writeln or inttostr) error that i can envision is that your DATA segment and your STACK segment are not aligned. I mean, you get the address of i using the %ebp register, which is itself a copy of your stack pointer %esp at some moment. both these register implicitly refer to %ss stack register. As you start manipulating it as a pointer, you (gcc) move it to a generic register (%eax and %edx) which are implicitly related to %ds ... so if %ss!=%ds, you can experience problems, especially if GDT[%ss].base != GDT[%ds].base