Page 1 of 1
How can i make my lidt/lgdt accept structs?
Posted: Tue Jan 03, 2017 4:15 pm
by NunoLava1998
I am loading the IDT and GDT. However, when i try to put a struct into my lidt and lgdt functions:
Code: Select all
static inline void lidt(void* base, uint16_t size)
{ // This function works in 32 and 64bit mode
struct {
uint16_t length;
void* base;
} __attribute__((packed)) IDTR = { size, base };
asm volatile ( "lidt %0" : : "m"(IDTR) ); // let the compiler choose an addressing mode
}
void lgdt(void* base, uint16_t size){
struct {
uint16_t length;
void* base;
} __attribute__((packed)) GDTR = { size, base };
asm volatile ("lgdt %0" : : "m"(GDTR) );
}
and try to insert my struct:
Code: Select all
lidt(struct idt_description);
lgdt(struct gdt_description);
I get errors and warnings that all relate to the function expecting 2 functions, but only being given 1.
How can i recode my lidt and lgdt instructions to accept only 1 instruction?
Oh, and no code and no arguing. I already know how to make code by myself. Unless it's extra difficult, you do not need to provide code.
Re: How can i make my lidt/lgdt accept structs?
Posted: Tue Jan 03, 2017 4:38 pm
by Kevin
The functions are declared to take a void* and a uint16_t. You're passing it a... type name or something? That's not quite the same.
And this is really just basic C, not related to OSes at all.
Re: How can i make my lidt/lgdt accept structs?
Posted: Tue Jan 03, 2017 4:48 pm
by NunoLava1998
Kevin wrote:The functions are declared to take a void* and a uint16_t. You're passing it a... type name or something? That's not quite the same.
And this is really just basic C, not related to OSes at all.
sorry. i'm trying to pass a struct
Re: How can i make my lidt/lgdt accept structs?
Posted: Tue Jan 03, 2017 5:28 pm
by Love4Boobies
I think all of us on the forum would do him a huge favour if we stopped answering his questions. This one is simply embarrassing; he doesn't understand the semantics of procedure calls---one of the simplest and most fundamental things anyone can learn in programming. He doesn't want want to read like 200 pages of text that would teach him C in a couple of days. He would be done with K&R by now. But no, instead, he wants to spend eternity asking the most stupid questions about each and every line of code (sometimes he doesn't even understand the questions he is asking, let alone the answers).
Re: How can i make my lidt/lgdt accept structs?
Posted: Wed Jan 04, 2017 12:57 am
by iansjack
+1
Re: How can i make my lidt/lgdt accept structs?
Posted: Wed Jan 04, 2017 2:34 am
by NunoLava1998
yeah, i'm gonna start adding some people as foes
i'm pretty sure only sortie and glauxosdever have actually realized i've started to write code myself
Re: How can i make my lidt/lgdt accept structs?
Posted: Wed Jan 04, 2017 2:43 am
by glauxosdever
Hi,
NunoLava1998 wrote:yeah, i'm gonna start adding some people as foes
This doesn't benefit you at all. Unless they are disrupting and/or insulting and have nothing good to give you, there is no point in adding them as foes; they still have something useful to say.
NunoLava1998 wrote:i'm pretty sure only sortie and glauxosdever have actually realized i've started to write code myself
Maybe you started to write code yourself, but you can't write correct code without help. I suggest you learn C.
Regards,
glauxosdever
Re: How can i make my lidt/lgdt accept structs?
Posted: Wed Jan 04, 2017 2:56 am
by osdever
NunoLava1998 wrote:Kevin wrote:The functions are declared to take a void* and a uint16_t. You're passing it a... type name or something? That's not quite the same.
And this is really just basic C, not related to OSes at all.
sorry. i'm trying to pass a struct
Just learn C. Please. I'm tired of all these questions.
Re: How can i make my lidt/lgdt accept structs?
Posted: Wed Jan 04, 2017 3:20 am
by Solar
Seconded. Kernel space is not the place to learn basics of your programming language of choice.
Re: How can i make my lidt/lgdt accept structs?
Posted: Wed Jan 04, 2017 7:24 am
by dozniak
You guys miss the chance to teach him something that is not C, nor asm, nor it is usable in any way, just for giggles.
Things like "Struct is a mirror of processor registers" or "function calls require heap", all that jazz.
Just imagine the face of his future employer.
Re: How can i make my lidt/lgdt accept structs?
Posted: Wed Jan 04, 2017 7:48 am
by Solar
Being one of those regularly assigned as tutor for newcomers in the office, and having to face the consequences of sub-par preparation for the job, I somewhat fail to see the joke. (
)
"Getting it right" is so much more satisfying.
Re: How can i make my lidt/lgdt accept structs?
Posted: Wed Jan 04, 2017 10:00 pm
by PrivatePecker2
Hi Nuno, I've noticed that you've been posting on these forums recently, to the annoyance of many, and I am genuinely concerned about your future in programming especially if you seek employment. A simple Google search of your username brings up many embarrassing results on all kinds of forums. All I really want you to do here is to make sure all of your accounts are thoroughly anonymized and it is impossible to connect your real name to your username on any of the many sites you have created accounts on.
Since this is my first post here I also thought I would say hello. I've recently taken up the hobby of OSDeving and like to browse these forums on occasion. Don't expect to hear from me that often, I'm not very social.
Re: How can i make my lidt/lgdt accept structs?
Posted: Thu Jan 05, 2017 4:56 pm
by Schol-R-LEA
That would be great advice (which I wish I had been given 20 years ago myself) if it weren't for the fact that, given what I have seen when searching on 'nunolava', his username is probably based on his real name. Nuño is a fairly common personal name in Spanish, and Nuno is equally common in Portuguese; while there are several Spanish and Portuguese surnames which start with 'Lava', such as Lavajo and Lavareda.
Thus, while it is not necessarily obvious which of the several individuals on (say) LinkedIn whose names match 'Nuno Lava*' he is, it would probably be fairly easy to narrow it down.