]> 4ch.mooo.com Git - 16.git/blob - src/lib/doslib/hw/cpu/gdt_enum.h
added a bunch of things~ and midi stuff~
[16.git] / src / lib / doslib / hw / cpu / gdt_enum.h
1 /* gdt_enum.h
2  *
3  * Library for reading the Global Descriptor Table if possible.
4  * (C) 2009-2012 Jonathan Campbell.
5  * Hackipedia DOS library.
6  *
7  * This code is licensed under the LGPL.
8  * <insert LGPL legal text here>
9  *
10  * Compiles for intended target environments:
11  *   - MS-DOS
12  *   - Windows 3.0/3.1/95/98/ME
13  *   - Windows NT 3.1/3.51/4.0/2000/XP/Vista/7
14  *   - OS/2 16-bit
15  *   - OS/2 32-bit
16  *
17  */
18
19 #include <stdio.h>
20 #include <conio.h> /* this is where Open Watcom hides the outp() etc. functions */
21 #include <stdlib.h>
22 #include <unistd.h>
23 #include <assert.h>
24 #include <string.h>
25 #include <fcntl.h>
26 #include <dos.h>
27
28 #include <hw/cpu/cpu.h>
29 #include <hw/dos/dos.h>
30
31 #pragma pack(push,1)
32 struct x86_gdtr {
33         uint16_t        limit;
34         uint32_t        base;
35         uint16_t        pad;
36 };
37 #pragma pack(pop)
38
39 #pragma pack(push,1)
40 struct cpu_gdtlib_entry {
41         uint32_t        limit;
42         uint32_t        base;
43         uint8_t         access,granularity;
44 };
45 #pragma pack(pop)
46
47 extern unsigned char                    cpu_gdtlib_can_read,cpu_gdtlib_can_write,cpu_gdtlib_result;
48 extern uint16_t                         cpu_gdtlib_ldtr;
49 extern struct x86_gdtr                  cpu_gdtlib_gdtr;
50 extern struct cpu_gdtlib_entry          cpu_gdtlib_ldt_ent;
51 #if TARGET_MSDOS == 16 && defined(TARGET_WINDOWS)
52 extern uint16_t                         cpu_gdtlib_gdt_sel;     /* selector for reading GDT table */
53 extern uint16_t                         cpu_gdtlib_ldt_sel;     /* selector for reading LDT table */
54 #endif
55
56 /* HACK: Win32 builds must be careful. Windows 9x/ME sets the flat selector as base == 0 limit = 0xFFFFFFFF while
57  *       Windows 3.1 Win32s sets base = 0xFFFF0000 limit = 0xFFFFFFFF for whatever weird reason. */
58 #if TARGET_MSDOS == 32 && defined(TARGET_WINDOWS)
59 extern uint32_t                         cpu_gdtlib_lin_bias;
60 #else
61 # define cpu_gdtlib_lin_bias (0UL)
62 #endif
63
64 #define cpu_gdtlib_empty_ldt_entry      cpu_gdtlib_empty_gdt_entry
65
66 unsigned int cpu_gdtlib_gdt_entries(struct x86_gdtr *r);
67 unsigned int cpu_gdtlib_ldt_entries(struct cpu_gdtlib_entry *r);
68 int cpu_gdtlib_read_ldtr(uint16_t *sel);
69 int cpu_gdtlib_read_gdtr(struct x86_gdtr *raw);
70 int cpu_gdtlib_init();
71 void cpu_gdtlib_free();
72 int cpu_gdtlib_ldt_read_entry(struct cpu_gdtlib_entry *e,unsigned int i);
73 int cpu_gdtlib_gdt_read_entry(struct cpu_gdtlib_entry *e,unsigned int i);
74 int cpu_gdtlib_empty_gdt_entry(struct cpu_gdtlib_entry *e);
75 int cpu_gdtlib_entry_is_special(struct cpu_gdtlib_entry *e);
76 int cpu_gdtlib_entry_is_executable(struct cpu_gdtlib_entry *e);
77 int cpu_gdtlib_read_current_regs();
78 int cpu_gdtlib_prepare_to_read_ldt();
79