Make it possible to include emu/jit.h in the kernel

This commit is contained in:
Theodore Dubois
2020-07-26 00:05:49 -07:00
parent 9bc2afb30e
commit 093041a882
10 changed files with 77 additions and 64 deletions
+40 -40
View File
@@ -69,19 +69,19 @@ struct cpu_state {
union {
dword_t eflags;
struct {
bits cf_bit:1;
bits pad1_1:1;
bits pf:1;
bits pad2_0:1;
bits af:1;
bits pad3_0:1;
bits zf:1;
bits sf:1;
bits tf:1;
bits if_:1;
bits df:1;
bits of_bit:1;
bits iopl:2;
bitfield cf_bit:1;
bitfield pad1_1:1;
bitfield pf:1;
bitfield pad2_0:1;
bitfield af:1;
bitfield pad3_0:1;
bitfield zf:1;
bitfield sf:1;
bitfield tf:1;
bitfield if_:1;
bitfield df:1;
bitfield of_bit:1;
bitfield iopl:2;
};
// for asm
#define PF_FLAG (1 << 2)
@@ -100,10 +100,10 @@ struct cpu_state {
dword_t res, op1, op2;
union {
struct {
bits pf_res:1;
bits zf_res:1;
bits sf_res:1;
bits af_ops:1;
bitfield pf_res:1;
bitfield zf_res:1;
bitfield sf_res:1;
bitfield af_ops:1;
};
// for asm
#define PF_RES (1 << 0)
@@ -121,35 +121,35 @@ struct cpu_state {
union {
word_t fsw;
struct {
bits ie:1; // invalid operation
bits de:1; // denormalized operand
bits ze:1; // divide by zero
bits oe:1; // overflow
bits ue:1; // underflow
bits pe:1; // precision
bits stf:1; // stack fault
bits es:1; // exception status
bits c0:1;
bits c1:1;
bits c2:1;
bitfield ie:1; // invalid operation
bitfield de:1; // denormalized operand
bitfield ze:1; // divide by zero
bitfield oe:1; // overflow
bitfield ue:1; // underflow
bitfield pe:1; // precision
bitfield stf:1; // stack fault
bitfield es:1; // exception status
bitfield c0:1;
bitfield c1:1;
bitfield c2:1;
unsigned top:3;
bits c3:1;
bits b:1; // fpu busy (?)
bitfield c3:1;
bitfield b:1; // fpu busy (?)
};
};
union {
word_t fcw;
struct {
bits im:1;
bits dm:1;
bits zm:1;
bits om:1;
bits um:1;
bits pm:1;
bits pad4:2;
bits pc:2;
bits rc:2;
bits y:1;
bitfield im:1;
bitfield dm:1;
bitfield zm:1;
bitfield om:1;
bitfield um:1;
bitfield pm:1;
bitfield pad4:2;
bitfield pc:2;
bitfield rc:2;
bitfield y:1;
};
};
+1 -2
View File
@@ -1,8 +1,7 @@
#ifndef FLOAT80_H
#define FLOAT80_H
#include <stdint.h>
#include <stdbool.h>
#include "misc.h"
typedef struct {
uint64_t signif;
+2
View File
@@ -7,6 +7,7 @@
typedef dword_t page_t;
#define BAD_PAGE 0x10000
#ifndef __KERNEL__
#define PAGE_BITS 12
#undef PAGE_SIZE // defined in system headers somewhere
#define PAGE_SIZE (1 << PAGE_BITS)
@@ -15,6 +16,7 @@ typedef dword_t page_t;
typedef dword_t pages_t;
// bytes MUST be unsigned if you would like this to overflow to zero
#define PAGE_ROUND_UP(bytes) (PAGE((bytes) + PAGE_SIZE - 1))
#endif
struct mmu {
struct mmu_ops *ops;
+1 -1
View File
@@ -1,7 +1,7 @@
#ifndef JIT_H
#define JIT_H
#include "misc.h"
#include "emu/memory.h"
#include "emu/mmu.h"
#include "util/list.h"
#include "util/sync.h"
+2
View File
@@ -1,3 +1,5 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "kernel/elf.h"
#include "kernel/vdso.h"
+18 -11
View File
@@ -1,13 +1,14 @@
#ifndef MISC_H
#define MISC_H
#ifndef __KERNEL__
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdnoreturn.h>
#include <sys/types.h>
#include <stdnoreturn.h>
#include <stdbool.h>
#endif
#include <stdint.h>
// utility macros
#define glue(a, b) _glue(a, b)
@@ -18,9 +19,6 @@
#define str(x) _str(x)
#define _str(x) #x
#define container_of(ptr, type, member) \
((type *) ((char *) (ptr) - offsetof(type, member)))
// compiler check
#define is_gcc(version) (__GNUC__ >= version)
@@ -37,22 +35,27 @@
#endif
// keywords
#define bits unsigned int
#define bitfield unsigned int
#define forceinline inline __attribute__((always_inline))
#define flatten __attribute__((flatten))
#ifdef NDEBUG
#if defined(NDEBUG) || defined(__KERNEL__)
#define posit __builtin_assume
#else
#define posit assert
#endif
#define must_check __attribute__((warn_unused_result))
#ifndef __KERNEL__
#define unlikely(x) __builtin_expect((x), 0)
#define typecheck(type, x) ({type _x = x; x;})
#define must_check __attribute__((warn_unused_result))
#define container_of(ptr, type, member) \
((type *) ((char *) (ptr) - offsetof(type, member)))
#if has_attribute(fallthrough)
#define fallthrough __attribute__((fallthrough))
#else
#define fallthrough
#endif
#endif
#if has_attribute(no_sanitize)
#define __no_instrument_msan
@@ -94,7 +97,9 @@ static inline void __use(int dummy __attribute__((unused)), ...) {}
})
#endif
#ifndef __KERNEL__
#define array_size(arr) (sizeof(arr)/sizeof((arr)[0]))
#endif
// types
typedef int64_t sqword_t;
@@ -118,8 +123,10 @@ typedef dword_t clock_t_;
#define uint(size) glue3(uint,size,_t)
#define sint(size) glue3(int,size,_t)
#ifndef __KERNEL__
#define ERR_PTR(err) (void *) (intptr_t) (err)
#define PTR_ERR(ptr) (intptr_t) (ptr)
#define IS_ERR(ptr) ((uintptr_t) (ptr) > (uintptr_t) -0xfff)
#endif
#endif
+1
View File
@@ -1,4 +1,5 @@
#define _GNU_SOURCE
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
+8 -8
View File
@@ -387,15 +387,15 @@ struct gdt_entry {
uint16_t limit0;
uint16_t base0;
uint8_t base1;
bits type:4;
bits system:1;
bits dpl:2;
bits present:1;
bitfield type:4;
bitfield system:1;
bitfield dpl:2;
bitfield present:1;
unsigned limit1:4;
bits avail:1;
bits is_64_code:1;
bits db:1;
bits granularity:1;
bitfield avail:1;
bitfield is_64_code:1;
bitfield db:1;
bitfield granularity:1;
uint8_t base2;
} __attribute__((packed));
+4 -1
View File
@@ -1,7 +1,6 @@
#ifndef LIST_H
#define LIST_H
#include <unistd.h>
#include <stdbool.h>
#include <stddef.h>
@@ -9,6 +8,8 @@ struct list {
struct list *next, *prev;
};
#ifndef __KERNEL__
static inline void list_init(struct list *list) {
list->next = list;
list->prev = list;
@@ -96,3 +97,5 @@ static inline unsigned long list_size(struct list *list) {
}
#endif
#endif
-1
View File
@@ -1,7 +1,6 @@
#ifndef UTIL_SYNC_H
#define UTIL_SYNC_H
#include <errno.h>
#include <stdatomic.h>
#include <pthread.h>
#include <stdbool.h>