1
0
Fork 0
mirror of https://github.com/tailix/libkernaux.git synced 2024-11-20 11:06:41 -05:00

Add i386 stuff (#116)

* Add struct KernAux_Arch_I386_IDTE
* Add struct KernAux_Arch_I386_DTR
* Remove unnecessary static check
* Add func KernAux_Arch_I386_IDTE_set_offset
This commit is contained in:
Alex Kotov 2022-11-28 15:00:34 +04:00 committed by GitHub
parent 91bce08aa3
commit 971b2f4803
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 81 additions and 3 deletions

1
.gitignore vendored
View file

@ -126,6 +126,7 @@
/tests/multiboot2_header_print2
/tests/multiboot2_info_print1
/tests/multiboot2_info_print2
/tests/test_arch_i386
/tests/test_cmdline
/tests/test_cmdline_gen
/tests/test_cmdline_gen.c

View file

@ -53,6 +53,16 @@ extern "C" {
#include <kernaux/macro/packing_start.run>
// Global, local or interrupt descriptor table register
// TODO: validate this according to spec
struct KernAux_Arch_I386_DTR {
uint16_t size;
uint32_t offset;
}
KERNAUX_PACKING_ATTR;
KERNAUX_STATIC_TEST_STRUCT_SIZE(KernAux_Arch_I386_DTR, 6);
// Global or local descriptor table entry
// TODO: validate this according to spec
struct KernAux_Arch_I386_DTE {
@ -74,8 +84,25 @@ struct KernAux_Arch_I386_DTE {
}
KERNAUX_PACKING_ATTR;
// Interrupt descriptor table entry
// TODO: validate this according to spec
typedef struct KernAux_Arch_I386_IDTE {
uint16_t offset_low;
uint16_t selector;
uint8_t _zero0;
uint8_t flags;
uint16_t offset_high;
}
KERNAUX_PACKING_ATTR
*KernAux_Arch_I386_IDTE;
KERNAUX_STATIC_TEST_STRUCT_SIZE(KernAux_Arch_I386_DTE, 8);
void KernAux_Arch_I386_IDTE_set_offset(
KernAux_Arch_I386_IDTE idte,
uint32_t address
);
/**
* @brief Task state segment
* @see The manual, page 132, figure 7-1

View file

@ -4,6 +4,11 @@
#include <kernaux/arch/i386.h>
__attribute__((unused))
static const int
TSS_validation[sizeof(struct KernAux_Arch_I386_TSS) == 104 ? 1 : -1];
void KernAux_Arch_I386_IDTE_set_offset(
const KernAux_Arch_I386_IDTE idte,
const uint32_t address
)
{
idte->offset_low = 0xFFFF & address;
idte->offset_high = 0xFFFF & (address >> 16);
}

View file

@ -56,6 +56,18 @@ multiboot2_info_print2_SOURCES = \
multiboot2_info_example2.h
endif
##################
# test_arch_i386 #
##################
if WITH_ARCH_I386
TESTS += test_arch_i386
test_arch_i386_LDADD = $(top_builddir)/libkernaux.la
test_arch_i386_SOURCES = \
main.c \
test_arch_i386.c
endif
################
# test_cmdline #
################

33
tests/test_arch_i386.c Normal file
View file

@ -0,0 +1,33 @@
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <kernaux/arch/i386.h>
#include <assert.h>
#include <string.h>
static void test_idte_set_offset();
void test_main()
{
test_idte_set_offset();
}
void test_idte_set_offset()
{
struct KernAux_Arch_I386_IDTE idte;
memset(&idte, 0, sizeof(idte));
KernAux_Arch_I386_IDTE_set_offset(&idte, 0);
assert(idte.offset_high == 0);
assert(idte.offset_low == 0);
KernAux_Arch_I386_IDTE_set_offset(&idte, 0xFFFFFFFF);
assert(idte.offset_high == 0xFFFF);
assert(idte.offset_low == 0xFFFF);
KernAux_Arch_I386_IDTE_set_offset(&idte, 0x12345678);
assert(idte.offset_high == 0x1234);
assert(idte.offset_low == 0x5678);
}