16-bit code and L4

Valery V. Sedletski _valerius at mail.ru
Wed Jun 20 12:27:32 CEST 2007

Would be someone so kind to answer some questions? These questions are about 16-bit instructions execution on intel 
processors in L4 usermode programs. First, excuse me for my bad English (it is not native for me).

And first I'll try to explain the motivation. -- I am now trying to contribute to the project aiming to create an Opensource OS/2 
clone. (osFree aka OS/3 project, http://www.osfree.org/) The goal now is to create OS/2 API implementation with binary 
compatibility with existing OS/2 (intel) applications. Also,  it would be desirable to reuse existing OS/2 device driver base (if it is 
possible). We are planning to use L4 as a base for API implementation.

The problem with existing OS/2 applications is that they are not pure 32-bit; there are many common 16-bit API's now (they are 
to be replaced with 32-bit analogues in new implementation); almost each LX format executable contains 16-bit fragments 
(thunks for calling 16-bit API's), though the most of each executable is 32-bit and uses 32-bit flat memory model. Also, most old 
OS/2 device drivers are 16-bit, they are still very common now (but newer drivers are 32-bit). Another problem is that many 
drivers and applications are available in binary-only form (so, they cannot be recompiled, as with Linux) 32-bit applications and 
drivers support can be made, for example, by implementing a converter of LX-executables to pure 32-bits. Also, 16-bit 
fragments can be executed in a virtual machine. Or, as another variant, it may be possible to execute these 16-bit parts on a 
real processor. The problem is only how to maintain correct segment registers values and how to add a 16-bit segment 
descriptor to GDT or LDT. 

The problem with L4 is that it doesn't expose segmentation to outside the kernel, it abstracts segmentation from usermode 
programs and only allows to use paging, but not segmentation. The reason is known: segmentation is not portable, it has no 
analogues on other architectures than intel one.

So, the questions are:

1) There is L4Linux. It is mostly 32-bit. But as I know, the Linux kernel also contains some 16-bit parts, such as setup code (it 
works with BIOS routines and probes hardware), and also (as I heard) acpi suspend/wakeup code. So, it contains 16-bit 
segments. But doesn't it interfere with L4? How did the people porting Linux to the L4 microkernel solve the problem of 16-bit 
code? And doesn't it interfere with ELF format capabilities (it is pure 32/64-bit, as I understand)?

2) Must all the segment registers be CS == DS == ES == FS == GS == SS == FLAT in L4 usermode programs (in Intel 
architecture implementation)? Or, there exist a possibility to use segments other than FLAT?

3) Is it possible to cause the L4 kernel to create 16-bit segment descriptor on Intel architecture?

More information about the l4-hackers mailing list