Page 1 of 1

How do i convert a void* to a unsigned long*?

Posted: Wed Jan 11, 2017 4:06 pm
by DixiumOS
I am trying to load ISR's. However, i have 32 isr(num) void type functions. Since my function only accepts uint32_t's or unsigned long's, i would like to convert my functions to a uint32_t*, unsigned long* or similar.

(the function is just a void, i point to it in the function).
If i try to do (uintptr_t)isr[num]();, it gives "invalid use of void expression".

If i try (uintptr_t*), same thing.

How would i convert this?

Re: How do i convert a void* to a unsigned long*?

Posted: Wed Jan 11, 2017 4:09 pm
by hgoel
By reading up on function pointers and seeing what extra stuff you you have there.

Re: How do i convert a void* to a unsigned long*?

Posted: Wed Jan 11, 2017 6:14 pm
by dozniak
DixiumOS wrote:How would i convert this?
Keep in mind, this forum is not for teaching beginner-level programming topics.

Re: How do i convert a void* to a unsigned long*?

Posted: Wed Jan 11, 2017 7:54 pm
by dchapiesky
assembly language would be a superior way of accomplishing this task

Re: How do i convert a void* to a unsigned long*?

Posted: Thu Jan 12, 2017 12:53 am
by DixiumOS
Looks like i get invalid void expression every time i try to do

Code: Select all

&(uint32_t)isr[num]()
or

Code: Select all

&(unsigned long)isr[num]()
or any other. I'm gonna try to switch my function type to an unsigned int and convert it to a unsigned long (same size) and see if that works.

Re: How do i convert a void* to a unsigned long*?

Posted: Thu Jan 12, 2017 1:06 am
by DixiumOS
Finally fixed it.

I had to make my function type an int then in the function do

Code: Select all

(unsigned)isr[num]()
.

Re: How do i convert a void* to a unsigned long*?

Posted: Thu Jan 12, 2017 1:36 am
by Octocontrabass
DixiumOS wrote:Finally fixed it.
No you didn't.

Just like with your terminal_writechar and terminal_writestring (which are both still broken, by the way), your code is obviously wrong.

As suggested in an earlier post, you need to research function pointers.

Re: How do i convert a void* to a unsigned long*?

Posted: Thu Jan 12, 2017 1:55 am
by DixiumOS
Octocontrabass wrote:
DixiumOS wrote:Finally fixed it.
No you didn't.

Just like with your terminal_writechar and terminal_writestring (which are both still broken, by the way), your code is obviously wrong.

As suggested in an earlier post, you need to research function pointers.
I didn't even need the pointer, anyway. The tutorial also puts (unsigned), but had the wrong types on the other file, i had to tweak things, i got on a completely different road (when i asked this question), and then went to the correct thing.

Now my only error/warning is a one that i can't seem to understand.

"Just like with your terminal_writechar and terminal_writestring (which are both still broken, by the way)"
I think you looked at the first few posts, and ignored the entire rest

Re: How do i convert a void* to a unsigned long*?

Posted: Thu Jan 12, 2017 2:18 am
by Octocontrabass
DixiumOS wrote:I didn't even need the pointer, anyway.
So if you don't need the pointer, then what exactly are you putting in your IDT? (And where is your assembly wrapper for your ISRs? You can't do IRET in inline assembly.)
DixiumOS wrote:Now my only error/warning is a one that i can't seem to understand.
This is why we keep telling you to learn C before you start writing an OS.
DixiumOS wrote:"Just like with your terminal_writechar and terminal_writestring (which are both still broken, by the way)"
I think you looked at the first few posts, and ignored the entire rest
No, I'm looking at your repo. Broken code everywhere.

Re: How do i convert a void* to a unsigned long*?

Posted: Thu Jan 12, 2017 2:28 am
by DixiumOS
Octocontrabass wrote:
DixiumOS wrote:"Just like with your terminal_writechar and terminal_writestring (which are both still broken, by the way)"
I think you looked at the first few posts, and ignored the entire rest
No, I'm looking at your repo. Broken code everywhere.
I still haven't updated that.

Re: How do i convert a void* to a unsigned long*?

Posted: Thu Jan 12, 2017 2:50 am
by Octocontrabass
Now you've updated it, but your code is still broken. You still aren't using function pointers correctly (and even if you were, you still can't use IRET in inline assembly).

Re: How do i convert a void* to a unsigned long*?

Posted: Thu Jan 12, 2017 10:07 am
by hgoel
Octocontrabass wrote:Now you've updated it, but your code is still broken. You still aren't using function pointers correctly (and even if you were, you still can't use IRET in inline assembly).
Technically you can, it just needs a lot more care. Agreed on the rest though.