User:Iguessthislldo/libx86emu: Difference between revisions

From OSDev.wiki
Jump to navigation Jump to search
Content added Content deleted
No edit summary
 
(5 intermediate revisions by one other user not shown)
Line 1: Line 1:
{{Rating|3}}
{{Rating|3|}}


'''libx86emu''' is a C library for emulating a [[real mode]] or a limited [[protected mode]] [[x86]] CPU. Like [[Virtual 8086 Mode]], it can be used to call [[BIOS]] functions, such as the ones for using [[VBE]], without dropping back into real mode. Unlike virtual 8086 mode though, it can be used in protected mode and [[x86-64|long mode]]. It might also be preferred because it doesn't require as much low level integration with the OS as the virtual 8086 mode does. It was created by the [[wikipedia:SciTech Software|SciTech Software Inc.]] in the 1990's. It was integrated into the XFree86 server, which was later forked to create the X.org server. In addition to the fork that still exists in X.org, there is [https://github.com/wfeldt/libx86emu a separate fork on GitHub that is maintained as part of OpenSUSE Linux].
'''libx86emu''' is a C library for emulating a [[real mode]] or a limited [[protected mode]] [[x86]] CPU. Like [[Virtual 8086 Mode]], it can be used to call [[BIOS]] functions, such as the ones for using [[VBE]], without dropping back into real mode. Unlike virtual 8086 mode though, it can be used in protected mode and [[x86-64|long mode]]. It might also be preferred because it doesn't require as much low level integration with the OS as the virtual 8086 mode does. It was created by the [[wikipedia:SciTech Software|SciTech Software Inc.]] in the 1990's. It was integrated into the [[wikipedia:XFree86|XFree86 server]], which was later forked to create the [[wikipedia:X.org server|X.org server]]. In addition to [https://cgit.freedesktop.org/xorg/xserver/tree/hw/xfree86/x86emu the fork that still exists in X.org], there is [https://github.com/wfeldt/libx86emu a separate fork on GitHub] that is maintained as part of OpenSUSE Linux.


While it's possible to use the libx86emu found in X.org, this article will assume the OpenSUSE fork is being used, specifically version 3.1. It will also assume the library is going to be integrated into the kernel and the source code of the library isn't going to be modified.
While it's possible to use the libx86emu found in X.org, this article will assume the OpenSUSE fork is being used, specifically version 3.1. It will also assume the library is going to be integrated into the kernel and the source code of the library isn't going to be modified.


=== Dependencies ===
== Dependencies ==


The following C headers and definitions are required to build:
The following C headers and definitions are required to build:
Line 39: Line 39:
*** This can be a stub implementation, only needed to use the <code>X86EMU_RUN_TIMEOUT</code> flag to limit the time a emulation runs.
*** This can be a stub implementation, only needed to use the <code>X86EMU_RUN_TIMEOUT</code> flag to limit the time a emulation runs.


=== Building ===
== Building ==


All the C files in the root of the source tree are part of the library and should be built together with the headers outlined above. One thing to note is that the undefined behavior sanitizer (UBsan), which is the <code>-fsanitize=undefined</code> option in Clang and GCC, should be not be used for libx86emu because some of the emulated instructions might set it off during execution.
All the C files in the root of the source tree are part of the library and should be built together with the headers outlined above. One thing to note is that the undefined behavior sanitizer (UBsan), which is the <code>-fsanitize=undefined</code> option in Clang and GCC, should be not be used with libx86emu because some of the emulated instructions might set it off during execution.


==== Building with the Zig Build System ====
=== Building with the Zig Build System ===


If using the Zig build system to build the library, it always passes <code>-fsanitize=undefined</code> for C code in a debug mode, so it will need to be disabled. It can be disabled using by passing <code>-fsanitize-blacklist=BLACKLIST_FILE</code>, where <code>BLACKLIST_FILE</code> is a path to a file relative to the Zig build file. This file should contain:
If using the Zig build system to build the library, it always passes <code>-fsanitize=undefined</code> for C code in a debug mode, so it will need to be disabled. It can be disabled by passing <code>-fsanitize-blacklist=BLACKLIST_FILE</code> to the C compile options, where <code>BLACKLIST_FILE</code> is a path to a file relative to the Zig build file. This file should contain something like:


[undefined]
[undefined]
Line 52: Line 52:
This assumes the C files are in a directory called <code>libx86emu</code>.
This assumes the C files are in a directory called <code>libx86emu</code>.


=== Example Usage ===
== Example Usage ==


'''TODO'''
'''TODO'''


=== External Links ===
== Also See ==


=== Forum Posts ===
* [https://forum.osdev.org/viewtopic.php?f=1&t=31388 Question about libx86emu]

=== External Links ===
* [https://github.com/wfeldt/libx86emu libx86emu on GitHub]
* [https://github.com/wfeldt/libx86emu libx86emu on GitHub]
* [https://cgit.freedesktop.org/xorg/xserver/tree/hw/xfree86/x86emu libx86emu in X.org server]
* [https://cgit.freedesktop.org/xorg/xserver/tree/hw/xfree86/x86emu libx86emu in X.org server]

[[Category:User drafts]]

Latest revision as of 20:18, 16 June 2024

Difficulty level

Advanced

libx86emu is a C library for emulating a real mode or a limited protected mode x86 CPU. Like Virtual 8086 Mode, it can be used to call BIOS functions, such as the ones for using VBE, without dropping back into real mode. Unlike virtual 8086 mode though, it can be used in protected mode and long mode. It might also be preferred because it doesn't require as much low level integration with the OS as the virtual 8086 mode does. It was created by the SciTech Software Inc. in the 1990's. It was integrated into the XFree86 server, which was later forked to create the X.org server. In addition to the fork that still exists in X.org, there is a separate fork on GitHub that is maintained as part of OpenSUSE Linux.

While it's possible to use the libx86emu found in X.org, this article will assume the OpenSUSE fork is being used, specifically version 3.1. It will also assume the library is going to be integrated into the kernel and the source code of the library isn't going to be modified.

Dependencies

The following C headers and definitions are required to build:

  • stdio.h
    • Can include the stddef.h freestanding header to get size_t.
    • int vsnprintf(char* buffer, size_t bufsz, const char* format, va_list vlist
      • This can be a stub implementation, but is needed for logging to be fully functional.
  • stdlib.h
    • Can include the stddef.h freestanding header to get NULL and size_t.
    • void* malloc(size_t size)
    • void* calloc(size_t num, size_t size)
    • void free(void* ptr)
  • string.h
    • char* strcat(char* dest, const char* src);
      • This can be a stub implementation, but is needed for logging to be fully functional.
  • sys
    • io.h
      • These could be stubs depending on how emulation is setup to perform port I/O.
      • unsigned char inb(unsigned short int port)
      • unsigned short int inw(unsigned short int port)
      • unsigned int inl(unsigned short int port)
      • void outb(unsigned char value, unsigned short int port)
      • void outw(unsigned short int value, unsigned short int port)
      • void outl(unsigned int value, unsigned short int port)
  • time.h
    • time_t
    • time_t time(time_t* arg)
      • This can be a stub implementation, only needed to use the X86EMU_RUN_TIMEOUT flag to limit the time a emulation runs.

Building

All the C files in the root of the source tree are part of the library and should be built together with the headers outlined above. One thing to note is that the undefined behavior sanitizer (UBsan), which is the -fsanitize=undefined option in Clang and GCC, should be not be used with libx86emu because some of the emulated instructions might set it off during execution.

Building with the Zig Build System

If using the Zig build system to build the library, it always passes -fsanitize=undefined for C code in a debug mode, so it will need to be disabled. It can be disabled by passing -fsanitize-blacklist=BLACKLIST_FILE to the C compile options, where BLACKLIST_FILE is a path to a file relative to the Zig build file. This file should contain something like:

 [undefined]
 src:*/libx86emu/*

This assumes the C files are in a directory called libx86emu.

Example Usage

TODO

Also See

Forum Posts

External Links