CVS commit: src/regress/sys/arch/i386/ldt
Module Name:src Committed By: maxv Date: Wed Aug 30 15:46:20 UTC 2017 Modified Files: src/regress/sys/arch/i386/ldt: testldt.c Log Message: Don't test call gates, they are not supported anymore. To generate a diff of this commit: cvs rdiff -u -r1.16 -r1.17 src/regress/sys/arch/i386/ldt/testldt.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/regress/sys/arch/i386/ldt/testldt.c diff -u src/regress/sys/arch/i386/ldt/testldt.c:1.16 src/regress/sys/arch/i386/ldt/testldt.c:1.17 --- src/regress/sys/arch/i386/ldt/testldt.c:1.16 Sat Sep 3 08:47:38 2016 +++ src/regress/sys/arch/i386/ldt/testldt.c Wed Aug 30 15:46:19 2017 @@ -1,6 +1,6 @@ -/* $NetBSD: testldt.c,v 1.16 2016/09/03 08:47:38 maxv Exp $ */ +/* $NetBSD: testldt.c,v 1.17 2017/08/30 15:46:19 maxv Exp $ */ -/*- +/* * Copyright (c) 1993 The NetBSD Foundation, Inc. * All rights reserved. * @@ -53,15 +53,6 @@ get_fs_byte(const char *addr) return _v; } -static unsigned short -get_cs(void) -{ - unsigned short _v; - - __asm ("movw %%cs,%0": "=r" (_v)); - return _v; -} - static int check_desc(int desc) { @@ -70,15 +61,6 @@ check_desc(int desc) return get_fs_byte((char *)0); } -static void -gated_call(void) -{ - printf("Called from call gate..."); - __asm volatile("movl %ebp,%esp"); - __asm volatile("popl %ebp"); - __asm volatile(".byte 0xcb"); -} - static union descriptor * make_sd(void *basep, unsigned limit, int type, int dpl, int seg32, int inpgs) { @@ -99,23 +81,6 @@ make_sd(void *basep, unsigned limit, int return &d; } -static union descriptor * -make_gd(void *func, unsigned int sel, unsigned stkcpy, int type, int dpl) -{ - static union descriptor d; - unsigned long offset = (unsigned long)func; - - d.gd.gd_looffset = offset & 0x; - d.gd.gd_selector = sel & 0x; - d.gd.gd_stkcpy = stkcpy & 0x1ff; - d.gd.gd_type = type & 0x1ff; - d.gd.gd_dpl = dpl & 0x3; - d.gd.gd_p= 1; - d.gd.gd_hioffset = (offset & 0x) >> 16; - - return &d; -} - static const char * seg_type_name[] = { "SYSNULL", "SYS286TSS", "SYSLDT", "SYS286BSY", @@ -206,9 +171,8 @@ main(int argc, char *argv[]) union descriptor ldt[MAX_USER_LDT]; int n, ch; int num; - unsigned int cs = get_cs(); unsigned char *data; - union descriptor *sd, *gd; + union descriptor *sd; unsigned char one = 1, two = 2, val; struct sigaction segv_act; int verbose = 0; @@ -229,10 +193,8 @@ main(int argc, char *argv[]) } printf("Testing i386_get_ldt\n"); - if ((num = i386_get_ldt(0, ldt, MAX_USER_LDT)) < 0) - err(2, "get_ldt"); - if (num == 0) - errx(1, "i386_get_ldt() returned empty initial LDT"); + if ((num = i386_get_ldt(0, ldt, MAX_USER_LDT)) >= 0) + err(2, "get_ldt succeeded"); if (verbose) { printf("Got %d (initial) LDT entries\n", num); @@ -275,39 +237,6 @@ main(int argc, char *argv[]) "expected 0x97, got 0x%x", check_desc(num)); /* - * Test a Call Gate - */ - printf("Making call gate\n"); - fflush(stdout); - - gd = make_gd((void *)gated_call, cs, 0, SDT_SYS386CGT, SEL_UPL); - if ((num = i386_set_ldt(4095, gd, 1)) < 0) - err(1, "set_ldt: call gate"); - - if (verbose) { - printf("setldt returned: %d\n", num); - printf("Call gate sel = 0x%x\n", LSEL(num, SEL_UPL)); - } - - if ((n = i386_get_ldt(num, ldt, 1)) < 0) - err(1, "get_ldt"); - - if (verbose) { - printf("Entry %d: ", num); - print_ldt(&ldt[0]); - } - - printf("Testing call gate..."); - fflush(stdout); - /* - * Long call to call gate. - * Only the selector matters; offset is irrelevant. - */ - __asm volatile("lcall $0x7fff,$0x0"); - - printf("Gated call returned\n"); - - /* * Test multiple sets. */
CVS commit: src/regress/sys/arch/i386/ldt
Module Name:src Committed By: maxv Date: Sat Sep 3 08:47:38 UTC 2016 Modified Files: src/regress/sys/arch/i386/ldt: testldt.c Log Message: Fix the mmap call, KNF, and make the output more readable. To generate a diff of this commit: cvs rdiff -u -r1.15 -r1.16 src/regress/sys/arch/i386/ldt/testldt.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/regress/sys/arch/i386/ldt/testldt.c diff -u src/regress/sys/arch/i386/ldt/testldt.c:1.15 src/regress/sys/arch/i386/ldt/testldt.c:1.16 --- src/regress/sys/arch/i386/ldt/testldt.c:1.15 Fri Mar 18 03:06:21 2011 +++ src/regress/sys/arch/i386/ldt/testldt.c Sat Sep 3 08:47:38 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: testldt.c,v 1.15 2011/03/18 03:06:21 joerg Exp $ */ +/* $NetBSD: testldt.c,v 1.16 2016/09/03 08:47:38 maxv Exp $ */ /*- * Copyright (c) 1993 The NetBSD Foundation, Inc. @@ -67,7 +67,7 @@ check_desc(int desc) { unsigned int sel = LSEL(desc, SEL_UPL); set_fs(sel); - return(get_fs_byte((char *) 0)); + return get_fs_byte((char *)0); } static void @@ -89,14 +89,14 @@ make_sd(void *basep, unsigned limit, int d.sd.sd_lobase = base & 0x00ff; d.sd.sd_type= type & 0x01f; d.sd.sd_dpl = dpl & 0x3; - d.sd.sd_p = 1; + d.sd.sd_p = 1; d.sd.sd_hilimit = (limit & 0x00ff) >> 16; - d.sd.sd_xx = 0; + d.sd.sd_xx = 0; d.sd.sd_def32 = seg32?1:0; d.sd.sd_gran= inpgs?1:0; d.sd.sd_hibase = (base & 0xff00) >> 24; - return (&d); + return &d; } static union descriptor * @@ -110,10 +110,10 @@ make_gd(void *func, unsigned int sel, un d.gd.gd_stkcpy = stkcpy & 0x1ff; d.gd.gd_type = type & 0x1ff; d.gd.gd_dpl = dpl & 0x3; - d.gd.gd_p = 1; + d.gd.gd_p= 1; d.gd.gd_hioffset = (offset & 0x) >> 16; - return(&d); + return &d; } static const char * @@ -133,10 +133,9 @@ segtype(unsigned int type) { if (type >= 32) return "Out of range"; - + return seg_type_name[type]; } - static void print_ldt(union descriptor *dp) @@ -145,8 +144,8 @@ print_ldt(union descriptor *dp) unsigned int type, dpl; unsigned long lp[2]; - (void) memcpy(lp, dp, sizeof(lp)); - + memcpy(lp, dp, sizeof(lp)); + base_addr = dp->sd.sd_lobase | (dp->sd.sd_hibase << 24); limit = dp->sd.sd_lolimit | (dp->sd.sd_hilimit << 16); offset = dp->gd.gd_looffset | (dp->gd.gd_hioffset << 16); @@ -157,13 +156,11 @@ print_ldt(union descriptor *dp) if (type == SDT_SYS386CGT || type == SDT_SYS286CGT) printf("LDT: Gate Off %8.8lx, Sel %5.5x, Stkcpy %lu DPL %d," - " Type %d/%s\n", - offset, dp->gd.gd_selector, stack_copy, dpl, + " Type %d/%s\n", offset, dp->gd.gd_selector, stack_copy, dpl, type, segtype(type)); else printf("LDT: Seg Base %8.8lx, Limit %5.5lx, DPL %d, " - "Type %d/%s\n", - base_addr, limit, dpl, + "Type %d/%s\n", base_addr, limit, dpl, type, segtype(type)); printf(" "); if (type & 0x1) @@ -188,7 +185,6 @@ print_ldt(union descriptor *dp) printf(" Raw descriptor: %08lx %08lx\n", lp[0], lp[1]); } -/* ARGSUSED */ static void busfault(int signo) { @@ -196,12 +192,13 @@ busfault(int signo) } static void -usage(int status) +usage(void) { - errx(status, "Usage: testldt [-v]"); + errx(1, "Usage: testldt [-v]"); } #define MAX_USER_LDT 1024 +#define DATA_ADDR ((void *)0x005f) int main(int argc, char *argv[]) @@ -226,21 +223,20 @@ main(int argc, char *argv[]) verbose++; break; default: - usage(1); + usage(); break; } } - printf("Testing i386_get_ldt...\n"); + printf("Testing i386_get_ldt\n"); if ((num = i386_get_ldt(0, ldt, MAX_USER_LDT)) < 0) err(2, "get_ldt"); - if (num == 0) errx(1, "i386_get_ldt() returned empty initial LDT"); if (verbose) { printf("Got %d (initial) LDT entries\n", num); - for (n=0; n < num; n++) { + for (n = 0; n < num; n++) { printf("Entry %d: ", n); print_ldt(&ldt[n]); } @@ -249,24 +245,20 @@ main(int argc, char *argv[]) /* * mmap a data area and assign an LDT to it */ - printf("Testing i386_set_ldt...\n"); - data = (void *) mmap( (char *)0x005f, 0x0fff, - PROT_EXEC | PROT_READ | PROT_WRITE, + printf("Testing i386_set_ldt\n"); + data = (void *)mmap(DATA_ADDR, 4096, PROT_READ | PROT_WRITE, MAP_FIXED | MAP_PRIVATE | MAP_ANON, -1, (off_t)0); - if (data == NULL) + if (data != DATA_ADDR) err(1, "mmap"); - if (verbose) - printf("data address: %p\n", data); - *data = 0x97; /* Get the next free LDT and set it to the allocated data. */ sd = make_sd(data, 2048, SDT_MEMRW, SEL_UPL, 0, 0); if ((num = i386_set_ldt(1024, sd, 1)) < 0) err(1, "set_ldt"); - - if (verbose) printf("setldt returned: %d\n", num); + if (verbose) + printf("setldt returned: %d\n", num); if ((n = i386_get_ldt(num, ldt, 1)) < 0) err(1, "get_ldt"); @@ -281,13 +273,13 @@ main(int argc, char *argv[]) if (
CVS commit: src/regress/sys/arch/i386/ldt
Module Name:src Committed By: joerg Date: Fri Mar 18 03:06:22 UTC 2011 Modified Files: src/regress/sys/arch/i386/ldt: testldt.c Log Message: Kill a redundant lvalue cast in assembler constrained. To generate a diff of this commit: cvs rdiff -u -r1.14 -r1.15 src/regress/sys/arch/i386/ldt/testldt.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/regress/sys/arch/i386/ldt/testldt.c diff -u src/regress/sys/arch/i386/ldt/testldt.c:1.14 src/regress/sys/arch/i386/ldt/testldt.c:1.15 --- src/regress/sys/arch/i386/ldt/testldt.c:1.14 Mon Apr 28 20:23:05 2008 +++ src/regress/sys/arch/i386/ldt/testldt.c Fri Mar 18 03:06:21 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: testldt.c,v 1.14 2008/04/28 20:23:05 martin Exp $ */ +/* $NetBSD: testldt.c,v 1.15 2011/03/18 03:06:21 joerg Exp $ */ /*- * Copyright (c) 1993 The NetBSD Foundation, Inc. @@ -58,7 +58,7 @@ { unsigned short _v; - __asm ("movw %%cs,%0": "=r" ((unsigned short) _v)); + __asm ("movw %%cs,%0": "=r" (_v)); return _v; }