On Hardware Abstraction Layers
- Love4Boobies
- Member
- Posts: 2111
- Joined: Fri Mar 07, 2008 5:36 pm
- Location: Bucharest, Romania
On Hardware Abstraction Layers
Hi.
I'd like to open a topic on HALs. What do you think would be the best way of implementing one? How does your OS handle it? There can be many designs; take for example Singularity which is certainly different from most OSes in this respect. What would be the best way to support as many architectures as possible?
I'd like to open a topic on HALs. What do you think would be the best way of implementing one? How does your OS handle it? There can be many designs; take for example Singularity which is certainly different from most OSes in this respect. What would be the best way to support as many architectures as possible?
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
[ Project UDI ]
-
- Member
- Posts: 566
- Joined: Tue Jun 20, 2006 9:17 am
Re: On Hardware Abstraction Layers
Hi,
Yup Windows has one .Contarary to popular belief ,Windows really is a portable operating system . Porting it to different architecture would mean only rewriting the HAL and some small modifications here and there .
Regards
Shrek
Yup Windows has one .Contarary to popular belief ,Windows really is a portable operating system . Porting it to different architecture would mean only rewriting the HAL and some small modifications here and there .
Regards
Shrek
Last edited by DeletedAccount on Fri Dec 12, 2008 7:17 pm, edited 2 times in total.
- Love4Boobies
- Member
- Posts: 2111
- Joined: Fri Mar 07, 2008 5:36 pm
- Location: Bucharest, Romania
Re: On Hardware Abstraction Layers
Well that's the purpose of the HAL in the first place. However, that does not answer my question I am not even sure how it is usually implemented. Is it implemented by putting architecture-specific stuff in #ifdef's? (P.S.: This probably should have been discussed in the OS Development section, but I also want you oppinions on different implementations).
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
[ Project UDI ]
-
- Member
- Posts: 566
- Joined: Tue Jun 20, 2006 9:17 am
Re: On Hardware Abstraction Layers
Hi,
HAL is usually a seperate module that rests below all the other higher level layers .It is a seperate module in itself and very much platform specific . I am not however a big fan of macros , using macros lead to hard to read code , as well as code that's difficult to debug .
Regards
Shrek
HAL is usually a seperate module that rests below all the other higher level layers .It is a seperate module in itself and very much platform specific . I am not however a big fan of macros , using macros lead to hard to read code , as well as code that's difficult to debug .
Regards
Shrek
Re: On Hardware Abstraction Layers
Hi,
Is implementing a HAL not just carefully separating interface from implementation?
(I'm probably missing something, sorry)
You can implement the separation of interface and implementation:
Is implementing a HAL not just carefully separating interface from implementation?
(I'm probably missing something, sorry)
You can implement the separation of interface and implementation:
- Via the linker: different compilation units for different platforms, each containing the same functions.
- Function pointers: adapt to changing hardware at runtime.
- Dynamic routing of messages: depending on the system state the HAL layer chooses a different implementation.
- Internal electronic auctions: probably costly, but perhaps it produces adaptive behaviour beyond that of dynamic routing.
- JIT compiling or JIT linking
- Love4Boobies
- Member
- Posts: 2111
- Joined: Fri Mar 07, 2008 5:36 pm
- Location: Bucharest, Romania
Re: On Hardware Abstraction Layers
This is pretty much the same as using #ifdef's, only you have more code to write.kasper wrote:Via the linker: different compilation units for different platforms, each containing the same functions.
This would increase the size of the binary. I can't see any reason for doing this.Function pointers: adapt to changing hardware at runtime.
I've never heard about this. I'll search it on the web. Would you like to elaborate?Dynamic routing of messages: depending on the system state the HAL layer chooses a different implementation.
The purpose of the HAL is to be a portable layer on top of hardware. It wouldn't really be a HAL if it were in hardware, would it? Besides, it wouldn't be flexibe or extensible.Internal electronic auctions: probably costly, but perhaps it produces adaptive behaviour beyond that of dynamic routing.
That's why I mentioned Singularity Still, probably Bartok has a HAL of its own (using #ifdef's). I'm not sure.JIT compiling or JIT linking
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
[ Project UDI ]
- Colonel Kernel
- Member
- Posts: 1437
- Joined: Tue Oct 17, 2006 6:06 pm
- Location: Vancouver, BC, Canada
- Contact:
Re: On Hardware Abstraction Layers
No, it's different because with the linker, different HALs can be selected at boot time, while with #ifdefs the right one must be chosen at compile time, which greatly limits its usefulness.Love4Boobies wrote:This is pretty much the same as using #ifdef's, only you have more code to write.kasper wrote:Via the linker: different compilation units for different platforms, each containing the same functions.
To clarify a bit what the Windows HAL is for: It abstracts away machine-specific detail, not just architecture-specific detail. For example, there used to be (and maybe still are) different HALs for uniprocessor and multiprocessor x86 versions of the NT kernel. The latter HAL uses the local APIC, while the former HAL (I believe) uses the old PIC instead, among other differences. I think there are even different HALs for different motherboard chipsets.
The existence of a HAL doesn't mean that the rest of the kernel outside the HAL cannot contain architecture-specific code, and that code is usually managed with #ifdefs, or different source files/make files, or some other compile-time selection mechanism.
<rant>Love4Boobies wrote:That's why I mentioned Singularity Still, probably Bartok has a HAL of its own (using #ifdef's). I'm not sure.JIT compiling or JIT linking
For the umpteenth time, Singularity does not use JIT compilation! Sorry, I just get frustrated when people repeat false information instead of going to the authoritative source.
</rant>
I don't recall if Singularity has a separate HAL either... It's quite architecture and machine specific I believe, since it is just a research OS and was not designed to be portable. There is no reason in principle why it couldn't be designed that way, but if it were it would work in a similar manner to Windows, since the compiled Singularity kernel is just native code and doesn't use any JIT compilation tricks.
Top three reasons why my OS project died:
- Too much overtime at work
- Got married
- My brain got stuck in an infinite loop while trying to design the memory manager
- Combuster
- 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: On Hardware Abstraction Layers
If you use C++, you'd have classes, vTables, and most of the appropriate function calls would be done via a pointer alreadyLove4Boobies wrote:This would increase the size of the binary. I can't see any reason for doing this.Function pointers: adapt to changing hardware at runtime.
Think microkernel, message passing, ...I've never heard about this. I'll search it on the web. Would you like to elaborate?Dynamic routing of messages: depending on the system state the HAL layer chooses a different implementation.
-
- Member
- Posts: 524
- Joined: Sun Nov 09, 2008 2:55 am
- Location: Pennsylvania, USA
Re: On Hardware Abstraction Layers
For loading modules in general (it would work with a HAL, but I personally don't use one) I use an initialization function in the module. All the kernel does is call the entry point in the module's file (designated in the module's ELF header) with a pointer to a table as the only argument. The table contains a list of all the functions that the module needs to use. As long as the module is compiled as position independent code, this works just fine. Position independent code can reduce performance, but my OS runs on x86_64 (where RIP relative addressing reduces the performance impact of position independent code). You might want to load your HAL at a specified address, so it doesn't need to be position independent.
Re: On Hardware Abstraction Layers
Hi all,
We could use auctions in a more wider setting. For example on mainframes and in distributed computing auctions can divide computing power among tasks. For the HAL the auctioned tasks or resources are more diverse than just computing power: they would include displaying graphics to the end user, storing data, etc.
But this is a different level than (JIT) linking, ifdefs, JIT compiling, etc. It can come on top of dynamic message routing, which I mentioned before.
Kasper
I didn't mean in hardware. Probably the word "electronic" put you of. I used electronic auctions to contrast them with regular auctions, like those at Sotheby's. An example of electronic auctions are those at eBay. (A habit useful in the context of AI, but redundant in OS dev since everything is electronic )Love4Boobies wrote:The purpose of the HAL is to be a portable layer on top of hardware. It wouldn't really be a HAL if it were in hardware, would it? Besides, it wouldn't be flexibe or extensible.kasper wrote: Internal electronic auctions: probably costly, but perhaps it produces adaptive behaviour beyond that of dynamic routing.
We could use auctions in a more wider setting. For example on mainframes and in distributed computing auctions can divide computing power among tasks. For the HAL the auctioned tasks or resources are more diverse than just computing power: they would include displaying graphics to the end user, storing data, etc.
But this is a different level than (JIT) linking, ifdefs, JIT compiling, etc. It can come on top of dynamic message routing, which I mentioned before.
Kasper
- Love4Boobies
- Member
- Posts: 2111
- Joined: Fri Mar 07, 2008 5:36 pm
- Location: Bucharest, Romania
Re: On Hardware Abstraction Layers
Would a compiler (properly) supporting SEH make it possible to NOT include interrupt support in the HAL?
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
[ Project UDI ]
- Colonel Kernel
- Member
- Posts: 1437
- Joined: Tue Oct 17, 2006 6:06 pm
- Location: Vancouver, BC, Canada
- Contact:
Re: On Hardware Abstraction Layers
I don't see how, given that SEH is about exceptions, not interrupts, and therefore has nothing to do with the PIC or APIC. Managing the PIC/APIC is one of the primary responsibilities of the HAL.Love4Boobies wrote:Would a compiler (properly) supporting SEH make it possible to NOT include interrupt support in the HAL?
Top three reasons why my OS project died:
- Too much overtime at work
- Got married
- My brain got stuck in an infinite loop while trying to design the memory manager
- Troy Martin
- Member
- Posts: 1686
- Joined: Fri Apr 18, 2008 4:40 pm
- Location: Langley, Vancouver, BC, Canada
- Contact:
Re: On Hardware Abstraction Layers
*cough*illegal*cough*
I'd go with ReactOS instead of hacking code out of Windoze.
I'd go with ReactOS instead of hacking code out of Windoze.