3 * Test program for gdt_enum.c library.
4 * Dumps the contents of the GDT onto the screen, if possible.
5 * (C) 2009-2012 Jonathan Campbell.
6 * Hackipedia DOS library.
8 * This code is licensed under the LGPL.
9 * <insert LGPL legal text here>
11 * Compiles for intended target environments:
13 * - Windows 3.0/3.1/95/98/ME
14 * - Windows NT 3.1/3.51/4.0/2000/XP/Vista/7
21 #include <conio.h> /* this is where Open Watcom hides the outp() etc. functions */
29 #include <hw/cpu/cpu.h>
30 #include <hw/dos/dos.h>
31 #include <hw/cpu/gdt_enum.h>
34 # define WINFCON_STOCK_WIN_MAIN
35 # include <hw/dos/winfcon.h>
39 struct cpu_gdtlib_entry ent;
43 if (!cpu_gdtlib_init()) {
44 printf("Unable to init CPU GDT library\n");
47 if (!cpu_gdtlib_read_current_regs()) {
48 printf("Cannot read current regs in any meaningful way\n");
52 printf("GDTR: Limit=0x%04x Base=0x%08lX LDTR: 0x%04x ",
53 (unsigned int)cpu_gdtlib_gdtr.limit,
54 (unsigned long)cpu_gdtlib_gdtr.base,
55 (unsigned int)cpu_gdtlib_ldtr);
57 /* for reference: print my code and data segment/selector values */
59 uint16_t v_cs=0,v_ds=0;
69 printf("CS=%04X DS=%04X\n",v_cs,v_ds);
73 for (i=0;i < cpu_gdtlib_gdt_entries(&cpu_gdtlib_gdtr);i++) {
74 if (cpu_gdtlib_gdt_read_entry(&ent,i)) {
75 if (!cpu_gdtlib_empty_gdt_entry(&ent)) {
76 printf("%04X: Lim=%08lX Base=%08lX Acc=%02X G=%02X ",
78 (unsigned long)ent.limit,
79 (unsigned long)ent.base,
82 if (cpu_gdtlib_entry_is_special(&ent)) {
83 printf("P=%u Other-%u Type=%u PL=%u",
85 (ent.granularity&0x40) ? 32 : 16,
89 else if (cpu_gdtlib_entry_is_executable(&ent)) {
90 printf("P=%u CODE-%u C=%u Read=%u PL=%u",
92 (ent.granularity&0x40) ? 32 : 16,
98 printf("P=%u DATA-%u D=%u RW=%u PL=%u",
100 (ent.granularity&0x40) ? 32 : 16,
111 if (c == 27) return 1;
118 if (cpu_gdtlib_prepare_to_read_ldt()) {
119 printf("LDT: Base=%08lX Limit=%08lX\n",
120 (unsigned long)cpu_gdtlib_ldt_ent.base,
121 (unsigned long)cpu_gdtlib_ldt_ent.limit);
123 for (i=0;i < cpu_gdtlib_ldt_entries(&cpu_gdtlib_ldt_ent);i++) {
124 if (cpu_gdtlib_ldt_read_entry(&ent,i)) {
125 if (!cpu_gdtlib_empty_ldt_entry(&ent)) {
126 printf("%04X: Lim=%08lX Base=%08lX Acc=%02X G=%02X ",
127 (unsigned int)(i << 3)+4,
128 (unsigned long)ent.limit,
129 (unsigned long)ent.base,
132 if (cpu_gdtlib_entry_is_special(&ent)) {
133 printf("P=%u Other-%u Type=%u PL=%u",
135 (ent.granularity&0x40) ? 32 : 16,
139 else if (cpu_gdtlib_entry_is_executable(&ent)) {
140 printf("P=%u CODE-%u C=%u Read=%u PL=%u",
142 (ent.granularity&0x40) ? 32 : 16,
148 printf("P=%u DATA-%u D=%u RW=%u PL=%u",
150 (ent.granularity&0x40) ? 32 : 16,
161 if (c == 27) return 1;