Syscalls
Re:Syscalls
Well, you can rise IOPL to any of these privilege levels, so you could put IO driver code into these rings. The main use for these PLs is, AFAIK, that they can freely access any data segments with higher PL (higher value, lower privilege, I mean), so a disk driver in ring2 could write directly into a buffer in a ring3 data segment, that was provided by an application.
But when you use the flat address space model (and thus overlapping segments), the benefit of ring1 and ring2 tends to zero, that's probably why these PLs are typically not used anymore.
cheers Joe
But when you use the flat address space model (and thus overlapping segments), the benefit of ring1 and ring2 tends to zero, that's probably why these PLs are typically not used anymore.
cheers Joe
Re:Syscalls
Yes, but disregarding which privilege level I put IOPL in, what's the actual difference between the two?
Re:Syscalls
Hi,
For example, you could have the kernel at CPL=0, device drivers at CPL=1, services at CPL=2 and applications at CPL=3. Then, device drivers would be able to access segments used for services, but services wouldn't be able to access segments used for device drivers.
Apart from this (and IOPL) there is no difference between CPL=1, CPL=2 and CPL=3. There are some instructions that can only be used at CPL=0 which makes it a little different.
Cheers,
Brendan
AFAIK it's mostly for systems that use segmentation fully (perhaps without paging).Crazed123 wrote:Yes, but disregarding which privilege level I put IOPL in, what's the actual difference between the two?
For example, you could have the kernel at CPL=0, device drivers at CPL=1, services at CPL=2 and applications at CPL=3. Then, device drivers would be able to access segments used for services, but services wouldn't be able to access segments used for device drivers.
Apart from this (and IOPL) there is no difference between CPL=1, CPL=2 and CPL=3. There are some instructions that can only be used at CPL=0 which makes it a little different.
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Re:Syscalls
One more question, since I don't have processor docs for non IA-32s: Do those other architectures have an equivalent to designating a process ring 1 or 2 and setting IOPL there, thus allowing device drivers to be run outside Pure Kernel Mode without giving I/O access to user programs?
Thanks a ton.
Thanks a ton.
Re:Syscalls
I don't know of any, at least
In general, using segmented memory has become quite out of fashion. And I don't mean that just the people don't use it much - also the CPU designers did not enhance the segmentation hardware much in today's processors (P IV, Athlon64). I remember there were rumours (or even facts?) that using non-flat segments today generates quite a lot of overhead, at least.
cheers Joe
- Alpha
- PowerPC
- ARM
- StrongARM
- IA64
In general, using segmented memory has become quite out of fashion. And I don't mean that just the people don't use it much - also the CPU designers did not enhance the segmentation hardware much in today's processors (P IV, Athlon64). I remember there were rumours (or even facts?) that using non-flat segments today generates quite a lot of overhead, at least.
Eh, I suspect you left my previous post half-read, have you?Yes, but disregarding which privilege level I put IOPL in, what's the actual difference between the two?
cheers Joe
Re:Syscalls
Actually, I read it. I just wanted to know the technical difference between the two rather than the benefits of using them.
Hmmm... so I guess non-IA-32s only have userspace and kernelspace. Drat, I was going to create a seperate protection level to put device drivers in.
Hmmm... so I guess non-IA-32s only have userspace and kernelspace. Drat, I was going to create a seperate protection level to put device drivers in.
Re:Syscalls
AMD64s in 64-bit mode (not compatibility mode) force a flat memory space and don't allow different bases or limits for CS and DS (ES, FS and GS may be changed for special uses), so it seems it's going quite out of fashion.In general, using segmented memory has become quite out of fashion. And I don't mean that just the people don't use it much - also the CPU designers did not enhance the segmentation hardware much in today's processors (P IV, Athlon64). I remember there were rumours (or even facts?) that using non-flat segments today generates quite a lot of overhead, at least
- Colonel Kernel
- Member
- Posts: 1437
- Joined: Tue Oct 17, 2006 6:06 pm
- Location: Vancouver, BC, Canada
- Contact:
Re:Syscalls
For the most part, yes. Although I remember reading up on MIPS, and being surprised to discover that it has three modes (user, kernel, and supervisor). In general, you can't assume more than two modes if you want your OS to be portable to other architectures.Crazed123 wrote: Hmmm... so I guess non-IA-32s only have userspace and kernelspace.
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
Re:Syscalls
Hmph. So do other processes at least have a way to simulate the extra protection level by designating some user processes able to do I/O but not others?
I would really look it up myself, but I don't have the docs and don't want to go hunting down processor docs for every processor I'm not using so far.
I would really look it up myself, but I don't have the docs and don't want to go hunting down processor docs for every processor I'm not using so far.
- Colonel Kernel
- Member
- Posts: 1437
- Joined: Tue Oct 17, 2006 6:06 pm
- Location: Vancouver, BC, Canada
- Contact:
Re:Syscalls
IA32 is one of the few architectures that has a separate I/O space. Most other architectures use memory-mapped I/O exclusively, which means you can control access to devices with the MMU. If you were to implement drivers in user-mode, the kernel could grant a driver appropriate access to its device's memory-mapped registers.Crazed123 wrote: Hmph. So do other processes at least have a way to simulate the extra protection level by designating some user processes able to do I/O but not others?
I would really look it up myself, but I don't have the docs and don't want to go hunting down processor docs for every processor I'm not using so far.
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
Re:Syscalls
Yes I am. How can I link against the kernel? I'd be very interested how this would work, so that I can dynamically load ocaml programs at runtime =)AR wrote: @purevoid: You're writing your OS in OCaml, all in kernel mode, right? In this case you can just directly link against the kernel, no need to worry about gates since you have no protection rings.
Re:Syscalls
The ELF Spec includes documentation on how to implement dynamic linkers, basically you'll just need to export symbols from the kernel and have the dynamic linker bind the symbols to the programs at runtime.
I'm not sure whether exporting symbols from an executable image (kernel) works properly, but it should hopefully. Basically the kernel will be just acting like a DLL.
I'm not sure whether exporting symbols from an executable image (kernel) works properly, but it should hopefully. Basically the kernel will be just acting like a DLL.
Re:Syscalls
According to ELF it will work, it just isn't used on any current systems.
ColonelKernel: Thanks, that makes everything exactly as portable as I want it to be.
ColonelKernel: Thanks, that makes everything exactly as portable as I want it to be.
Re:Syscalls
Any tips on how to export the symbols correctly? I was told they have to show up in .dynsyms section of my ELF file.
Re:Syscalls
Good question. Shouldn't it work just to export them like you would from a normal program, thus making them show up in the exported symbol tables?