User:Iguessthislldo/libx86emu: Difference between revisions

From OSDev.wiki
Jump to navigation Jump to search
Content added Content deleted
No edit summary
(Dependencies)
Line 1: Line 1:
{{Rating|3}}
'''libx86emu''' is a compact C library for emulating a [[real mode]] or limited [[protected mode]] [[x86]] CPU. Like [[Virtual 8086 Mode]], it can be used to call [[BIOS]] functions from protected modes. Unlike virutal 8086 mode, it can be used directly in [[x86-64|long mode]]. It was created by the SciTech Software Inc. in the 1990's. It was integrated into XFree86, which was forked to create X.org, where it's used to access the [[VBE]] BIOS interrupts.


'''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 directly 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, although it does require writing some support functions. 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 [https://github.com/wfeldt/libx86emu a separate fork on GitHub that is maintained as part of OpenSUSE Linux].

=== Building ===

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

==== Dependencies ====

The following C headers and functions are required to build:

* <code>stdio.h</code>
** Can include the <code>stddef.h</code> freestanding header to get <code>size_t</code>.
** <code>int vsnprintf(char* buffer, size_t bufsz, const char* format, va_list vlist</code>
*** This can be a stub implementation, but could be useful depending on what you want the library to log.

'''TODO: stdlib should be freestanding?'''

* <code>stdlib.h</code>
** Can include the <code>stddef.h</code> freestanding header to get <code>NULL</code> and <code>size_t</code>.
** <code>void* malloc(size_t size)</code>
** <code>void* calloc(size_t num, size_t size)</code>
** <code>void free(void* ptr)</code>

* <code>string.h</code>
** <code>char* strcat(char* dest, const char* src);</code>
*** This can be a stub implementation, but could be useful depending on what you want the library to log.

* <code>sys</code>
** <code>io.h</code>
*** These could be stubs depending on how you want to have the emulation perform port I/O.
*** <code>unsigned char inb(unsigned short int port)</code>
*** <code>unsigned short int inw(unsigned short int port)</code>
*** <code>unsigned int inl(unsigned short int port)</code>
*** <code>void outb(unsigned char value, unsigned short int port)</code>
*** <code>void outw(unsigned short int value, unsigned short int port)</code>
*** <code>void outl(unsigned int value, unsigned short int port)</code>

* <code>time.h</code>
** <code>time_t</code>
** <code>time_t time(time_t* arg)</code>
*** Can be a stub. Only used if you want to put a timeout on the emulation run using the <code>X86EMU_RUN_TIMEOUT</code> flag.


=== Example Usage ===

'''TODO'''


=== External Links ===
=== 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]

Revision as of 23:44, 5 May 2021

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 directly 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, although it does require writing some support functions. 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.

Building

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

Dependencies

The following C headers and functions 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 could be useful depending on what you want the library to log.

TODO: stdlib should be freestanding?

  • 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 could be useful depending on what you want the library to log.
  • sys
    • io.h
      • These could be stubs depending on how you want to have the emulation 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)
      • Can be a stub. Only used if you want to put a timeout on the emulation run using the X86EMU_RUN_TIMEOUT flag.


Example Usage

TODO

External Links