OSDev.org

The Place to Start for Operating System Developers
It is currently Sat Jun 25, 2022 8:32 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Need some explainations
PostPosted: Tue Jan 11, 2022 9:17 pm 
Offline
Member
Member

Joined: Wed Oct 20, 2021 6:00 pm
Posts: 102
Location: Paraguay
Hi,
I'm trying to implement HPET on my hobby OS. After I read this article: https://wiki.osdev.org/HPET, I want to ask one thing: Can you explain this line?
Code:
write_register_64(timer_configuration(n), (ioapic_input << 9) | (1 << 2));

Not exactly that line, but the function write_register_64. I don't know how to implement it. Can anyone help me?


Top
 Profile  
 
 Post subject: Re: Need some explainations
PostPosted: Tue Jan 11, 2022 10:38 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 3865
It's a function that writes a 64-bit value to a MMIO register.

If you're writing your kernel in C, you should probably write the function in assembly so you can ensure compiler optimizations won't reorder or remove the write.


Top
 Profile  
 
 Post subject: Re: Need some explainations
PostPosted: Wed Jan 12, 2022 1:13 am 
Offline
Member
Member

Joined: Wed Oct 20, 2021 6:00 pm
Posts: 102
Location: Paraguay
Octocontrabass wrote:
It's a function that writes a 64-bit value to a MMIO register.

That's the problem, I don't know what I should write. I have worked with registers, memory,... but this is my first time with MMIO register. In my case, is that I have to use port and outX/inX?


Top
 Profile  
 
 Post subject: Re: Need some explainations
PostPosted: Wed Jan 12, 2022 5:46 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4365
Location: Chichester, UK
The clue is in the name Memory-Mapped Input/Output.


Top
 Profile  
 
 Post subject: Re: Need some explainations
PostPosted: Thu Jan 13, 2022 2:01 am 
Offline
Member
Member

Joined: Mon Jul 05, 2021 6:57 pm
Posts: 84
NeonLightions wrote:
That's the problem, I don't know what I should write. I have worked with registers, memory,... but this is my first time with MMIO register. In my case, is that I have to use port and outX/inX?


No, "memory mapped" means you read and write it as if it was memory. Literally just store or read a value from the correct address.

You should use a volatile pointer to avoid the compiler re-ordering, collapsing or eliding the loads and stores.


Top
 Profile  
 
 Post subject: Re: Need some explainations
PostPosted: Thu Jan 13, 2022 2:22 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 3865
davmac314 wrote:
You should use a volatile pointer to avoid the compiler re-ordering, collapsing or eliding the loads and stores.

The C standard still gives compilers some flexibility in how they implement volatile. GCC seems to handle it in a way that's appropriate for MMIO, but I'm pretty sure Clang does not!


Top
 Profile  
 
 Post subject: Re: Need some explainations
PostPosted: Sat Jan 15, 2022 1:00 am 
Offline
Member
Member

Joined: Mon Jul 05, 2021 6:57 pm
Posts: 84
Octocontrabass wrote:
The C standard still gives compilers some flexibility in how they implement volatile. GCC seems to handle it in a way that's appropriate for MMIO, but I'm pretty sure Clang does not!

I know that volatile has historically been problematic in both GCC and Clang (https://llvm.org/pubs/2008-10-EMSOFT-Volatiles.pdf) but I'm not aware of any current bugs in code generation around use of volatile in Clang. I'd be interested to see any example.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group