diff options
Diffstat (limited to 'i386/i386at')
35 files changed, 1565 insertions, 545 deletions
diff --git a/i386/i386at/acpi.c b/i386/i386at/acpi.c new file mode 100644 index 00000000..ec8aeb1e --- /dev/null +++ b/i386/i386at/acpi.c @@ -0,0 +1,82 @@ +/* acpi.c - get acpi tables. */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2009 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <grub/glue.h> +#include <grub/acpi.h> +#include <grub/misc.h> + +struct grub_acpi_rsdp_v10 * +grub_machine_acpi_get_rsdpv1 (void) +{ + int ebda_len; + grub_uint8_t *ebda, *ptr; + + grub_dprintf ("acpi", "Looking for RSDP. Scanning EBDA\n"); + ebda = (grub_uint8_t *) phystokv ((* ((grub_uint16_t *) phystokv (0x40e))) << 4); + ebda_len = * (grub_uint16_t *) ebda; + if (! ebda_len) + return 0; + for (ptr = ebda; ptr < ebda + 0x400; ptr += 16) + if (grub_memcmp (ptr, GRUB_RSDP_SIGNATURE, GRUB_RSDP_SIGNATURE_SIZE) == 0 + && grub_byte_checksum (ptr, sizeof (struct grub_acpi_rsdp_v10)) == 0 + && ((struct grub_acpi_rsdp_v10 *) ptr)->revision == 0) + return (struct grub_acpi_rsdp_v10 *) ptr; + + grub_dprintf ("acpi", "Looking for RSDP. Scanning BIOS\n"); + for (ptr = (grub_uint8_t *) phystokv (0xe0000); ptr < (grub_uint8_t *) phystokv (0x100000); + ptr += 16) + if (grub_memcmp (ptr, GRUB_RSDP_SIGNATURE, GRUB_RSDP_SIGNATURE_SIZE) == 0 + && grub_byte_checksum (ptr, sizeof (struct grub_acpi_rsdp_v10)) == 0 + && ((struct grub_acpi_rsdp_v10 *) ptr)->revision == 0) + return (struct grub_acpi_rsdp_v10 *) ptr; + return 0; +} + +struct grub_acpi_rsdp_v20 * +grub_machine_acpi_get_rsdpv2 (void) +{ + int ebda_len; + grub_uint8_t *ebda, *ptr; + + grub_dprintf ("acpi", "Looking for RSDP. Scanning EBDA\n"); + ebda = (grub_uint8_t *) phystokv ((* ((grub_uint16_t *) phystokv (0x40e))) << 4); + ebda_len = * (grub_uint16_t *) ebda; + if (! ebda_len) + return 0; + for (ptr = ebda; ptr < ebda + 0x400; ptr += 16) + if (grub_memcmp (ptr, GRUB_RSDP_SIGNATURE, GRUB_RSDP_SIGNATURE_SIZE) == 0 + && grub_byte_checksum (ptr, sizeof (struct grub_acpi_rsdp_v10)) == 0 + && ((struct grub_acpi_rsdp_v10 *) ptr)->revision != 0 + && ((struct grub_acpi_rsdp_v20 *) ptr)->length < 1024 + && grub_byte_checksum (ptr, ((struct grub_acpi_rsdp_v20 *) ptr)->length) + == 0) + return (struct grub_acpi_rsdp_v20 *) ptr; + + grub_dprintf ("acpi", "Looking for RSDP. Scanning BIOS\n"); + for (ptr = (grub_uint8_t *) phystokv (0xe0000); ptr < (grub_uint8_t *) phystokv (0x100000); + ptr += 16) + if (grub_memcmp (ptr, GRUB_RSDP_SIGNATURE, GRUB_RSDP_SIGNATURE_SIZE) == 0 + && grub_byte_checksum (ptr, sizeof (struct grub_acpi_rsdp_v10)) == 0 + && ((struct grub_acpi_rsdp_v10 *) ptr)->revision != 0 + && ((struct grub_acpi_rsdp_v20 *) ptr)->length < 1024 + && grub_byte_checksum (ptr, ((struct grub_acpi_rsdp_v20 *) ptr)->length) + == 0) + return (struct grub_acpi_rsdp_v20 *) ptr; + return 0; +} diff --git a/i386/i386at/acpihalt.c b/i386/i386at/acpihalt.c new file mode 100644 index 00000000..23df44ff --- /dev/null +++ b/i386/i386at/acpihalt.c @@ -0,0 +1,409 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2010 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <grub/glue.h> + +#ifdef GRUB_DSDT_TEST +#include <stdio.h> +#include <unistd.h> +#include <stdlib.h> +#include <stdint.h> +#include <string.h> +#include <errno.h> + +#define grub_dprintf(cond, args...) printf ( args ) +#define grub_printf printf +typedef uint64_t grub_uint64_t; +typedef uint32_t grub_uint32_t; +typedef uint16_t grub_uint16_t; +typedef uint8_t grub_uint8_t; + +#endif + +#include <grub/acpi.h> +#ifndef GRUB_DSDT_TEST +#include <grub/i18n.h> +#else +#define _(x) x +#define N_(x) x +#endif + +#ifndef GRUB_DSDT_TEST +#include <grub/mm.h> +#include <grub/misc.h> +#include <grub/time.h> +#include <grub/cpu/io.h> +#endif + +static inline grub_uint32_t +decode_length (const grub_uint8_t *ptr, int *numlen) +{ + int num_bytes, i; + grub_uint32_t ret; + if (*ptr < 64) + { + if (numlen) + *numlen = 1; + return *ptr; + } + num_bytes = *ptr >> 6; + if (numlen) + *numlen = num_bytes + 1; + ret = *ptr & 0xf; + ptr++; + for (i = 0; i < num_bytes; i++) + { + ret |= *ptr << (8 * i + 4); + ptr++; + } + return ret; +} + +static inline grub_uint32_t +skip_name_string (const grub_uint8_t *ptr, const grub_uint8_t *end) +{ + const grub_uint8_t *ptr0 = ptr; + + while (ptr < end && (*ptr == '^' || *ptr == '\\')) + ptr++; + switch (*ptr) + { + case '.': + ptr++; + ptr += 8; + break; + case '/': + ptr++; + ptr += 1 + (*ptr) * 4; + break; + case 0: + ptr++; + break; + default: + ptr += 4; + break; + } + return ptr - ptr0; +} + +static inline grub_uint32_t +skip_data_ref_object (const grub_uint8_t *ptr, const grub_uint8_t *end) +{ + grub_dprintf ("acpi", "data type = 0x%x\n", *ptr); + switch (*ptr) + { + case GRUB_ACPI_OPCODE_PACKAGE: + case GRUB_ACPI_OPCODE_BUFFER: + return 1 + decode_length (ptr + 1, 0); + case GRUB_ACPI_OPCODE_ZERO: + case GRUB_ACPI_OPCODE_ONES: + case GRUB_ACPI_OPCODE_ONE: + return 1; + case GRUB_ACPI_OPCODE_BYTE_CONST: + return 2; + case GRUB_ACPI_OPCODE_WORD_CONST: + return 3; + case GRUB_ACPI_OPCODE_DWORD_CONST: + return 5; + case GRUB_ACPI_OPCODE_STRING_CONST: + { + const grub_uint8_t *ptr0 = ptr; + for (ptr++; ptr < end && *ptr; ptr++); + if (ptr == end) + return 0; + return ptr - ptr0 + 1; + } + default: + if (*ptr == '^' || *ptr == '\\' || *ptr == '_' + || (*ptr >= 'A' && *ptr <= 'Z')) + return skip_name_string (ptr, end); + grub_printf ("Unknown opcode 0x%x\n", *ptr); + return 0; + } +} + +static inline grub_uint32_t +skip_ext_op (const grub_uint8_t *ptr, const grub_uint8_t *end) +{ + const grub_uint8_t *ptr0 = ptr; + int add; + grub_dprintf ("acpi", "Extended opcode: 0x%x\n", *ptr); + switch (*ptr) + { + case GRUB_ACPI_EXTOPCODE_MUTEX: + ptr++; + ptr += skip_name_string (ptr, end); + ptr++; + break; + case GRUB_ACPI_EXTOPCODE_EVENT_OP: + ptr++; + ptr += skip_name_string (ptr, end); + break; + case GRUB_ACPI_EXTOPCODE_OPERATION_REGION: + ptr++; + ptr += skip_name_string (ptr, end); + ptr++; + ptr += add = skip_data_ref_object (ptr, end); + if (!add) + return 0; + ptr += add = skip_data_ref_object (ptr, end); + if (!add) + return 0; + break; + case GRUB_ACPI_EXTOPCODE_FIELD_OP: + case GRUB_ACPI_EXTOPCODE_DEVICE_OP: + case GRUB_ACPI_EXTOPCODE_PROCESSOR_OP: + case GRUB_ACPI_EXTOPCODE_POWER_RES_OP: + case GRUB_ACPI_EXTOPCODE_THERMAL_ZONE_OP: + case GRUB_ACPI_EXTOPCODE_INDEX_FIELD_OP: + case GRUB_ACPI_EXTOPCODE_BANK_FIELD_OP: + ptr++; + ptr += decode_length (ptr, 0); + break; + default: + grub_printf ("Unexpected extended opcode: 0x%x\n", *ptr); + return 0; + } + return ptr - ptr0; +} + +static int +get_sleep_type (grub_uint8_t *table, grub_uint8_t *ptr, grub_uint8_t *end, + grub_uint8_t *scope, int scope_len) +{ + grub_uint8_t *prev = table; + + if (!ptr) + ptr = table + sizeof (struct grub_acpi_table_header); + while (ptr < end && prev < ptr) + { + int add; + prev = ptr; + grub_dprintf ("acpi", "Opcode 0x%x\n", *ptr); + grub_dprintf ("acpi", "Tell %x\n", (unsigned) (ptr - table)); + switch (*ptr) + { + case GRUB_ACPI_OPCODE_EXTOP: + ptr++; + ptr += add = skip_ext_op (ptr, end); + if (!add) + return -1; + break; + case GRUB_ACPI_OPCODE_CREATE_WORD_FIELD: + case GRUB_ACPI_OPCODE_CREATE_BYTE_FIELD: + { + ptr += 5; + ptr += add = skip_data_ref_object (ptr, end); + if (!add) + return -1; + ptr += 4; + break; + } + case GRUB_ACPI_OPCODE_NAME: + ptr++; + if ((!scope || grub_memcmp (scope, "\\", scope_len) == 0) && + (grub_memcmp (ptr, "_S5_", 4) == 0 || grub_memcmp (ptr, "\\_S5_", 4) == 0)) + { + int ll; + grub_uint8_t *ptr2 = ptr; + grub_dprintf ("acpi", "S5 found\n"); + ptr2 += skip_name_string (ptr, end); + if (*ptr2 != 0x12) + { + grub_printf ("Unknown opcode in _S5: 0x%x\n", *ptr2); + return -1; + } + ptr2++; + decode_length (ptr2, &ll); + ptr2 += ll; + ptr2++; + switch (*ptr2) + { + case GRUB_ACPI_OPCODE_ZERO: + return 0; + case GRUB_ACPI_OPCODE_ONE: + return 1; + case GRUB_ACPI_OPCODE_BYTE_CONST: + return ptr2[1]; + default: + grub_printf ("Unknown data type in _S5: 0x%x\n", *ptr2); + return -1; + } + } + ptr += add = skip_name_string (ptr, end); + if (!add) + return -1; + ptr += add = skip_data_ref_object (ptr, end); + if (!add) + return -1; + break; + case GRUB_ACPI_OPCODE_SCOPE: + { + int scope_sleep_type; + int ll; + grub_uint8_t *name; + int name_len; + + ptr++; + add = decode_length (ptr, &ll); + name = ptr + ll; + name_len = skip_name_string (name, ptr + add); + if (!name_len) + return -1; + scope_sleep_type = get_sleep_type (table, name + name_len, + ptr + add, name, name_len); + if (scope_sleep_type != -2) + return scope_sleep_type; + ptr += add; + break; + } + case GRUB_ACPI_OPCODE_IF: + case GRUB_ACPI_OPCODE_METHOD: + { + ptr++; + ptr += decode_length (ptr, 0); + break; + } + default: + grub_printf ("Unknown opcode 0x%x\n", *ptr); + return -1; + } + } + + return -2; +} + +#ifdef GRUB_DSDT_TEST +int +main (int argc, char **argv) +{ + FILE *f; + size_t len; + unsigned char *buf; + if (argc < 2) + printf ("Usage: %s FILE\n", argv[0]); + f = grub_util_fopen (argv[1], "rb"); + if (!f) + { + printf ("Couldn't open file\n"); + return 1; + } + fseek (f, 0, SEEK_END); + len = ftell (f); + fseek (f, 0, SEEK_SET); + buf = malloc (len); + if (!buf) + { + printf (_("error: %s.\n"), _("out of memory")); + fclose (f); + return 2; + } + if (fread (buf, 1, len, f) != len) + { + printf (_("cannot read `%s': %s"), argv[1], strerror (errno)); + free (buf); + fclose (f); + return 2; + } + + printf ("Sleep type = %d\n", get_sleep_type (buf, NULL, buf + len, NULL, 0)); + free (buf); + fclose (f); + return 0; +} + +#else + +void +grub_acpi_halt (void) +{ + struct grub_acpi_rsdp_v20 *rsdp2; + struct grub_acpi_rsdp_v10 *rsdp1; + struct grub_acpi_table_header *rsdt; + grub_uint32_t *entry_ptr; + grub_uint32_t port = 0; + int sleep_type = -1; + + rsdp2 = grub_acpi_get_rsdpv2 (); + if (rsdp2) + rsdp1 = &(rsdp2->rsdpv1); + else + rsdp1 = grub_acpi_get_rsdpv1 (); + grub_dprintf ("acpi", "rsdp1=%p\n", rsdp1); + if (!rsdp1) + return; + + rsdt = (struct grub_acpi_table_header *) + io_map_cached (rsdp1->rsdt_addr, sizeof *rsdt); + rsdt = (struct grub_acpi_table_header *) + io_map_cached (rsdp1->rsdt_addr, rsdt->length); + + for (entry_ptr = (grub_uint32_t *) (rsdt + 1); + entry_ptr < (grub_uint32_t *) (((grub_uint8_t *) rsdt) + + rsdt->length); + entry_ptr++) + { + if (grub_memcmp ((void *) io_map_cached (*entry_ptr, 4), + "FACP", 4) == 0) + { + struct grub_acpi_fadt *fadt = (struct grub_acpi_fadt *) + io_map_cached (*entry_ptr, sizeof *fadt); + + struct grub_acpi_table_header *dsdt = + (struct grub_acpi_table_header *) + io_map_cached (fadt->dsdt_addr, sizeof *dsdt); + grub_uint8_t *buf = (grub_uint8_t *) + io_map_cached (fadt->dsdt_addr, dsdt->length); + + port = fadt->pm1a; + + grub_dprintf ("acpi", "PM1a port=%x\n", port); + + if (grub_memcmp (dsdt->signature, "DSDT", + sizeof (dsdt->signature)) == 0 + && sleep_type < 0) + sleep_type = get_sleep_type (buf, NULL, buf + dsdt->length, + NULL, 0); + } + else + if (grub_memcmp ((void *) io_map_cached (*entry_ptr, 4), "SSDT", 4) == 0 + && sleep_type < 0) + { + struct grub_acpi_table_header *ssdt + = (struct grub_acpi_table_header *) (grub_addr_t) + io_map_cached (*entry_ptr, sizeof *ssdt); + grub_uint8_t *buf = (grub_uint8_t *) + io_map_cached (*entry_ptr, ssdt->length); + + grub_dprintf ("acpi", "SSDT = %p\n", ssdt); + + sleep_type = get_sleep_type (buf, NULL, buf + ssdt->length, NULL, 0); + } + } + + grub_dprintf ("acpi", "SLP_TYP = %d, port = 0x%x\n", sleep_type, port); + if (port && sleep_type >= 0 && sleep_type < 8) + grub_outw (GRUB_ACPI_SLP_EN | (sleep_type << GRUB_ACPI_SLP_TYP_OFFSET), + port & 0xffff); + + grub_millisleep (1500); + + /* TRANSLATORS: It's computer shutdown using ACPI, not disabling ACPI. */ + grub_puts_ (N_("ACPI shutdown failed")); +} +#endif diff --git a/i386/i386at/acpihalt.h b/i386/i386at/acpihalt.h new file mode 100644 index 00000000..a4fdb075 --- /dev/null +++ b/i386/i386at/acpihalt.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2014 Free Software Foundation. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef _ACPIHALT_H_ +#define _ACPIHALT_H_ + +void grub_acpi_halt (void); + +#endif /* _ACPIHALT_H_ */ diff --git a/i386/i386at/autoconf.c b/i386/i386at/autoconf.c index 93c71412..908c3ec0 100644 --- a/i386/i386at/autoconf.c +++ b/i386/i386at/autoconf.c @@ -38,12 +38,12 @@ #if NCOM > 0 extern struct bus_driver comdriver; -extern void comintr(); +#include <i386at/com.h> #endif /* NCOM */ #if NLPR > 0 extern struct bus_driver lprdriver; -extern void lprintr(); +#include <i386at/lpr.h> #endif /* NLPR */ struct bus_ctlr bus_master_init[] = { @@ -92,9 +92,9 @@ struct bus_device bus_device_init[] = { */ void probeio(void) { - register struct bus_device *device; - register struct bus_ctlr *master; - int i = 0; + struct bus_device *device; + struct bus_ctlr *master; + int i = 0; for (master = bus_master_init; master->driver; master++) { @@ -122,7 +122,7 @@ void probeio(void) } void take_dev_irq( - struct bus_device *dev) + const struct bus_device *dev) { int pic = (int)dev->sysdep1; @@ -144,7 +144,7 @@ void take_dev_irq( } void take_ctlr_irq( - struct bus_ctlr *ctlr) + const struct bus_ctlr *ctlr) { int pic = ctlr->sysdep1; if (intpri[pic] == 0) { diff --git a/i386/i386at/com.c b/i386/i386at/com.c index 93c3faaa..84891bd2 100644 --- a/i386/i386at/com.c +++ b/i386/i386at/com.c @@ -49,11 +49,7 @@ #include <device/cons.h> -int comprobe(), commctl(); -void comstart(struct tty *); -void comstop(), comattach(), comintr(); static void comparam(); -int comgetstat(), comsetstat(); static vm_offset_t com_std[NCOM] = { 0 }; struct bus_device *cominfo[NCOM]; @@ -149,7 +145,7 @@ comprobe_general(struct bus_device *dev, int noisy) type = "82450 or 16450"; outb(FIFO_CTL(addr), iFIFOENA | iFIFO14CH); /* Enable fifo */ if ((inb(FIFO_CTL(addr)) & iFIFO14CH) != 0) - { /* Was it successfull */ + { /* Was it successful */ /* if both bits are not set then broken xx550 */ if ((inb(FIFO_CTL(addr)) & iFIFO14CH) == iFIFO14CH) { @@ -173,9 +169,9 @@ comprobe_general(struct bus_device *dev, int noisy) * all of bus_device_init */ int -comprobe(int port, struct bus_device *dev) +comprobe(vm_offset_t port, struct bus_ctlr *dev) { - return comprobe_general(dev, /*noisy*/ 0); + return comprobe_general((struct bus_device *)dev, /*noisy*/ 0); } /* @@ -265,7 +261,7 @@ comcninit(struct consdev *cp) outb(LINE_CTL(addr), iDLAB); outb(BAUD_LSB(addr), divisorreg[RCBAUD] & 0xff); outb(BAUD_MSB(addr), divisorreg[RCBAUD] >>8); - outb(LINE_CTL(addr), i8BITS); + outb(LINE_CTL(addr), i8BITS); outb(INTR_ENAB(addr), 0); outb(MODEM_CTL(addr), iDTR|iRTS|iOUT2); @@ -323,7 +319,7 @@ boolean_t com_reprobe( } io_return_t comopen( - int dev, + dev_t dev, int flag, io_req_t ior) { @@ -342,6 +338,8 @@ io_return_t comopen( */ if (!com_reprobe(unit)) return D_NO_SUCH_DEVICE; + if ((isai = cominfo[unit]) == 0 || isai->alive == 0) + return D_NO_SUCH_DEVICE; } tp = &com_tty[unit]; @@ -402,8 +400,8 @@ io_return_t comopen( return result; } -io_return_t comclose(dev, flag) -int dev; +void comclose(dev, flag) +dev_t dev; int flag; { struct tty *tp = &com_tty[minor(dev)]; @@ -418,18 +416,18 @@ int flag; if (comfifo[minor(dev)] != 0) outb(INTR_ID(addr), 0x00); /* Disable fifos */ } - return 0; + return; } io_return_t comread(dev, ior) -int dev; +dev_t dev; io_req_t ior; { return char_read(&com_tty[minor(dev)], ior); } io_return_t comwrite(dev, ior) -int dev; +dev_t dev; io_req_t ior; { return char_write(&com_tty[minor(dev)], ior); @@ -466,11 +464,11 @@ natural_t *count; /* out */ } io_return_t -comsetstat(dev, flavor, data, count) -dev_t dev; -int flavor; -int * data; -natural_t count; +comsetstat( + dev_t dev, + int flavor, + int * data, + natural_t count) { io_return_t result = D_SUCCESS; int unit = minor(dev); @@ -496,10 +494,9 @@ natural_t count; } void -comintr(unit) -int unit; +comintr(int unit) { - register struct tty *tp = &com_tty[unit]; + struct tty *tp = &com_tty[unit]; u_short addr = cominfo[unit]->address; static char comoverrun = 0; char c, line, intr_id; @@ -521,10 +518,35 @@ int unit; case RECi: case CTIi: /* Character timeout indication */ if (tp->t_state&TS_ISOPEN) { + int escape = 0; while ((line = inb(LINE_STAT(addr))) & iDR) { c = inb(TXRX(addr)); - ttyinput(c, tp); + + if (c == 0x1b) { + escape = 1; + continue; + } + +#if MACH_KDB + if (escape && c == 'D'-('A'-1)) + /* ctrl-alt-d pressed, + invoke debugger */ + kdb_kintr(); + else +#endif /* MACH_KDB */ + if (escape) { + ttyinput(0x1b, tp); + ttyinput(c, tp); + } + else + ttyinput(c, tp); + + escape = 0; } + + if (escape) + /* just escape */ + ttyinput(0x1b, tp); } else tt_open_wakeup(tp); break; @@ -547,8 +569,7 @@ int unit; } static void -comparam(unit) -register int unit; +comparam(int unit) { struct tty *tp = &com_tty[unit]; u_short addr = (int)tp->t_addr; @@ -617,10 +638,9 @@ comparm(int unit, int baud, int intr, int mode, int modem) int comst_1, comst_2, comst_3, comst_4, comst_5 = 14; void -comstart(tp) -struct tty *tp; +comstart(struct tty *tp) { - char nch; + int nch; #if 0 int i; #endif @@ -656,6 +676,8 @@ comst_4++; } #else nch = getc(&tp->t_outq); + if (nch == -1) + return; if ((nch & 0200) && ((tp->t_flags & LITOUT) == 0)) { timeout((timer_func_t *)ttrstrt, (char *)tp, (nch & 0x7f) + 6); tp->t_state |= TS_TIMEOUT; @@ -698,8 +720,9 @@ printf("Tty %p was stuck\n", tp); * Set receive modem state from modem status register. */ void -fix_modem_state(unit, modem_stat) -int unit, modem_stat; +fix_modem_state( + int unit, + int modem_stat) { int stat = 0; @@ -751,14 +774,14 @@ commodem_intr( */ int commctl( - register struct tty *tp, - int bits, - int how) + struct tty *tp, + int bits, + int how) { spl_t s; int unit; vm_offset_t dev_addr; - register int b = 0; /* Suppress gcc warning */ + int b = 0; /* Suppress gcc warning */ unit = minor(tp->t_dev); @@ -817,9 +840,9 @@ commctl( } void -comstop(tp, flags) -register struct tty *tp; -int flags; +comstop( + struct tty *tp, + int flags) { if ((tp->t_state & TS_BUSY) && (tp->t_state & TS_TTSTOP) == 0) tp->t_state |= TS_FLUSH; @@ -830,16 +853,16 @@ int flags; * Code to be called from debugger. * */ -void compr_addr(addr) +void compr_addr(vm_offset_t addr) { /* The two line_stat prints may show different values, since * touching some of the registers constitutes changing them. */ - printf("LINE_STAT(%x) %x\n", + printf("LINE_STAT(%lu) %x\n", LINE_STAT(addr), inb(LINE_STAT(addr))); - printf("TXRX(%x) %x, INTR_ENAB(%x) %x, INTR_ID(%x) %x, LINE_CTL(%x) %x,\n\ -MODEM_CTL(%x) %x, LINE_STAT(%x) %x, MODEM_STAT(%x) %x\n", + printf("TXRX(%lu) %x, INTR_ENAB(%lu) %x, INTR_ID(%lu) %x, LINE_CTL(%lu) %x,\n\ +MODEM_CTL(%lu) %x, LINE_STAT(%lu) %x, MODEM_STAT(%lu) %x\n", TXRX(addr), inb(TXRX(addr)), INTR_ENAB(addr), inb(INTR_ENAB(addr)), INTR_ID(addr), inb(INTR_ID(addr)), @@ -849,7 +872,7 @@ MODEM_CTL(%x) %x, LINE_STAT(%x) %x, MODEM_STAT(%x) %x\n", MODEM_STAT(addr),inb(MODEM_STAT(addr))); } -int compr(unit) +int compr(int unit) { compr_addr(cominfo[unit]->address); return(0); diff --git a/i386/i386at/com.h b/i386/i386at/com.h index 49f23eec..779cdba8 100644 --- a/i386/i386at/com.h +++ b/i386/i386at/com.h @@ -28,6 +28,8 @@ #include <mach/std_types.h> #include <device/cons.h> +#include <device/tty.h> +#include <chips/busses.h> /* * Set receive modem state from modem status register. @@ -47,5 +49,36 @@ extern int comcnprobe(struct consdev *cp); extern int comcninit(struct consdev *cp); extern int comcngetc(dev_t dev, int wait); extern int comcnputc(dev_t dev, int c); +extern void comintr(int unit); + +int comprobe(vm_offset_t port, struct bus_ctlr *dev); +int commctl(struct tty *tp, int bits, int how); +void comstart(struct tty *tp); +void comstop(struct tty *tp, int flags); +void comattach(struct bus_device *dev); + +extern io_return_t +comgetstat( + dev_t dev, + int flavor, + int *data, + natural_t *count); + +extern io_return_t +comsetstat( + dev_t dev, + int flavor, + int *data, + natural_t count); + +#if MACH_KDB +extern void kdb_kintr(void); +#endif /* MACH_KDB */ + +extern io_return_t comopen(dev_t dev, int flag, io_req_t ior); +extern void comclose(dev_t dev, int flag); +extern io_return_t comread(dev_t dev, io_req_t ior); +extern io_return_t comwrite(dev_t dev, io_req_t ior); +extern io_return_t comportdeath(dev_t dev, mach_port_t port); #endif /* _COM_H_ */ diff --git a/i386/i386at/conf.c b/i386/i386at/conf.c index 83c8dbfc..fe7c7c09 100644 --- a/i386/i386at/conf.c +++ b/i386/i386at/conf.c @@ -29,48 +29,42 @@ #include <mach/machine/vm_types.h> #include <device/conf.h> +#include <kern/mach_clock.h> +#include <i386at/model_dep.h> -extern int timeopen(), timeclose(); -extern vm_offset_t timemmap(); #define timename "time" #ifndef MACH_HYP -extern int kdopen(), kdclose(), kdread(), kdwrite(); -extern int kdgetstat(), kdsetstat(), kdportdeath(); -extern vm_offset_t kdmmap(); +#include <i386at/kd.h> #define kdname "kd" #if NCOM > 0 -extern int comopen(), comclose(), comread(), comwrite(); -extern int comgetstat(), comsetstat(), comportdeath(); +#include <i386at/com.h> #define comname "com" #endif /* NCOM > 0 */ #if NLPR > 0 -extern int lpropen(), lprclose(), lprread(), lprwrite(); -extern int lprgetstat(), lprsetstat(), lprportdeath(); +#include <i386at/lpr.h> #define lprname "lpr" #endif /* NLPR > 0 */ #endif /* MACH_HYP */ -extern int kbdopen(), kbdclose(), kbdread(); -extern int kbdgetstat(), kbdsetstat(); +#include <i386at/kd_event.h> #define kbdname "kbd" #ifndef MACH_HYP -extern int mouseopen(), mouseclose(), mouseread(), mousegetstat(); +#include <i386at/kd_mouse.h> #define mousename "mouse" -extern vm_offset_t memmmap(); +#include <i386at/mem.h> #define memname "mem" #endif /* MACH_HYP */ -extern int kmsgopen(), kmsgclose(), kmsgread(), kmsggetstat(); +#include <device/kmsg.h> #define kmsgname "kmsg" #ifdef MACH_HYP -extern int hypcnopen(), hypcnclose(), hypcnread(), hypcnwrite(); -extern int hypcngetstat(), hypcnsetstat(), hypcnportdeath(); +#include <xen/console.h> #define hypcnname "hyp" #endif /* MACH_HYP */ @@ -87,21 +81,27 @@ struct dev_ops dev_name_list[] = /* We don't assign a console here, when we find one via cninit() we stick something appropriate here through the indirect list */ - { "cn", nulldev, nulldev, nulldev, - nulldev, nulldev, nulldev, nomap, - nodev, nulldev, nulldev, 0, + { "cn", nulldev_open, nulldev_close, nulldev_read, + nulldev_write, nulldev_getstat, nulldev_setstat, nomap, + nodev, nulldev, nulldev_portdeath, 0, nodev }, #ifndef MACH_HYP +#if ENABLE_IMMEDIATE_CONSOLE + { "immc", nulldev_open, nulldev_close, nulldev_read, + nulldev_write, nulldev_getstat, nulldev_setstat, + nomap, nodev, nulldev, nulldev_portdeath, 0, + nodev }, +#endif /* ENABLE_IMMEDIATE_CONSOLE */ { kdname, kdopen, kdclose, kdread, kdwrite, kdgetstat, kdsetstat, kdmmap, nodev, nulldev, kdportdeath, 0, nodev }, #endif /* MACH_HYP */ - { timename, timeopen, timeclose, nulldev, - nulldev, nulldev, nulldev, timemmap, - nodev, nulldev, nulldev, 0, + { timename, timeopen, timeclose, nulldev_read, + nulldev_write, nulldev_getstat, nulldev_setstat, timemmap, + nodev, nulldev, nulldev_portdeath, 0, nodev }, #ifndef MACH_HYP @@ -120,25 +120,25 @@ struct dev_ops dev_name_list[] = #endif { mousename, mouseopen, mouseclose, mouseread, - nodev, mousegetstat, nulldev, nomap, - nodev, nulldev, nulldev, 0, + nulldev_write, mousegetstat, nulldev_setstat, nomap, + nodev, nulldev, nulldev_portdeath, 0, nodev }, { kbdname, kbdopen, kbdclose, kbdread, - nodev, kbdgetstat, kbdsetstat, nomap, - nodev, nulldev, nulldev, 0, + nulldev_write, kbdgetstat, kbdsetstat, nomap, + nodev, nulldev, nulldev_portdeath, 0, nodev }, - { memname, nulldev, nulldev, nodev, - nodev, nodev, nodev, memmmap, - nodev, nulldev, nulldev, 0, + { memname, nulldev_open, nulldev_close, nulldev_read, + nulldev_write, nulldev_getstat, nulldev_setstat, memmmap, + nodev, nulldev, nulldev_portdeath, 0, nodev }, #endif /* MACH_HYP */ #ifdef MACH_KMSG { kmsgname, kmsgopen, kmsgclose, kmsgread, - nodev, kmsggetstat, nodev, nomap, - nodev, nulldev, nulldev, 0, + nulldev_write, kmsggetstat, nulldev_setstat, nomap, + nodev, nulldev, nulldev_portdeath, 0, nodev }, #endif diff --git a/i386/i386at/cons_conf.c b/i386/i386at/cons_conf.c index cf42bb63..1d7dd387 100644 --- a/i386/i386at/cons_conf.c +++ b/i386/i386at/cons_conf.c @@ -39,6 +39,10 @@ #endif #endif /* MACH_HYP */ +#if ENABLE_IMMEDIATE_CONSOLE +#include "immc.h" +#endif /* ENABLE_IMMEDIATE_CONSOLE */ + /* * The rest of the consdev fields are filled in by the respective * cnprobe routine. @@ -47,6 +51,9 @@ struct consdev constab[] = { #ifdef MACH_HYP {"hyp", hypcnprobe, hypcninit, hypcngetc, hypcnputc}, #else /* MACH_HYP */ +#if ENABLE_IMMEDIATE_CONSOLE + {"immc", immc_cnprobe, immc_cninit, immc_cngetc, immc_cnputc}, +#endif /* ENABLE_IMMEDIATE_CONSOLE */ {"kd", kdcnprobe, kdcninit, kdcngetc, kdcnputc}, #if NCOM > 0 {"com", comcnprobe, comcninit, comcngetc, comcnputc}, diff --git a/i386/i386at/cram.h b/i386/i386at/cram.h index 8373ce03..40f3f0a5 100644 --- a/i386/i386at/cram.h +++ b/i386/i386at/cram.h @@ -50,6 +50,9 @@ NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUR OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#ifndef _CRAM_H_ +#define _CRAM_H_ + /* * outb(CMOS_ADDR, addr); * result = inb(CMOS_DATA); @@ -73,3 +76,4 @@ WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #define CM_CGA_80 0x20 #define CM_MONO_80 0x30 +#endif /* _CRAM_H_ */ diff --git a/i386/i386at/disk.h b/i386/i386at/disk.h index e1fe6b98..63d033f0 100644 --- a/i386/i386at/disk.h +++ b/i386/i386at/disk.h @@ -49,6 +49,9 @@ WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * disk.h */ +#ifndef _DISK_H_ +#define _DISK_H_ + /* Grab the public part. */ #include <mach/machine/disk.h> @@ -184,3 +187,4 @@ struct mboot { /* master boot block */ u_short signature; }; +#endif /* _DISK_H_ */ diff --git a/i386/i386at/grub_glue.c b/i386/i386at/grub_glue.c new file mode 100644 index 00000000..68a4cb1f --- /dev/null +++ b/i386/i386at/grub_glue.c @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2014 Free Software Foundation. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <kern/printf.h> +#include <stdarg.h> +#include <i386/vm_param.h> + +#include <grub/glue.h> +#include <grub/acpi.h> + +#define GRUB_DEBUG 0 + +void +grub_real_dprintf (const char *file, const int line, const char *condition, + const char *fmt, ...) +{ +#if GRUB_DEBUG + va_list listp; + va_start(listp, fmt); + vprintf (fmt, listp); + va_end(listp); +#endif +} + +void +grub_millisleep (grub_uint32_t ms) +{ + /* Do nothing. */ +} + +struct grub_acpi_rsdp_v20 * +grub_acpi_get_rsdpv2 (void) +{ + return grub_machine_acpi_get_rsdpv2 (); +} + +struct grub_acpi_rsdp_v10 * +grub_acpi_get_rsdpv1 (void) +{ + return grub_machine_acpi_get_rsdpv1 (); +} + +/* Simple checksum by summing all bytes. Used by ACPI and SMBIOS. */ +grub_uint8_t +grub_byte_checksum (void *base, grub_size_t size) +{ + grub_uint8_t *ptr; + grub_uint8_t ret = 0; + for (ptr = (grub_uint8_t *) base; ptr < ((grub_uint8_t *) base) + size; + ptr++) + ret += *ptr; + return ret; +} diff --git a/i386/i386at/i8250.h b/i386/i386at/i8250.h index fa81173e..9b8a8019 100644 --- a/i386/i386at/i8250.h +++ b/i386/i386at/i8250.h @@ -49,6 +49,9 @@ WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * Header file for i8250 chip */ +#ifndef _I8250_H_ +#define _I8250_H_ + /* port offsets from the base i/o address */ #define RDAT 0 @@ -127,3 +130,5 @@ WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #define BCNT2400 0x30 #define BCNT4800 0x18 #define BCNT9600 0x0c + +#endif /* _I8250_H_ */ diff --git a/i386/i386at/idt.h b/i386/i386at/idt.h index 1b3284fa..56e6296c 100644 --- a/i386/i386at/idt.h +++ b/i386/i386at/idt.h @@ -36,6 +36,6 @@ #ifndef __ASSEMBLER__ extern void idt_init (void); -#endif +#endif /* __ASSEMBLER__ */ #endif /* _I386AT_IDT_ */ diff --git a/i386/i386at/immc.c b/i386/i386at/immc.c index db64620e..bd61522d 100644 --- a/i386/i386at/immc.c +++ b/i386/i386at/immc.c @@ -21,8 +21,11 @@ * Author: Bryan Ford, University of Utah CSL */ -#ifdef ENABLE_IMMEDIATE_CONSOLE +#if ENABLE_IMMEDIATE_CONSOLE +#include <device/cons.h> +#include <mach/boolean.h> +#include <i386/vm_param.h> #include <string.h> /* This is a special "feature" (read: kludge) @@ -33,24 +36,67 @@ so it can be used to debug things that happen very early before any devices are initialized. */ -int immediate_console_enable = 1; +boolean_t immediate_console_enable = TRUE; -void -immc_cnputc(unsigned char c) +/* + * XXX we assume that pcs *always* have a console + */ +int +immc_cnprobe(struct consdev *cp) +{ + int maj, unit, pri; + + maj = 0; + unit = 0; + pri = CN_INTERNAL; + + cp->cn_dev = makedev(maj, unit); + cp->cn_pri = pri; + return 0; +} + +int +immc_cninit(struct consdev *cp) +{ + return 0; +} + +int immc_cnmaygetc(void) +{ + return -1; +} + +int +immc_cngetc(dev_t dev, int wait) +{ + if (wait) { + int c; + while ((c = immc_cnmaygetc()) < 0) + continue; + return c; + } + else + return immc_cnmaygetc(); +} + +int +immc_cnputc(dev_t dev, int c) { static int ofs = -1; if (!immediate_console_enable) - return; - if (ofs < 0) + return -1; + if (ofs < 0 || ofs >= 80) { ofs = 0; - immc_cnputc('\n'); + immc_cnputc(dev, '\n'); } - else if (c == '\n') + + if (c == '\n') { - memmove(0xb8000, 0xb8000+80*2, 80*2*24); - memset(0xb8000+80*2*24, 0, 80*2); + memmove((void *) phystokv(0xb8000), + (void *) phystokv(0xb8000+80*2), 80*2*24); + memset((void *) phystokv((0xb8000+80*2*24)), 0, 80*2); ofs = 0; } else @@ -59,20 +105,22 @@ immc_cnputc(unsigned char c) if (ofs >= 80) { - immc_cnputc('\r'); - immc_cnputc('\n'); + immc_cnputc(dev, '\r'); + immc_cnputc(dev, '\n'); } - p = (void*)0xb8000 + 80*2*24 + ofs*2; + p = (void *) phystokv(0xb8000 + 80*2*24 + ofs*2); p[0] = c; p[1] = 0x0f; ofs++; } + return 0; } -int immc_cnmaygetc(void) +void +immc_romputc(char c) { - return -1; + immc_cnputc (0, c); } #endif /* ENABLE_IMMEDIATE_CONSOLE */ diff --git a/i386/i386at/immc.h b/i386/i386at/immc.h new file mode 100644 index 00000000..dc802c84 --- /dev/null +++ b/i386/i386at/immc.h @@ -0,0 +1,31 @@ +/* Declarations for the immediate console. + + Copyright (C) 2015 Free Software Foundation, Inc. + + This file is part of the GNU Mach. + + The GNU Mach is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2, or (at + your option) any later version. + + The GNU Mach is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with the GNU Mach. If not, see <http://www.gnu.org/licenses/>. */ + +#ifndef _IMMC_H_ +#define _IMMC_H_ + +#include <sys/types.h> + +int immc_cnprobe(struct consdev *cp); +int immc_cninit(struct consdev *cp); +int immc_cngetc(dev_t dev, int wait); +int immc_cnputc(dev_t dev, int c); +void immc_romputc(char c); + +#endif /* _IMMC_H_ */ diff --git a/i386/i386at/int_init.c b/i386/i386at/int_init.c index 0f00b868..43daad8b 100644 --- a/i386/i386at/int_init.c +++ b/i386/i386at/int_init.c @@ -27,7 +27,7 @@ /* defined in locore.S */ extern vm_offset_t int_entry_table[]; -void int_init() +void int_init(void) { int i; diff --git a/i386/i386at/int_init.h b/i386/i386at/int_init.h index f4abef0b..f9b03b74 100644 --- a/i386/i386at/int_init.h +++ b/i386/i386at/int_init.h @@ -29,6 +29,6 @@ #ifndef __ASSEMBLER__ extern void int_init (void); -#endif +#endif /* __ASSEMBLER__ */ #endif /* _INT_INIT_H_ */ diff --git a/i386/i386at/kd.c b/i386/i386at/kd.c index c9778629..5656e830 100644 --- a/i386/i386at/kd.c +++ b/i386/i386at/kd.c @@ -83,7 +83,7 @@ WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include <device/conf.h> #include <device/tty.h> #include <device/io_req.h> -#include <device/buf.h> /* for struct uio (!) */ +#include <device/buf.h> #include <vm/vm_kern.h> #include <i386/locore.h> #include <i386/loose_ends.h> @@ -100,20 +100,15 @@ WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #define DEBUG 1 /* export feep() */ -void kd_enqsc(); /* enqueues a scancode */ - #if 0 #define BROKEN_KEYBOARD_RESET #endif struct tty kd_tty; -extern int rebootflag; +extern boolean_t rebootflag; static void charput(), charmvup(), charmvdown(), charclear(), charsetcursor(); -static void kd_noopreset(); -boolean_t kdcheckmagic(); - -int do_modifier (int, Scancode, boolean_t); +static void kd_noopreset(void); /* * These routines define the interface to the device-specific layer. @@ -127,10 +122,6 @@ void (*kd_dsetcursor)() = charsetcursor; /* set cursor position on displayed page */ void (*kd_dreset)() = kd_noopreset; /* prepare for reboot */ -/* forward declarations */ -unsigned char kd_getdata(), state2leds(); - - /* * Globals used for both character-based controllers and bitmap-based * controllers. Default is EGA. @@ -213,7 +204,7 @@ u_char *esc_spt = (u_char *)0; - Delete returns `ESC [ 9' instead of 0x7f. - Alt + function keys return key sequences that are different from the key sequences returned by the function keys alone. - This is done with the idea of alowing a terminal server to + This is done with the idea of allowing a terminal server to implement multiple virtual consoles mapped on Alt+F1, Alt+F2, etc, as in Linux. @@ -249,8 +240,7 @@ unsigned char key_map[NUMKEYS][WIDTH_KMAP] = { {K_LBRKT,NC,NC, K_LBRACE,NC,NC, K_ESC,NC,NC, 0x1b,K_LBRKT,NC, 0x1b,0x4e,K_LBRACE}, {K_RBRKT,NC,NC, K_RBRACE,NC,NC, K_GS,NC,NC, 0x1b,K_RBRKT,NC, 0x1b,0x4e,K_RBRACE}, {K_CR,NC,NC, K_CR,NC,NC, K_CR,NC,NC, 0x1b,K_CR,NC, K_CR,NC,NC}, -{K_SCAN,K_CTLSC,NC, K_SCAN,K_CTLSC,NC, K_SCAN,K_CTLSC,NC, K_SCAN,K_CTLSC,NC, - K_SCAN,K_CTLSC,NC}, +{K_SCAN,K_CTLSC,NC, K_SCAN,K_CTLSC,NC, K_SCAN,K_CTLSC,NC, K_SCAN,K_CTLSC,NC, K_SCAN,K_CTLSC,NC}, {K_a,NC,NC, K_A,NC,NC, K_SOH,NC,NC, 0x1b,K_a,NC, 0x1b,0x4e,K_A}, {K_s,NC,NC, K_S,NC,NC, K_DC3,NC,NC, 0x1b,K_s,NC, 0x1b,0x4e,K_S}, {K_d,NC,NC, K_D,NC,NC, K_EOT,NC,NC, 0x1b,K_d,NC, 0x1b,0x4e,K_D}, @@ -263,8 +253,7 @@ unsigned char key_map[NUMKEYS][WIDTH_KMAP] = { {K_SEMI,NC,NC, K_COLON,NC,NC, K_SEMI,NC,NC, 0x1b,K_SEMI,NC, 0x1b,0x4e,K_COLON}, {K_SQUOTE,NC,NC,K_DQUOTE,NC,NC, K_SQUOTE,NC,NC,0x1b,K_SQUOTE,NC, 0x1b,0x4e,K_DQUOTE}, {K_GRAV,NC,NC, K_TILDE,NC,NC, K_RS,NC,NC, 0x1b,K_GRAV,NC, 0x1b,0x4e,K_TILDE}, -{K_SCAN,K_LSHSC,NC, K_SCAN,K_LSHSC,NC, K_SCAN,K_LSHSC,NC, K_SCAN,K_LSHSC,NC, - K_SCAN,K_LSHSC,NC}, +{K_SCAN,K_LSHSC,NC, K_SCAN,K_LSHSC,NC, K_SCAN,K_LSHSC,NC, K_SCAN,K_LSHSC,NC, K_SCAN,K_LSHSC,NC}, {K_BSLSH,NC,NC, K_PIPE,NC,NC, K_FS,NC,NC, 0x1b,K_BSLSH,NC, 0x1b,0x4e,K_PIPE}, {K_z,NC,NC, K_Z,NC,NC, K_SUB,NC,NC, 0x1b,K_z,NC, 0x1b,0x4e,K_Z}, {K_x,NC,NC, K_X,NC,NC, K_CAN,NC,NC, 0x1b,K_x,NC, 0x1b,0x4e,K_X}, @@ -276,14 +265,11 @@ unsigned char key_map[NUMKEYS][WIDTH_KMAP] = { {K_COMMA,NC,NC, K_LTHN,NC,NC, K_COMMA,NC,NC, 0x1b,K_COMMA,NC, 0x1b,0x4e,K_LTHN}, {K_PERIOD,NC,NC,K_GTHN,NC,NC, K_PERIOD,NC,NC,0x1b,K_PERIOD,NC, 0x1b,0x4e,K_GTHN}, {K_SLASH,NC,NC, K_QUES,NC,NC, K_SLASH,NC,NC, 0x1b,K_SLASH,NC, 0x1b,0x4e,K_QUES}, -{K_SCAN,K_RSHSC,NC, K_SCAN,K_RSHSC,NC, K_SCAN,K_RSHSC,NC, K_SCAN,K_RSHSC,NC, - K_SCAN,K_RSHSC,NC}, +{K_SCAN,K_RSHSC,NC, K_SCAN,K_RSHSC,NC, K_SCAN,K_RSHSC,NC, K_SCAN,K_RSHSC,NC, K_SCAN,K_RSHSC,NC}, {K_ASTER,NC,NC, K_ASTER,NC,NC, K_ASTER,NC,NC, 0x1b,K_ASTER,NC, 0x1b,0x4e,K_ASTER}, -{K_SCAN,K_ALTSC,NC, K_SCAN,K_ALTSC,NC, K_SCAN,K_ALTSC,NC, K_SCAN,K_ALTSC,NC, - K_SCAN,K_ALTSC,NC}, +{K_SCAN,K_ALTSC,NC, K_SCAN,K_ALTSC,NC, K_SCAN,K_ALTSC,NC, K_SCAN,K_ALTSC,NC, K_SCAN,K_ALTSC,NC}, {K_SPACE,NC,NC, K_SPACE,NC,NC, K_NUL,NC,NC, 0x1b,K_SPACE,NC, K_SPACE,NC,NC}, -{K_SCAN,K_CLCKSC,NC, K_SCAN,K_CLCKSC,NC, K_SCAN,K_CLCKSC,NC, - K_SCAN,K_CLCKSC,NC, K_SCAN,K_CLCKSC,NC}, +{K_SCAN,K_CLCKSC,NC, K_SCAN,K_CLCKSC,NC, K_SCAN,K_CLCKSC,NC, K_SCAN,K_CLCKSC,NC, K_SCAN,K_CLCKSC,NC}, {K_F1, K_F1S, K_F1, K_F1A, K_F1S}, {K_F2, K_F2S, K_F2, K_F2A, K_F2S}, {K_F3, K_F3S, K_F3, K_F3A, K_F3S}, @@ -294,20 +280,16 @@ unsigned char key_map[NUMKEYS][WIDTH_KMAP] = { {K_F8, K_F8S, K_F8, K_F8A, K_F8S}, {K_F9, K_F9S, K_F9, K_F9A, K_F9S}, {K_F10, K_F10S, K_F10, K_F10A, K_F10S}, -{K_SCAN,K_NLCKSC,NC, K_SCAN,K_NLCKSC,NC, K_SCAN,K_NLCKSC,NC, - K_SCAN,K_NLCKSC,NC, K_SCAN,K_NLCKSC,NC}, +{K_SCAN,K_NLCKSC,NC, K_SCAN,K_NLCKSC,NC, K_SCAN,K_NLCKSC,NC, K_SCAN,K_NLCKSC,NC, K_SCAN,K_NLCKSC,NC}, {K_SCRL, K_NUL,NC,NC, K_SCRL, K_SCRL, K_NUL,NC,NC}, {K_HOME, K_SEVEN,NC,NC, K_HOME, K_HOME, 0x1b,0x4e,K_SEVEN}, {K_UA, K_EIGHT,NC,NC, K_UA, K_UA, 0x1b,0x4e,K_EIGHT}, {K_PUP, K_NINE,NC,NC, K_PUP, K_PUP, 0x1b,0x4e,K_NINE}, -{0x1b,0x5b,0x53, K_MINUS,NC,NC, 0x1b,0x5b,0x53, 0x1b,0x5b,0x53, - 0x1b,0x4e,0x2d}, +{0x1b,0x5b,0x53, K_MINUS,NC,NC, 0x1b,0x5b,0x53, 0x1b,0x5b,0x53, 0x1b,0x4e,0x2d}, {K_LA, K_FOUR,NC,NC, K_LA, K_LA, 0x1b,0x4e,K_FOUR}, -{0x1b,0x5b,0x47, K_FIVE,NC,NC, 0x1b,0x5b,0x47, 0x1b,0x5b,0x47, - 0x1b,0x4e,0x35}, +{0x1b,0x5b,0x47, K_FIVE,NC,NC, 0x1b,0x5b,0x47, 0x1b,0x5b,0x47, 0x1b,0x4e,0x35}, {K_RA, K_SIX,NC,NC, K_RA, K_RA, 0x1b,0x4e,K_SIX}, -{0x1b,0x5b,0x54, K_PLUS,NC,NC, 0x1b,0x5b,0x54, 0x1b,0x5b,0x54, - 0x1b,0x4e,0x2b}, +{0x1b,0x5b,0x54, K_PLUS,NC,NC, 0x1b,0x5b,0x54, 0x1b,0x5b,0x54, 0x1b,0x4e,0x2b}, {K_END, K_ONE,NC,NC, K_END, K_END, 0x1b,0x4e,K_ONE}, {K_DA, K_TWO,NC,NC, K_DA, K_DA, 0x1b,0x4e,K_TWO}, {K_PDN, K_THREE,NC,NC, K_PDN, K_PDN, 0x1b,0x4e,K_THREE}, @@ -367,7 +349,7 @@ int kd_pollc = 0; * Warning: uses outb(). You may prefer to use kd_debug_put. */ void -feep() +feep(void) { int i; @@ -378,7 +360,7 @@ feep() } void -pause() +pause(void) { int i; @@ -392,9 +374,9 @@ pause() * one column to the left, etc. */ void -kd_debug_put(loc, c) -int loc; -char c; +kd_debug_put( + int loc, + char c) { csrpos_t pos = ONE_PAGE - (loc+1) * ONE_SPACE; @@ -403,12 +385,11 @@ char c; #endif /* DEBUG */ -extern int mouse_in_use; -int old_kb_mode; +extern boolean_t mouse_in_use; +int old_kb_mode; void -cnpollc(on) -boolean_t on; +cnpollc(boolean_t on) { if (mouse_in_use) { if (on) { @@ -449,15 +430,13 @@ boolean_t on; * */ int -kdopen(dev, flag, ior) - dev_t dev; - int flag; - io_req_t ior; +kdopen( + dev_t dev, + int flag, + io_req_t ior) { struct tty *tp; - void kdstart(); spl_t o_pri; - void kdstop(); tp = &kd_tty; o_pri = spltty(); @@ -498,7 +477,7 @@ kdopen(dev, flag, ior) /*ARGSUSED*/ void kdclose(dev, flag) -int dev; +dev_t dev; int flag; { struct tty *tp; @@ -530,8 +509,8 @@ int flag; /*ARGSUSED*/ int kdread(dev, uio) -int dev; -struct uio *uio; +dev_t dev; +io_req_t uio; { struct tty *tp; @@ -555,8 +534,8 @@ struct uio *uio; /*ARGSUSED*/ int kdwrite(dev, uio) -int dev; -struct uio *uio; +dev_t dev; +io_req_t uio; { return((*linesw[kd_tty.t_line].l_write)(&kd_tty, uio)); } @@ -569,10 +548,10 @@ struct uio *uio; int kdmmap(dev, off, prot) dev_t dev; - off_t off; - int prot; + vm_offset_t off; + vm_prot_t prot; { - if ((u_int) off >= (128*1024)) + if (off >= (128*1024)) return(-1); /* Get page frame number for the page to be mapped. */ @@ -580,19 +559,19 @@ kdmmap(dev, off, prot) } int -kdportdeath(dev, port) - dev_t dev; - mach_port_t port; +kdportdeath( + dev_t dev, + mach_port_t port) { return (tty_portdeath(&kd_tty, (ipc_port_t)port)); } /*ARGSUSED*/ -io_return_t kdgetstat(dev, flavor, data, count) - dev_t dev; - int flavor; - int * data; /* pointer to OUT array */ - natural_t *count; /* OUT */ +io_return_t kdgetstat( + dev_t dev, + int flavor, + int * data, /* pointer to OUT array */ + natural_t *count) /* OUT */ { io_return_t result; @@ -618,11 +597,11 @@ io_return_t kdgetstat(dev, flavor, data, count) } /*ARGSUSED*/ -io_return_t kdsetstat(dev, flavor, data, count) - dev_t dev; - int flavor; - int * data; - natural_t count; +io_return_t kdsetstat( + dev_t dev, + int flavor, + int * data, + natural_t count) { io_return_t result; @@ -655,13 +634,12 @@ io_return_t kdsetstat(dev, flavor, data, count) * on/off value. */ int -kdsetbell(val, flags) -int val; /* on or off */ -int flags; /* flags set for console */ +kdsetbell( + int val, /* on or off */ + int flags) /* flags set for console */ { int err = 0; - if (val == KD_BELLON) kd_bellon(); else if (val == KD_BELLOFF) @@ -672,15 +650,13 @@ int flags; /* flags set for console */ return(err); } - /* * kdgetkbent: * * Get entry from key mapping table. Returns error code, if any. */ int -kdgetkbent(kbent) -struct kbentry * kbent; +kdgetkbent(struct kbentry *kbent) { u_char *cp; spl_t o_pri = SPLKD(); /* probably superfluous */ @@ -700,9 +676,9 @@ struct kbentry * kbent; * Set entry in key mapping table. Return error code, if any. */ int -kdsetkbent(kbent, flags) -struct kbentry * kbent; -int flags; /* flags set for console */ +kdsetkbent( + struct kbentry *kbent, + int flags) /* flags set for console */ { u_char *cp; spl_t o_pri; @@ -732,15 +708,14 @@ int flags; /* flags set for console */ */ /*ARGSUSED*/ void -kdintr(vec) -int vec; +kdintr(int vec) { struct tty *tp; unsigned char c; unsigned char scancode; - int char_idx; + unsigned int char_idx; boolean_t up = FALSE; /* key-up event */ - extern int mouse_in_use; + if (kd_pollc) return; /* kdb polling kbd */ @@ -749,7 +724,8 @@ int vec; tp = &kd_tty; #ifdef old - while ((inb(K_STATUS) & K_OBUF_FUL) == 0); /* this should never loop */ + while ((inb(K_STATUS) & K_OBUF_FUL) == 0) + ; /* this should never loop */ #else /* old */ { /* @@ -818,7 +794,7 @@ int vec; set_kd_state(do_modifier(kd_state, c, up)); } else if (!up) { /* regular key-down */ - int max; /* max index for char sequence */ + unsigned int max; /* max index for char sequence */ max = char_idx + NUMOUTPUT; char_idx++; @@ -873,7 +849,7 @@ int vec; * drop the ack on the floor. */ void -kd_handle_ack() +kd_handle_ack(void) { switch (kd_ack) { case SET_LEDS: @@ -898,7 +874,7 @@ kd_handle_ack() * Resend a missed keyboard command or data byte. */ void -kd_resend() +kd_resend(void) { if (kd_ack == NOT_WAITING) printf("unexpected RESEND from keyboard\n"); @@ -919,10 +895,10 @@ kd_resend() * output: the new state */ int -do_modifier(state, c, up) -int state; -Scancode c; -boolean_t up; +do_modifier( + int state, + Scancode c, + boolean_t up) { switch (c) { case (K_ALTSC): @@ -984,12 +960,10 @@ boolean_t up; * are still held down. */ boolean_t -kdcheckmagic(scancode) -Scancode scancode; +kdcheckmagic(Scancode scancode) { static int magic_state = KS_NORMAL; /* like kd_state */ boolean_t up = FALSE; - extern int rebootflag; if (scancode == 0x46) /* scroll lock */ /* if (scancode == 0x52) ** insert key */ @@ -1040,9 +1014,9 @@ Scancode scancode; * Return the value for the 2nd index into key_map that * corresponds to the given state. */ -int +unsigned int kdstate2idx(state, extended) -int state; /* bit vector, not a state index */ +unsigned int state; /* bit vector, not a state index */ boolean_t extended; { int state_idx = NORM_STATE; @@ -1081,8 +1055,7 @@ boolean_t extended; * ASSUMES that it is never called from interrupt-driven code. */ void -kdstart(tp) -struct tty *tp; +kdstart(struct tty *tp) { spl_t o_pri; int ch; @@ -1132,9 +1105,9 @@ struct tty *tp; /*ARGSUSED*/ void -kdstop(tp, flags) - register struct tty *tp; - int flags; +kdstop( + struct tty *tp, + int flags) { /* * do nothing - all characters are output by one call to @@ -1159,9 +1132,8 @@ kdstop(tp, flags) * */ void -kdinit() +kdinit(void) { - void kd_xga_init(); unsigned char k_comm; /* keyboard command byte */ if (kd_initialized) @@ -1190,19 +1162,19 @@ kdinit() kd_senddata(k_comm); kd_initialized = TRUE; -#ifdef ENABLE_IMMEDIATE_CONSOLE +#if ENABLE_IMMEDIATE_CONSOLE /* Now that we're set up, we no longer need or want the immediate console. */ { - extern int immediate_console_enable; - immediate_console_enable = 0; + extern boolean_t immediate_console_enable; + immediate_console_enable = FALSE; } /* The immediate console printed stuff at the bottom of the screen rather than at the cursor position, so that's where we should start. */ kd_setpos(ONE_PAGE - ONE_LINE); printf("\n"); -#endif +#endif /* ENABLE_IMMEDIATE_CONSOLE */ cnsetleds(kd_state = KS_NORMAL); /* clear the LEDs AFTER we @@ -1224,7 +1196,7 @@ kdinit() * output : bell is turned off * */ -static unsigned int kd_bellstate = 0; +static boolean_t kd_bellstate = FALSE; void kd_belloff(void * param) @@ -1233,7 +1205,7 @@ kd_belloff(void * param) status = (inb(K_PORTB) & ~(K_SPKRDATA | K_ENABLETMR2)); outb(K_PORTB, status); - kd_bellstate = 0; + kd_bellstate = FALSE; return; } @@ -1248,7 +1220,7 @@ kd_belloff(void * param) * */ void -kd_bellon() +kd_bellon(void) { unsigned char status; @@ -1278,8 +1250,7 @@ kd_bellon() int sit_for_0 = 1; void -kd_putc(ch) -u_char ch; +kd_putc(u_char ch) { if ((!ch) && sit_for_0) return; @@ -1306,7 +1277,7 @@ u_char ch; { kd_bellon(); timeout(kd_belloff, 0, hz/8 ); - kd_bellstate = 1; + kd_bellstate = TRUE; } break; default: @@ -1332,8 +1303,7 @@ u_char ch; * */ void -kd_setpos(newpos) -csrpos_t newpos; +kd_setpos(csrpos_t newpos) { if (newpos > ONE_PAGE) { kd_scrollup(); @@ -1359,7 +1329,7 @@ csrpos_t newpos; * */ void -kd_scrollup() +kd_scrollup(void) { csrpos_t to; csrpos_t from; @@ -1389,7 +1359,7 @@ kd_scrollup() * */ void -kd_scrolldn() +kd_scrolldn(void) { csrpos_t to; csrpos_t from; @@ -1423,7 +1393,7 @@ kd_scrolldn() * */ void -kd_parseesc() +kd_parseesc(void) { u_char *escp; @@ -1495,8 +1465,7 @@ unsigned char color_table[] = { 0, 4, 2, 6, 1, 5, 3, 7, * */ void -kd_parserest(cp) -u_char *cp; +kd_parserest(u_char *cp) { int number[16], npar = 0, i; csrpos_t newpos; @@ -1760,7 +1729,7 @@ u_char *cp; } void -kd_tab() +kd_tab(void) { int i; @@ -1781,7 +1750,7 @@ kd_tab() * */ void -kd_cls() +kd_cls(void) { (*kd_dclear)(0, ONE_PAGE/ONE_SPACE, kd_attr); return; @@ -1799,7 +1768,7 @@ kd_cls() * */ void -kd_home() +kd_home(void) { kd_setpos(0); return; @@ -1816,7 +1785,7 @@ kd_home() * */ void -kd_up() +kd_up(void) { if (kd_curpos < ONE_LINE) kd_scrolldn(); @@ -1836,7 +1805,7 @@ kd_up() * */ void -kd_down() +kd_down(void) { if (kd_curpos >= (ONE_PAGE - ONE_LINE)) kd_scrollup(); @@ -1856,7 +1825,7 @@ kd_down() * */ void -kd_right() +kd_right(void) { if (kd_curpos < (ONE_PAGE - ONE_SPACE)) kd_setpos(kd_curpos + ONE_SPACE); @@ -1878,7 +1847,7 @@ kd_right() * */ void -kd_left() +kd_left(void) { if (0 < kd_curpos) kd_setpos(kd_curpos - ONE_SPACE); @@ -1897,7 +1866,7 @@ kd_left() * */ void -kd_cr() +kd_cr(void) { kd_setpos(BEG_OF_LINE(kd_curpos)); return; @@ -1911,11 +1880,11 @@ kd_cr() * of the screen. * * input : None - * output : Screen is cleared from current cursor postion to bottom + * output : Screen is cleared from current cursor position to bottom * */ void -kd_cltobcur() +kd_cltobcur(void) { csrpos_t start; int count; @@ -1934,11 +1903,11 @@ kd_cltobcur() * of the screen. * * input : None - * output : Screen is cleared from current cursor postion to top + * output : Screen is cleared from current cursor position to top * */ void -kd_cltopcur() +kd_cltopcur(void) { int count; @@ -1958,7 +1927,7 @@ kd_cltopcur() * */ void -kd_cltoecur() +kd_cltoecur(void) { csrpos_t i; csrpos_t hold; @@ -1981,7 +1950,7 @@ kd_cltoecur() * */ void -kd_clfrbcur() +kd_clfrbcur(void) { csrpos_t i; @@ -2002,8 +1971,7 @@ kd_clfrbcur() * */ void -kd_delln(number) -int number; +kd_delln(int number) { csrpos_t to; csrpos_t from; @@ -2041,8 +2009,7 @@ int number; * */ void -kd_insln(number) -int number; +kd_insln(int number) { csrpos_t to; csrpos_t from; @@ -2081,12 +2048,11 @@ int number; * */ void -kd_delch(number) -int number; +kd_delch(int number) { - int count; /* num words moved/filled */ - int delbytes; /* bytes to delete */ - register csrpos_t to; + int count; /* num words moved/filled */ + int delbytes; /* bytes to delete */ + csrpos_t to; csrpos_t from; csrpos_t nextline; /* start of next line */ @@ -2123,8 +2089,7 @@ int number; * */ void -kd_erase(number) -int number; +kd_erase(int number) { csrpos_t i; csrpos_t stop; @@ -2149,7 +2114,7 @@ int number; * */ void -kd_eraseln() +kd_eraseln(void) { csrpos_t i; csrpos_t stop; @@ -2173,8 +2138,7 @@ kd_eraseln() * */ void -kd_insch(number) -int number; +kd_insch(int number) { csrpos_t to; csrpos_t from; @@ -2215,8 +2179,7 @@ int number; * */ boolean_t -kd_isupper(c) -u_char c; +kd_isupper(u_char c) { if (('A' <= c) && (c <= 'Z')) return(TRUE); @@ -2224,8 +2187,7 @@ u_char c; } boolean_t -kd_islower(c) -u_char c; +kd_islower(u_char c) { if (('a' <= c) && (c <= 'z')) return(TRUE); @@ -2242,10 +2204,10 @@ u_char c; * */ void -kd_senddata(ch) -unsigned char ch; +kd_senddata(unsigned char ch) { - while (inb(K_STATUS) & K_IBUF_FUL); + while (inb(K_STATUS) & K_IBUF_FUL) + ; outb(K_RDWR, ch); last_sent = ch; return; @@ -2260,10 +2222,10 @@ unsigned char ch; * */ void -kd_sendcmd(ch) -unsigned char ch; +kd_sendcmd(unsigned char ch) { - while (inb(K_STATUS) & K_IBUF_FUL); + while (inb(K_STATUS) & K_IBUF_FUL) + ; outb(K_CMD, ch); return; } @@ -2277,41 +2239,47 @@ unsigned char ch; * read. */ unsigned char -kd_getdata() +kd_getdata(void) { - while ((inb(K_STATUS) & K_OBUF_FUL) == 0); + while ((inb(K_STATUS) & K_OBUF_FUL) == 0) + ; return(inb(K_RDWR)); } unsigned char -kd_cmdreg_read() +kd_cmdreg_read(void) { int ch=KC_CMD_READ; - while (inb(K_STATUS) & K_IBUF_FUL); + while (inb(K_STATUS) & K_IBUF_FUL) + ; outb(K_CMD, ch); - while ((inb(K_STATUS) & K_OBUF_FUL) == 0); + while ((inb(K_STATUS) & K_OBUF_FUL) == 0) + ; return(inb(K_RDWR)); } void -kd_cmdreg_write(val) +kd_cmdreg_write(int val) { int ch=KC_CMD_WRITE; - while (inb(K_STATUS) & K_IBUF_FUL); + while (inb(K_STATUS) & K_IBUF_FUL) + ; outb(K_CMD, ch); - while (inb(K_STATUS) & K_IBUF_FUL); + while (inb(K_STATUS) & K_IBUF_FUL) + ; outb(K_RDWR, val); } void -kd_mouse_drain() +kd_mouse_drain(void) { int i; - while(inb(K_STATUS) & K_IBUF_FUL); + while(inb(K_STATUS) & K_IBUF_FUL) + ; while((i = inb(K_STATUS)) & K_OBUF_FUL) printf("kbd: S = %x D = %x\n", i, inb(K_RDWR)); } @@ -2322,8 +2290,7 @@ kd_mouse_drain() * Set kd_state and update the keyboard status LEDs. */ void -set_kd_state(newstate) -int newstate; +set_kd_state(int newstate) { kd_state = newstate; kd_setleds1(state2leds(newstate)); @@ -2336,8 +2303,7 @@ int newstate; * a state vector. */ u_char -state2leds(state) -int state; +state2leds(int state) { u_char result = 0; @@ -2354,8 +2320,7 @@ int state; * Set the keyboard LEDs according to the given byte. */ void -kd_setleds1(val) -u_char val; +kd_setleds1(u_char val) { if (kd_ack != NOT_WAITING) { #ifdef MACH_KBD @@ -2370,7 +2335,7 @@ u_char val; } void -kd_setleds2() +kd_setleds2(void) { kd_senddata(kd_nextled); } @@ -2384,8 +2349,7 @@ kd_setleds2() * lock anyway. */ void -cnsetleds(val) -u_char val; +cnsetleds(u_char val) { kd_senddata(K_CMD_LEDS); (void)kd_getdata(); /* XXX - assume is ACK */ @@ -2394,7 +2358,7 @@ u_char val; } void -kdreboot() +kdreboot(void) { (*kd_dreset)(); @@ -2413,7 +2377,7 @@ static int which_button[] = {0, MOUSE_LEFT, MOUSE_MIDDLE, MOUSE_RIGHT}; static struct mouse_motion moved; int -kd_kbd_magic(scancode) +kd_kbd_magic(int scancode) { int new_button = 0; @@ -2507,14 +2471,18 @@ int new_button = 0; * Initialization specific to character-based graphics adapters. */ void -kd_xga_init() +kd_xga_init(void) { csrpos_t xga_getpos(); unsigned char screen; + unsigned char start, stop; outb(CMOS_ADDR, CMOS_EB); screen = inb(CMOS_DATA) & CM_SCRMSK; switch(screen) { + default: + printf("kd: unknown screen type, defaulting to EGA\n"); + /* FALLTHROUGH */ case CM_EGA_VGA: /* * Here we'll want to query to bios on the card @@ -2540,6 +2508,8 @@ kd_xga_init() addr[i] = 0x00; } break; +#if 0 + /* XXX: some buggy BIOSes report these... */ case CM_CGA_40: vid_start = (u_char *)phystokv(CGA_START); kd_index_reg = CGA_IDX_REG; @@ -2561,8 +2531,25 @@ kd_xga_init() kd_lines = 25; kd_cols = 80; break; - default: - printf("kd: unknown screen type, defaulting to EGA\n"); +#endif + } + + outb(kd_index_reg, C_START); + start = inb(kd_io_reg); + /* Make sure cursor is enabled */ + start &= ~0x20; + outb(kd_io_reg, start); + outb(kd_index_reg, C_STOP); + stop = inb(kd_io_reg); + + if (!start && !stop) + { + /* Some firmware seem not to be initializing the cursor size + * any more... Try using standard values. */ + outb(kd_index_reg, C_START); + outb(kd_io_reg, 14); + outb(kd_index_reg, C_STOP); + outb(kd_io_reg, 15); } kd_setpos(xga_getpos()); @@ -2580,7 +2567,7 @@ kd_xga_init() * */ csrpos_t -xga_getpos() +xga_getpos(void) { unsigned char low; @@ -2683,38 +2670,24 @@ char chattr; * No-op reset routine for kd_dreset. */ static void -kd_noopreset() +kd_noopreset(void) { } - -/* - * Generic routines for bitmap devices (i.e., assume no hardware - * assist). Assumes a simple byte ordering (i.e., a byte at a lower - * address is to the left of the byte at the next higher address). - * For the 82786, this works anyway if the characters are 2 bytes - * wide. (more bubble gum and paper clips.) - * - * See the comments above about SLAMBPW. - */ - -void bmpch2bit(), bmppaintcsr(); -u_char *bit2fbptr(); - - /* * bmpput: Copy a character from the font to the frame buffer. */ void -bmpput(pos, ch, chattr) -csrpos_t pos; -char ch, chattr; +bmpput( + csrpos_t pos, + char ch, + char chattr) { short xbit, ybit; /* u/l corner of char pos */ - register u_char *to, *from; - register short i, j; + u_char *to, *from; + short i, j; u_char mask = (chattr == KA_REVERSE ? 0xff : 0); if ((u_char)ch >= chars_in_font) @@ -2736,13 +2709,14 @@ char ch, chattr; * another. */ void -bmpcp1char(from, to) -csrpos_t from, to; +bmpcp1char( + csrpos_t from, + csrpos_t to) { short from_xbit, from_ybit; short to_xbit, to_ybit; - register u_char *tp, *fp; - register short i, j; + u_char *tp, *fp; + short i, j; bmpch2bit(from, &from_xbit, &from_ybit); bmpch2bit(to, &to_xbit, &to_ybit); @@ -2762,9 +2736,10 @@ csrpos_t from, to; * bmpvmup: Copy a block of character positions upwards. */ void -bmpmvup(from, to, count) -csrpos_t from, to; -int count; +bmpmvup( + csrpos_t from, + csrpos_t to, + int count) { short from_xbit, from_ybit; short to_xbit, to_ybit; @@ -2797,9 +2772,10 @@ int count; * bmpmvdown: copy a block of characters down. */ void -bmpmvdown(from, to, count) -csrpos_t from, to; -int count; +bmpmvdown( + csrpos_t from, + csrpos_t to, + int count) { short from_xbit, from_ybit; short to_xbit, to_ybit; @@ -2835,12 +2811,12 @@ int count; * bmpclear: clear one or more character positions. */ void -bmpclear(to, count, chattr) -csrpos_t to; /* 1st char */ -int count; /* num chars */ -char chattr; /* reverse or normal */ +bmpclear( + csrpos_t to, /* 1st char */ + int count, /* num chars */ + char chattr) /* reverse or normal */ { - register short i; + short i; u_short clearval; u_short clearbyte = (chattr == KA_REVERSE ? char_white : char_black); @@ -2861,8 +2837,7 @@ char chattr; /* reverse or normal */ * bmpsetcursor: update the display and set the logical cursor. */ void -bmpsetcursor(pos) -csrpos_t pos; +bmpsetcursor(csrpos_t pos) { /* erase old cursor & paint new one */ bmppaintcsr(kd_curpos, char_black); @@ -2874,13 +2849,13 @@ csrpos_t pos; * bmppaintcsr: paint cursor bits. */ void -bmppaintcsr(pos, val) -csrpos_t pos; -u_char val; +bmppaintcsr( + csrpos_t pos, + u_char val) { short xbit, ybit; - register u_char *cp; - register short line, byte; + u_char *cp; + short line, byte; bmpch2bit(pos, &xbit, &ybit); ybit += char_height; /* position at bottom of line */ @@ -2897,11 +2872,12 @@ u_char val; * (0, 0) is the upper left corner. */ void -bmpch2bit(pos, xb, yb) -csrpos_t pos; -short *xb, *yb; /* x, y bit positions, u/l corner */ +bmpch2bit( + csrpos_t pos, + short *xb, + short *yb) /* x, y bit positions, u/l corner */ { - register short xch, ych; + short xch, ych; xch = (pos / ONE_SPACE) % kd_cols; ych = pos / (ONE_SPACE * kd_cols); @@ -2916,8 +2892,9 @@ short *xb, *yb; /* x, y bit positions, u/l corner */ * byte. */ u_char * -bit2fbptr(xb, yb) -short xb, yb; +bit2fbptr( + short xb, + short yb) { return(vid_start + yb * fb_byte_width + xb/8); } @@ -3052,6 +3029,39 @@ kdcnmaygetc(void) #ifdef notdef cnsetleds(state2leds(kd_state)); #endif + } else if (! up + && c == K_ESC + && key_map[scancode][char_idx+1] == 0x5b) { + /* As a convenience for the nice + people using our debugger, remap + some keys to the readline-like + shortcuts supported by dde. + + XXX This is a workaround for the + limited kernel getchar interface. + It is only used by the debugger. */ + c = key_map[scancode][char_idx+2]; + switch (c) { +#define _MAP(A,B,C) (C) +#define MAP(T) _MAP(T) +#define CTRL(c) ((c) & 0x1f) + case MAP(K_HOME): c = CTRL('a'); break; + case MAP(K_UA): c = CTRL('p'); break; + case MAP(K_LA): c = CTRL('b'); break; + case MAP(K_RA): c = CTRL('f'); break; + case MAP(K_DA): c = CTRL('n'); break; + case MAP(K_END): c = CTRL('e'); break; + /* delete */ + case 0x39: c = CTRL('d'); break; +#undef CTRL +#undef MAP +#undef _MAP + default: + /* Retain the old behavior. */ + c = K_ESC; + } + + return(c); } else if (!up) { /* regular key-down */ if (c == K_CR) diff --git a/i386/i386at/kd.h b/i386/i386at/kd.h index 1d53538b..0cfed695 100644 --- a/i386/i386at/kd.h +++ b/i386/i386at/kd.h @@ -76,7 +76,10 @@ WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include <sys/types.h> #include <sys/time.h> #include <device/cons.h> - +#include <device/io_req.h> +#include <device/buf.h> +#include <device/tty.h> +#include <i386at/kdsoft.h> /* * Where memory for various graphics adapters starts. @@ -110,6 +113,8 @@ WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. /* * Commands sent to graphics adapter. */ +#define C_START 0x0a /* return cursor line start */ +#define C_STOP 0x0b /* return cursor line stop */ #define C_LOW 0x0f /* return low byte of cursor addr */ #define C_HIGH 0x0e /* high byte */ @@ -359,10 +364,10 @@ typedef u_char Scancode; * Other mappable non-Ascii keys (e.g., "ctrl") are represented by a * two-byte sequence: K_SCAN, followed by the key's scan code. */ -#define K_DONE 0xff /* must be same as NC */ -#define NC 0xff /* No character defined */ +#define K_DONE 0xffu /* must be same as NC */ +#define NC 0xffu /* No character defined */ -#define K_SCAN 0xfe /* followed by scan code */ +#define K_SCAN 0xfeu /* followed by scan code */ /* ascii char set */ #define K_NUL 0x00 /* Null character */ @@ -728,13 +733,14 @@ extern int kdsetbell (int, int); extern void kd_resend (void); extern void kd_handle_ack (void); extern int kd_kbd_magic (int); -extern int kdstate2idx (int, boolean_t); +extern unsigned int kdstate2idx (unsigned int, boolean_t); extern void kd_parserest (u_char *); extern int kdcnprobe(struct consdev *cp); extern int kdcninit(struct consdev *cp); extern int kdcngetc(dev_t dev, int wait); extern int kdcnmaygetc (void); extern int kdcnputc(dev_t dev, int c); +extern void kd_setpos(csrpos_t newpos); extern void kd_slmwd (void *start, int count, int value); extern void kd_slmscu (void *from, void *to, int count); @@ -742,4 +748,53 @@ extern void kd_slmscd (void *from, void *to, int count); extern void kdintr(int vec); +#if MACH_KDB +extern void kdb_kintr(void); +#endif /* MACH_KDB */ + +extern int kdopen(dev_t dev, int flag, io_req_t ior); +extern void kdclose(dev_t dev, int flag); +extern int kdread(dev_t dev, io_req_t uio); +extern int kdwrite(dev_t dev, io_req_t uio); + +extern io_return_t kdgetstat( + dev_t dev, + int flavor, + int *data, + natural_t *count); + +extern io_return_t kdsetstat( + dev_t dev, + int flavor, + int * data, + natural_t count); + +extern int kdportdeath(dev_t dev, mach_port_t port); +extern int kdmmap(dev_t dev, vm_offset_t off, vm_prot_t prot); + +boolean_t kdcheckmagic(Scancode scancode); + +int do_modifier(int state, Scancode c, boolean_t up); + +/* + * Generic routines for bitmap devices (i.e., assume no hardware + * assist). Assumes a simple byte ordering (i.e., a byte at a lower + * address is to the left of the byte at the next higher address). + * For the 82786, this works anyway if the characters are 2 bytes + * wide. (more bubble gum and paper clips.) + * + * See the comments above (in i386at/kd.c) about SLAMBPW. + */ +void bmpch2bit(csrpos_t pos, short *xb, short *yb); +void bmppaintcsr(csrpos_t pos, u_char val); +u_char *bit2fbptr(short xb, short yb); + +unsigned char kd_getdata(void); +unsigned char state2leds(int state); + +void kdstart(struct tty *tp); +void kdstop(struct tty *tp, int flags); + +void kd_xga_init(void); + #endif /* _KD_H_ */ diff --git a/i386/i386at/kd_event.c b/i386/i386at/kd_event.c index 4d2ea008..694c165e 100644 --- a/i386/i386at/kd_event.c +++ b/i386/i386at/kd_event.c @@ -83,11 +83,6 @@ WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. kd_event_queue kbd_queue; /* queue of keyboard events */ queue_head_t kbd_read_queue = { &kbd_read_queue, &kbd_read_queue }; - -void kbd_enqueue(); -io_return_t X_kdb_enter_init(); -io_return_t X_kdb_exit_init(); - static boolean_t initialized = FALSE; @@ -96,7 +91,7 @@ static boolean_t initialized = FALSE; */ void -kbdinit() +kbdinit(void) { spl_t s = SPLKD(); @@ -115,9 +110,10 @@ kbdinit() /*ARGSUSED*/ int -kbdopen(dev, flags) +kbdopen(dev, flags, ior) dev_t dev; int flags; + io_req_t ior; { spl_t o_pri = spltty(); kdinit(); @@ -135,9 +131,9 @@ kbdopen(dev, flags) /*ARGSUSED*/ void -kbdclose(dev, flags) - dev_t dev; - int flags; +kbdclose( + dev_t dev, + int flags) { spl_t s = SPLKD(); @@ -147,11 +143,11 @@ kbdclose(dev, flags) } -io_return_t kbdgetstat(dev, flavor, data, count) - dev_t dev; - int flavor; - int * data; /* pointer to OUT array */ - unsigned int *count; /* OUT */ +io_return_t kbdgetstat( + dev_t dev, + int flavor, + int * data, /* pointer to OUT array */ + unsigned int *count) /* OUT */ { switch (flavor) { case KDGKBDTYPE: @@ -169,11 +165,11 @@ io_return_t kbdgetstat(dev, flavor, data, count) return (D_SUCCESS); } -io_return_t kbdsetstat(dev, flavor, data, count) - dev_t dev; - int flavor; - int * data; - unsigned int count; +io_return_t kbdsetstat( + dev_t dev, + int flavor, + int * data, + unsigned int count) { switch (flavor) { case KDSKBDMODE: @@ -187,9 +183,9 @@ io_return_t kbdsetstat(dev, flavor, data, count) kd_setleds1 (*data); break; case K_X_KDB_ENTER: - return X_kdb_enter_init(data, count); + return X_kdb_enter_init((unsigned int *)data, count); case K_X_KDB_EXIT: - return X_kdb_exit_init(data, count); + return X_kdb_exit_init((unsigned int *)data, count); default: return (D_INVALID_OPERATION); } @@ -201,16 +197,13 @@ io_return_t kbdsetstat(dev, flavor, data, count) /* * kbdread - dequeue and return any queued events. */ - -boolean_t kbd_read_done(); /* forward */ - int -kbdread(dev, ior) - dev_t dev; - register io_req_t ior; +kbdread( + dev_t dev, + io_req_t ior) { - register int err, count; - register spl_t s; + int err, count; + spl_t s; /* Check if IO_COUNT is a multiple of the record size. */ if (ior->io_count % sizeof(kd_event) != 0) @@ -233,7 +226,7 @@ kbdread(dev, ior) } count = 0; while (!kdq_empty(&kbd_queue) && count < ior->io_count) { - register kd_event *ev; + kd_event *ev; ev = kdq_get(&kbd_queue); *(kd_event *)(&ior->io_data[count]) = *ev; @@ -244,11 +237,10 @@ kbdread(dev, ior) return (D_SUCCESS); } -boolean_t kbd_read_done(ior) - register io_req_t ior; +boolean_t kbd_read_done(io_req_t ior) { - register int count; - register spl_t s; + int count; + spl_t s; s = SPLKD(); if (kdq_empty(&kbd_queue)) { @@ -260,7 +252,7 @@ boolean_t kbd_read_done(ior) count = 0; while (!kdq_empty(&kbd_queue) && count < ior->io_count) { - register kd_event *ev; + kd_event *ev; ev = kdq_get(&kbd_queue); *(kd_event *)(&ior->io_data[count]) = *ev; @@ -281,8 +273,7 @@ boolean_t kbd_read_done(ior) */ void -kd_enqsc(sc) - Scancode sc; +kd_enqsc(Scancode sc) { kd_event ev; @@ -299,16 +290,15 @@ kd_enqsc(sc) */ void -kbd_enqueue(ev) - kd_event *ev; +kbd_enqueue(kd_event *ev) { if (kdq_full(&kbd_queue)) - printf("kbd: queue full\n"); + printf_once("kbd: queue full\n"); else kdq_put(&kbd_queue, ev); { - register io_req_t ior; + io_req_t ior; while ((ior = (io_req_t)dequeue_head(&kbd_read_queue)) != 0) iodone(ior); } @@ -319,9 +309,9 @@ int X_kdb_enter_len = 0, X_kdb_exit_len = 0; void kdb_in_out(p) -u_int *p; +const u_int *p; { -register int t = p[0]; + int t = p[0]; switch (t & K_X_TYPE) { case K_X_IN|K_X_BYTE: @@ -351,9 +341,9 @@ register int t = p[0]; } void -X_kdb_enter() +X_kdb_enter(void) { -register u_int *u_ip, *endp; + u_int *u_ip, *endp; for (u_ip = X_kdb_enter_str, endp = &X_kdb_enter_str[X_kdb_enter_len]; u_ip < endp; @@ -362,9 +352,9 @@ register u_int *u_ip, *endp; } void -X_kdb_exit() +X_kdb_exit(void) { -register u_int *u_ip, *endp; + u_int *u_ip, *endp; for (u_ip = X_kdb_exit_str, endp = &X_kdb_exit_str[X_kdb_exit_len]; u_ip < endp; @@ -373,9 +363,9 @@ register u_int *u_ip, *endp; } io_return_t -X_kdb_enter_init(data, count) - u_int *data; - u_int count; +X_kdb_enter_init( + u_int *data, + u_int count) { if (count * sizeof X_kdb_enter_str[0] > sizeof X_kdb_enter_str) return D_INVALID_OPERATION; @@ -386,9 +376,9 @@ X_kdb_enter_init(data, count) } io_return_t -X_kdb_exit_init(data, count) - u_int *data; - u_int count; +X_kdb_exit_init( + u_int *data, + u_int count) { if (count * sizeof X_kdb_exit_str[0] > sizeof X_kdb_exit_str) return D_INVALID_OPERATION; diff --git a/i386/i386at/kd_event.h b/i386/i386at/kd_event.h index 677af99b..8b2d6642 100644 --- a/i386/i386at/kd_event.h +++ b/i386/i386at/kd_event.h @@ -26,8 +26,37 @@ #ifndef _KD_EVENT_H_ #define _KD_EVENT_H_ +#include <sys/types.h> +#include <device/io_req.h> +#include <i386at/kd.h> + extern void X_kdb_enter (void); extern void X_kdb_exit (void); +extern int kbdopen(dev_t dev, int flags, io_req_t ior); +extern void kbdclose(dev_t dev, int flags); +extern int kbdread(dev_t dev, io_req_t ior); + +extern io_return_t kbdgetstat( + dev_t dev, + int flavor, + int *data, + unsigned int *count); + +extern io_return_t kbdsetstat( + dev_t dev, + int flavor, + int *data, + unsigned int count); + +extern void kd_enqsc(Scancode sc); + +void kbd_enqueue(kd_event *ev); + +io_return_t X_kdb_enter_init(u_int *data, u_int count); +io_return_t X_kdb_exit_init(u_int *data, u_int count); + +boolean_t kbd_read_done(io_req_t ior); + #endif /* _KD_EVENT_H_ */ diff --git a/i386/i386at/kd_mouse.c b/i386/i386at/kd_mouse.c index 6e7b68a8..0f1881f4 100644 --- a/i386/i386at/kd_mouse.c +++ b/i386/i386at/kd_mouse.c @@ -101,8 +101,6 @@ u_char lastbuttons; /* previous state of mouse buttons */ #define MOUSE_DOWN 0 #define MOUSE_ALL_UP 0x7 -void mouseintr(); -void mouse_enqueue(); int mouse_baud = BCNT1200; boolean_t mouse_char_cmd = FALSE; /* mouse response is to cmd */ @@ -114,7 +112,7 @@ int mouse_char_index; /* mouse response */ * init_mouse_hw - initialize the serial port. */ void -init_mouse_hw(unit, mode) +init_mouse_hw(dev_t unit, int mode) { unsigned short base_addr = cominfo[unit]->address; @@ -149,9 +147,10 @@ int track_man[10]; /*ARGSUSED*/ int -mouseopen(dev, flags) +mouseopen(dev, flags, ior) dev_t dev; int flags; + io_req_t ior; { if (mouse_in_use) return (D_ALREADY_OPEN); @@ -164,6 +163,7 @@ mouseopen(dev, flags) mousebufsize = 3; serial_mouse_open(dev); init_mouse_hw(dev&7, LC7); + break; case MICROSOFT_MOUSE: mousebufsize = 3; serial_mouse_open(dev); @@ -198,8 +198,7 @@ mouseopen(dev, flags) } void -serial_mouse_open(dev) - dev_t dev; +serial_mouse_open(dev_t dev) { int unit = minor(dev) & 0x7; int mouse_pic = cominfo[unit]->sysdep1; @@ -219,12 +218,11 @@ serial_mouse_open(dev) int mouse_packets = 0; void -kd_mouse_open(dev, mouse_pic) - dev_t dev; - int mouse_pic; +kd_mouse_open( + dev_t dev, + int mouse_pic) { spl_t s = splhi(); /* disable interrupts */ - extern void kdintr(); oldvect = ivect[mouse_pic]; ivect[mouse_pic] = kdintr; @@ -239,9 +237,9 @@ kd_mouse_open(dev, mouse_pic) * and restore the serial port interrupt vector. */ void -mouseclose(dev, flags) - dev_t dev; - int flags; +mouseclose( + dev_t dev, + int flags) { switch (mouse_type) { case MICROSOFT_MOUSE: @@ -266,9 +264,9 @@ mouseclose(dev, flags) /*ARGSUSED*/ void -serial_mouse_close(dev, flags) - dev_t dev; - int flags; +serial_mouse_close( + dev_t dev, + int flags) { spl_t o_pri = splhi(); /* mutex with open() */ int unit = minor(dev) & 0x7; @@ -285,9 +283,9 @@ serial_mouse_close(dev, flags) } void -kd_mouse_close(dev, mouse_pic) - dev_t dev; - int mouse_pic; +kd_mouse_close( + dev_t dev, + int mouse_pic) { spl_t s = splhi(); @@ -297,11 +295,11 @@ kd_mouse_close(dev, mouse_pic) splx(s); } -io_return_t mousegetstat(dev, flavor, data, count) - dev_t dev; - int flavor; - int * data; /* pointer to OUT array */ - unsigned int *count; /* OUT */ +io_return_t mousegetstat( + dev_t dev, + int flavor, + int * data, /* pointer to OUT array */ + unsigned int *count) /* OUT */ { switch (flavor) { case DEV_GET_SIZE: @@ -319,15 +317,13 @@ io_return_t mousegetstat(dev, flavor, data, count) /* * mouseread - dequeue and return any queued events. */ -boolean_t mouse_read_done(); /* forward */ - int -mouseread(dev, ior) - dev_t dev; - register io_req_t ior; +mouseread( + dev_t dev, + io_req_t ior) { - register int err, count; - register spl_t s; + int err, count; + spl_t s; /* Check if IO_COUNT is a multiple of the record size. */ if (ior->io_count % sizeof(kd_event) != 0) @@ -350,7 +346,7 @@ mouseread(dev, ior) } count = 0; while (!kdq_empty(&mouse_queue) && count < ior->io_count) { - register kd_event *ev; + kd_event *ev; ev = kdq_get(&mouse_queue); *(kd_event *)(&ior->io_data[count]) = *ev; @@ -361,11 +357,10 @@ mouseread(dev, ior) return (D_SUCCESS); } -boolean_t mouse_read_done(ior) - register io_req_t ior; +boolean_t mouse_read_done(io_req_t ior) { - register int count; - register spl_t s; + int count; + spl_t s; s = SPLKD(); if (kdq_empty(&mouse_queue)) { @@ -377,7 +372,7 @@ boolean_t mouse_read_done(ior) count = 0; while (!kdq_empty(&mouse_queue) && count < ior->io_count) { - register kd_event *ev; + kd_event *ev; ev = kdq_get(&mouse_queue); *(kd_event *)(&ior->io_data[count]) = *ev; @@ -397,7 +392,7 @@ boolean_t mouse_read_done(ior) * mouseintr - Get a byte and pass it up for handling. Called at SPLKD. */ void -mouseintr(unit) +mouseintr(int unit) { unsigned short base_addr = cominfo[unit]->address; unsigned char id, ls; @@ -445,8 +440,7 @@ int middlegitech = 0; /* what should the middle button be */ static u_char mousebuf[MOUSEBUFSIZE]; /* 5-byte packet from mouse */ void -mouse_handle_byte(ch) - u_char ch; +mouse_handle_byte(u_char ch) { if (show_mouse_byte) { printf("%x(%c) ", ch, ch); @@ -527,8 +521,7 @@ mouse_handle_byte(ch) } void -mouse_packet_mouse_system_mouse(mousebuf) -u_char mousebuf[MOUSEBUFSIZE]; +mouse_packet_mouse_system_mouse(u_char mousebuf[MOUSEBUFSIZE]) { u_char buttons, buttonchanges; struct mouse_motion moved; @@ -563,8 +556,7 @@ u_char mousebuf[MOUSEBUFSIZE]; * */ void -mouse_packet_microsoft_mouse(mousebuf) -u_char mousebuf[MOUSEBUFSIZE]; +mouse_packet_microsoft_mouse(u_char mousebuf[MOUSEBUFSIZE]) { u_char buttons, buttonchanges; struct mouse_motion moved; @@ -656,8 +648,7 @@ void kd_mouse_read_reset(void) } void -ibm_ps2_mouse_open(dev) - dev_t dev; +ibm_ps2_mouse_open(dev_t dev) { spl_t s = spltty(); @@ -700,8 +691,7 @@ ibm_ps2_mouse_open(dev) } void -ibm_ps2_mouse_close(dev) - dev_t dev; +ibm_ps2_mouse_close(dev_t dev) { spl_t s = spltty(); @@ -732,8 +722,7 @@ ibm_ps2_mouse_close(dev) * */ void -mouse_packet_ibm_ps2_mouse(mousebuf) -u_char mousebuf[MOUSEBUFSIZE]; +mouse_packet_ibm_ps2_mouse(u_char mousebuf[MOUSEBUFSIZE]) { u_char buttons, buttonchanges; struct mouse_motion moved; @@ -765,8 +754,7 @@ u_char mousebuf[MOUSEBUFSIZE]; * Enqueue a mouse-motion event. Called at SPLKD. */ void -mouse_moved(where) - struct mouse_motion where; +mouse_moved(struct mouse_motion where) { kd_event ev; @@ -776,14 +764,13 @@ mouse_moved(where) mouse_enqueue(&ev); } - /* * Enqueue an event for mouse button press or release. Called at SPLKD. */ void -mouse_button(which, direction) - kev_type which; - u_char direction; +mouse_button( + kev_type which, + u_char direction) { kd_event ev; @@ -793,23 +780,21 @@ mouse_button(which, direction) mouse_enqueue(&ev); } - /* * mouse_enqueue - enqueue an event and wake up selecting processes, if * any. Called at SPLKD. */ void -mouse_enqueue(ev) - kd_event *ev; +mouse_enqueue(kd_event *ev) { if (kdq_full(&mouse_queue)) - printf("mouse: queue full\n"); + printf_once("mouse: queue full\n"); else kdq_put(&mouse_queue, ev); { - register io_req_t ior; + io_req_t ior; while ((ior = (io_req_t)dequeue_head(&mouse_read_queue)) != 0) iodone(ior); } diff --git a/i386/i386at/kd_mouse.h b/i386/i386at/kd_mouse.h index baa51c8a..a8a72a3b 100644 --- a/i386/i386at/kd_mouse.h +++ b/i386/i386at/kd_mouse.h @@ -54,4 +54,17 @@ extern void mouse_packet_mouse_system_mouse (u_char *mousebuf); extern void mouse_packet_ibm_ps2_mouse (u_char *mousebuf); +extern int mouseopen(dev_t dev, int flags, io_req_t ior); +extern void mouseclose(dev_t dev, int flags); +extern int mouseread(dev_t dev, io_req_t ior); + +extern io_return_t mousegetstat( + dev_t dev, + int flavor, + int *data, + unsigned int *count); + +void mouseintr(int unit); +boolean_t mouse_read_done(io_req_t ior); + #endif /* _KD_MOUSE_H_ */ diff --git a/i386/i386at/kd_queue.c b/i386/i386at/kd_queue.c index 2b83044a..57d6fbf7 100644 --- a/i386/i386at/kd_queue.c +++ b/i386/i386at/kd_queue.c @@ -72,14 +72,14 @@ WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. boolean_t kdq_empty(q) - kd_event_queue *q; + const kd_event_queue *q; { return(q->firstfree == q->firstout); } boolean_t kdq_full(q) - kd_event_queue *q; + const kd_event_queue *q; { return(q_next(q->firstfree) == q->firstout); } @@ -98,8 +98,7 @@ kdq_put(q, ev) } kd_event * -kdq_get(q) - kd_event_queue *q; +kdq_get(kd_event_queue *q) { kd_event *result = q->events + q->firstout; @@ -108,8 +107,7 @@ kdq_get(q) } void -kdq_reset(q) - kd_event_queue *q; +kdq_reset(kd_event_queue *q) { q->firstout = q->firstfree = 0; } diff --git a/i386/i386at/kd_queue.h b/i386/i386at/kd_queue.h index c976acfa..702efe8a 100644 --- a/i386/i386at/kd_queue.h +++ b/i386/i386at/kd_queue.h @@ -64,6 +64,9 @@ WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * /dev/mouse. */ +#ifndef _KD_QUEUE_H_ +#define _KD_QUEUE_H_ + #include <mach/std_types.h> #include <i386at/kd.h> @@ -76,6 +79,8 @@ typedef struct { extern void kdq_put(kd_event_queue *, kd_event *); extern void kdq_reset(kd_event_queue *); -extern boolean_t kdq_empty(kd_event_queue *); -extern boolean_t kdq_full(kd_event_queue *); +extern boolean_t kdq_empty(const kd_event_queue *); +extern boolean_t kdq_full(const kd_event_queue *); extern kd_event *kdq_get(kd_event_queue *); + +#endif /* _KD_QUEUE_H_ */ diff --git a/i386/i386at/kdsoft.h b/i386/i386at/kdsoft.h index 96e2df8c..1dfd2b2c 100644 --- a/i386/i386at/kdsoft.h +++ b/i386/i386at/kdsoft.h @@ -57,6 +57,9 @@ NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUR OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#ifndef _KDSOFT_H_ +#define _KDSOFT_H_ + /* * Globals used for both character-based controllers and bitmap-based * controllers. @@ -203,3 +206,5 @@ extern short xstart, ystart; extern short char_byte_width; /* char_width/8 */ extern short fb_byte_width; /* fb_width/8 */ extern short font_byte_width; /* num bytes in 1 scan line of font */ + +#endif /* _KDSOFT_H_ */ diff --git a/i386/i386at/lpr.c b/i386/i386at/lpr.c index c92795ef..5c16b153 100644 --- a/i386/i386at/lpr.c +++ b/i386/i386at/lpr.c @@ -44,20 +44,12 @@ #include <i386/pio.h> #include <chips/busses.h> #include <i386at/autoconf.h> -#include <i386at/lprreg.h> +#include <i386at/lpr.h> - /* * Driver information for auto-configuration stuff. */ -int lprprobe(); -void lprstop(); -void lprintr(), lprstart(); -void lprattach(struct bus_device *); -int lprgetstat(), lprsetstat(); -void lprpr_addr(); - struct bus_device *lprinfo[NLPR]; /* ??? */ static vm_offset_t lpr_std[NLPR] = { 0 }; @@ -71,7 +63,8 @@ int lpr_alive[NLPR]; int lprprobe(port, dev) -struct bus_device *dev; +vm_offset_t port; +struct bus_ctlr *dev; { u_short addr = (u_short) dev->address; int unit = dev->unit; @@ -113,7 +106,7 @@ void lprattach(struct bus_device *dev) int lpropen(dev, flag, ior) -int dev; +dev_t dev; int flag; io_req_t ior; { @@ -142,7 +135,7 @@ u_short addr; void lprclose(dev, flag) -int dev; +dev_t dev; int flag; { int unit = minor(dev); @@ -158,7 +151,7 @@ u_short addr = (u_short) lprinfo[unit]->address; int lprread(dev, ior) -int dev; +dev_t dev; io_req_t ior; { return char_read(&lpr_tty[minor(dev)], ior); @@ -166,7 +159,7 @@ io_req_t ior; int lprwrite(dev, ior) -int dev; +dev_t dev; io_req_t ior; { return char_write(&lpr_tty[minor(dev)], ior); @@ -199,11 +192,11 @@ natural_t *count; /* out */ } io_return_t -lprsetstat(dev, flavor, data, count) -dev_t dev; -int flavor; -int * data; -natural_t count; +lprsetstat( + dev_t dev, + int flavor, + int * data, + natural_t count) { io_return_t result = D_SUCCESS; int unit = minor(dev); @@ -218,10 +211,9 @@ natural_t count; return (D_SUCCESS); } -void lprintr(unit) -int unit; +void lprintr(int unit) { - register struct tty *tp = &lpr_tty[unit]; + struct tty *tp = &lpr_tty[unit]; if ((tp->t_state & TS_ISOPEN) == 0) return; @@ -233,8 +225,7 @@ int unit; lprstart(tp); } -void lprstart(tp) -struct tty *tp; +void lprstart(struct tty *tp) { spl_t s = spltty(); u_short addr = (natural_t) tp->t_addr; @@ -274,22 +265,22 @@ struct tty *tp; } void -lprstop(tp, flags) -register struct tty *tp; -int flags; +lprstop( + struct tty *tp, + int flags) { if ((tp->t_state & TS_BUSY) && (tp->t_state & TS_TTSTOP) == 0) tp->t_state |= TS_FLUSH; } int -lprpr(unit) +lprpr(int unit) { lprpr_addr(lprinfo[unit]->address); return 0; } void -lprpr_addr(addr) +lprpr_addr(unsigned short addr) { printf("DATA(%x) %x, STATUS(%x) %x, INTR_ENAB(%x) %x\n", DATA(addr), inb(DATA(addr)), diff --git a/i386/i386at/lprreg.h b/i386/i386at/lpr.h index c6fbed43..269fd643 100644 --- a/i386/i386at/lprreg.h +++ b/i386/i386at/lpr.h @@ -27,7 +27,40 @@ * Parallel port printer driver v1.0 * All rights reserved. */ + +#ifndef _LPRREG_H_ +#define _LPRREG_H_ #define DATA(addr) (addr + 0) #define STATUS(addr) (addr + 1) #define INTR_ENAB(addr) (addr + 2) + +extern void lprintr(int unit); +int lprprobe(vm_offset_t port, struct bus_ctlr *dev); +void lprstop(struct tty *tp, int flags); +void lprstart(struct tty *tp); +void lprattach(struct bus_device *dev); + +extern io_return_t +lprgetstat( + dev_t dev, + int flavor, + int *data, + natural_t *count); + +extern io_return_t +lprsetstat( + dev_t dev, + int flavor, + int *data, + natural_t count); + +void lprpr_addr(unsigned short addr); + +extern int lpropen(dev_t dev, int flag, io_req_t ior); +extern void lprclose(dev_t dev, int flag); +extern int lprread(dev_t dev, io_req_t ior); +extern int lprwrite(dev_t dev, io_req_t ior); +extern int lprportdeath(dev_t dev, mach_port_t port); + +#endif /* _LPRREG_H_ */ diff --git a/i386/i386at/mem.c b/i386/i386at/mem.c index 5e51676b..f239afac 100644 --- a/i386/i386at/mem.c +++ b/i386/i386at/mem.c @@ -32,7 +32,7 @@ /*ARGSUSED*/ int memmmap(dev, off, prot) -int dev; +dev_t dev; vm_offset_t off; vm_prot_t prot; { diff --git a/i386/i386at/mem.h b/i386/i386at/mem.h new file mode 100644 index 00000000..0bc85ea4 --- /dev/null +++ b/i386/i386at/mem.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2013 Free Software Foundation. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef _MEM_H_ +#define _MEM_H_ + +extern int memmmap(dev_t dev, vm_offset_t off, vm_prot_t prot); + +#endif /* _MEM_H_ */ diff --git a/i386/i386at/model_dep.c b/i386/i386at/model_dep.c index 3db03d76..fdf983b9 100644 --- a/i386/i386at/model_dep.c +++ b/i386/i386at/model_dep.c @@ -48,6 +48,7 @@ #include <kern/debug.h> #include <kern/mach_clock.h> #include <kern/printf.h> +#include <kern/startup.h> #include <sys/time.h> #include <sys/types.h> #include <vm/vm_page.h> @@ -67,6 +68,8 @@ #include <i386at/int_init.h> #include <i386at/kd.h> #include <i386at/rtc.h> +#include <i386at/model_dep.h> +#include <i386at/acpihalt.h> #ifdef MACH_XEN #include <xen/console.h> #include <xen/store.h> @@ -74,14 +77,29 @@ #include <xen/xen.h> #endif /* MACH_XEN */ +#if ENABLE_IMMEDIATE_CONSOLE +#include "immc.h" +#endif /* ENABLE_IMMEDIATE_CONSOLE */ + /* Location of the kernel's symbol table. Both of these are 0 if none is available. */ #if MACH_KDB +#include <ddb/db_sym.h> +#include <i386/db_interface.h> + +/* a.out symbol table */ static vm_offset_t kern_sym_start, kern_sym_end; -#else + +/* ELF section header */ +static unsigned elf_shdr_num; +static vm_size_t elf_shdr_size; +static vm_offset_t elf_shdr_addr; +static unsigned elf_shdr_shndx; + +#else /* MACH_KDB */ #define kern_sym_start 0 #define kern_sym_end 0 -#endif +#endif /* MACH_KDB */ /* These indicate the total extent of physical memory addresses we're using. They are page-aligned. */ @@ -123,14 +141,8 @@ static vm_size_t avail_remaining; extern char version[]; -extern void setup_main(); - -void halt_all_cpus (boolean_t reboot) __attribute__ ((noreturn)); -void halt_cpu (void) __attribute__ ((noreturn)); - -void inittodr(); /* forward */ - -int rebootflag = 0; /* exported to kdintr */ +/* If set, reboot the system on ctrl-alt-delete. */ +boolean_t rebootflag = FALSE; /* exported to kdintr */ /* XX interrupt stack pointer and highwater mark, for locore.S. */ vm_offset_t int_stack_top, int_stack_high; @@ -139,8 +151,6 @@ vm_offset_t int_stack_top, int_stack_high; extern void linux_init(void); #endif -boolean_t init_alloc_aligned(vm_size_t size, vm_offset_t *addrp); - /* * Find devices. The system is alive. */ @@ -184,10 +194,14 @@ void machine_init(void) *(unsigned short *)phystokv(0x472) = 0x1234; #endif /* MACH_HYP */ +#if VM_MIN_KERNEL_ADDRESS == 0 /* * Unmap page 0 to trap NULL references. + * + * Note that this breaks accessing some BIOS areas stored there. */ pmap_unmap_page_zero(); +#endif } /* Conserve power on processor CPU. */ @@ -201,7 +215,7 @@ void machine_idle (int cpu) #endif /* MACH_HYP */ } -void machine_relax () +void machine_relax (void) { asm volatile ("rep; nop" : : : "memory"); } @@ -223,8 +237,7 @@ void halt_cpu(void) /* * Halt the system or reboot. */ -void halt_all_cpus(reboot) - boolean_t reboot; +void halt_all_cpus(boolean_t reboot) { if (reboot) { #ifdef MACH_HYP @@ -233,10 +246,11 @@ void halt_all_cpus(reboot) kdreboot(); } else { - rebootflag = 1; + rebootflag = TRUE; #ifdef MACH_HYP hyp_halt(); #endif /* MACH_HYP */ + grub_acpi_halt(); printf("In tight loop: hit ctl-alt-del to reboot\n"); (void) spl0(); } @@ -249,6 +263,11 @@ void exit(int rc) halt_all_cpus(0); } +void db_halt_cpu(void) +{ + halt_all_cpus(0); +} + void db_reset_cpu(void) { halt_all_cpus(1); @@ -274,14 +293,44 @@ mem_size_init(void) } else phys_last_addr = boot_info.nr_pages * 0x1000; #else /* MACH_HYP */ - /* TODO: support mmap */ - vm_size_t phys_last_kb = 0x400 + boot_info.mem_upper; - /* Avoid 4GiB overflow. */ - if (phys_last_kb < 0x400 || phys_last_kb >= 0x400000) { - printf("Truncating memory size to 4GiB\n"); - phys_last_addr = 0xffffffffU; - } else - phys_last_addr = phys_last_kb * 0x400; + vm_size_t phys_last_kb; + + if (boot_info.flags & MULTIBOOT_MEM_MAP) { + struct multiboot_mmap *map, *map_end; + + map = (void*) phystokv(boot_info.mmap_addr); + map_end = (void*) map + boot_info.mmap_count; + + while (map + 1 <= map_end) { + if (map->Type == MB_ARD_MEMORY) { + unsigned long long start = map->BaseAddr, end = map->BaseAddr + map->Length;; + + if (start >= 0x100000000ULL) { + printf("Ignoring %luMiB RAM region above 4GiB\n", (unsigned long) (map->Length >> 20)); + } else { + if (end >= 0x100000000ULL) { + printf("Truncating memory region to 4GiB\n"); + end = 0x0ffffffffU; + } + if (end > phys_last_addr) + phys_last_addr = end; + + printf("AT386 boot: physical memory map from 0x%lx to 0x%lx\n", + (unsigned long) start, + (unsigned long) end); + } + } + map = (void*) map + map->size + sizeof(map->size); + } + } else { + phys_last_kb = 0x400 + boot_info.mem_upper; + /* Avoid 4GiB overflow. */ + if (phys_last_kb < 0x400 || phys_last_kb >= 0x400000) { + printf("Truncating memory size to 4GiB\n"); + phys_last_addr = 0xffffffffU; + } else + phys_last_addr = phys_last_kb * 0x400; + } #endif /* MACH_HYP */ printf("AT386 boot: physical memory from 0x%lx to 0x%lx\n", @@ -292,7 +341,7 @@ mem_size_init(void) max_phys_size = VM_MAX_KERNEL_ADDRESS - VM_MIN_KERNEL_ADDRESS - VM_KERNEL_MAP_SIZE; if (phys_last_addr - phys_first_addr > max_phys_size) { phys_last_addr = phys_first_addr + max_phys_size; - printf("Truncating memory size to %luMiB\n", (phys_last_addr - phys_first_addr) / (1024 * 1024)); + printf("Truncating memory to %luMiB\n", (phys_last_addr - phys_first_addr) / (1024 * 1024)); /* TODO Xen: be nice, free lost memory */ } @@ -344,7 +393,7 @@ i386at_init(void) int len = strlen ((char*)phystokv(boot_info.cmdline)) + 1; assert(init_alloc_aligned(round_page(len), &addr)); kernel_cmdline = (char*) phystokv(addr); - memcpy(kernel_cmdline, (char*)phystokv(boot_info.cmdline), len); + memcpy(kernel_cmdline, (void *)phystokv(boot_info.cmdline), len); boot_info.cmdline = addr; } @@ -496,6 +545,10 @@ i386at_init(void) */ void c_boot_entry(vm_offset_t bi) { +#if ENABLE_IMMEDIATE_CONSOLE + romputc = immc_romputc; +#endif /* ENABLE_IMMEDIATE_CONSOLE */ + /* Stash the boot_image_info pointer. */ boot_info = *(typeof(boot_info)*)phystokv(bi); int cpu_type; @@ -535,6 +588,17 @@ void c_boot_entry(vm_offset_t bi) kern_sym_start, kern_sym_end, symtab_size, strtab_size); } + + if ((boot_info.flags & MULTIBOOT_ELF_SHDR) + && boot_info.syms.e.num) + { + elf_shdr_num = boot_info.syms.e.num; + elf_shdr_size = boot_info.syms.e.size; + elf_shdr_addr = (vm_offset_t)phystokv(boot_info.syms.e.addr); + elf_shdr_shndx = boot_info.syms.e.shndx; + + printf("ELF section header table at %08lx\n", elf_shdr_addr); + } #endif /* MACH_KDB */ #endif /* MACH_XEN */ @@ -551,7 +615,14 @@ void c_boot_entry(vm_offset_t bi) */ if (kern_sym_start) { - aout_db_sym_init(kern_sym_start, kern_sym_end, "mach", 0); + aout_db_sym_init((char *)kern_sym_start, (char *)kern_sym_end, "mach", (char *)0); + } + + if (elf_shdr_num) + { + elf_db_sym_init(elf_shdr_num,elf_shdr_size, + elf_shdr_addr, elf_shdr_shndx, + "mach", NULL); } #endif /* MACH_KDB */ @@ -590,15 +661,13 @@ void c_boot_entry(vm_offset_t bi) #include <mach/time_value.h> int -timemmap(dev,off,prot) +timemmap(dev, off, prot) + dev_t dev; + vm_offset_t off; vm_prot_t prot; { extern time_value_t *mtime; -#ifdef lint - dev++; off++; -#endif /* lint */ - if (prot & VM_PROT_WRITE) return (-1); return (i386_btop(pmap_extract(pmap_kernel(), (vm_offset_t) mtime))); @@ -710,7 +779,56 @@ init_alloc_aligned(vm_size_t size, vm_offset_t *addrp) #ifndef MACH_HYP /* Skip past the I/O and ROM area. */ - if ((avail_next > (boot_info.mem_lower * 0x400)) && (addr < 0x100000)) + if (boot_info.flags & MULTIBOOT_MEM_MAP) + { + struct multiboot_mmap *map, *map_end, *current = NULL, *next = NULL; + unsigned long long minimum_next = ~0ULL; + + map = (void*) phystokv(boot_info.mmap_addr); + map_end = (void*) map + boot_info.mmap_count; + + /* Find both our current map, and the next one */ + while (map + 1 <= map_end) + { + if (map->Type == MB_ARD_MEMORY) + { + unsigned long long start = map->BaseAddr; + unsigned long long end = start + map->Length;; + + if (start <= addr && avail_next <= end) + { + /* Ok, fits in the current map */ + current = map; + break; + } + else if (avail_next <= start && start < minimum_next) + { + /* This map is not far from avail_next */ + next = map; + minimum_next = start; + } + } + map = (void*) map + map->size + sizeof(map->size); + } + + if (!current) { + /* Area does not fit in the current map, switch to next + * map if any */ + if (!next || next->BaseAddr >= phys_last_addr) + { + /* No further reachable map, we have reached + * the end of memory, but possibly wrap around + * 16MiB. */ + avail_next = phys_last_addr; + goto retry; + } + + /* Start from next map */ + avail_next = next->BaseAddr; + goto retry; + } + } + else if ((avail_next > (boot_info.mem_lower * 0x400)) && (addr < 0x100000)) { avail_next = 0x100000; goto retry; @@ -762,8 +880,7 @@ init_alloc_aligned(vm_size_t size, vm_offset_t *addrp) return TRUE; } -boolean_t pmap_next_page(addrp) - vm_offset_t *addrp; +boolean_t pmap_next_page(vm_offset_t *addrp) { return init_alloc_aligned(PAGE_SIZE, addrp); } @@ -780,8 +897,7 @@ pmap_grab_page(void) return addr; } -boolean_t pmap_valid_page(x) - vm_offset_t x; +boolean_t pmap_valid_page(vm_offset_t x) { /* XXX is this OK? What does it matter for? */ return (((phys_first_addr <= x) && (x < phys_last_addr)) diff --git a/i386/i386at/model_dep.h b/i386/i386at/model_dep.h new file mode 100644 index 00000000..aa240320 --- /dev/null +++ b/i386/i386at/model_dep.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2013 Free Software Foundation. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef _MODEL_DEP_H_ +#define _MODEL_DEP_H_ + +#include <mach/vm_prot.h> + +extern int timemmap(dev_t dev, vm_offset_t off, vm_prot_t prot); + +void inittodr(void); + +boolean_t init_alloc_aligned(vm_size_t size, vm_offset_t *addrp); + +#endif /* _MODEL_DEP_H_ */ diff --git a/i386/i386at/pic_isa.c b/i386/i386at/pic_isa.c index e48fb507..0b36534e 100644 --- a/i386/i386at/pic_isa.c +++ b/i386/i386at/pic_isa.c @@ -28,10 +28,10 @@ #include <i386/ipl.h> #include <i386/pic.h> #include <i386/fpu.h> +#include <i386/hardclock.h> #include <i386at/kd.h> /* These interrupts are always present */ -extern void hardclock(); void (*ivect[NINTR])() = { /* 00 */ hardclock, /* always */ diff --git a/i386/i386at/rtc.c b/i386/i386at/rtc.c index 67768013..01e09772 100644 --- a/i386/i386at/rtc.c +++ b/i386/i386at/rtc.c @@ -53,10 +53,10 @@ WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include <i386/pio.h> #include <i386at/rtc.h> -static int first_rtcopen_ever = 1; +static boolean_t first_rtcopen_ever = TRUE; void -rtcinit() +rtcinit(void) { outb(RTC_ADDR, RTC_A); outb(RTC_DATA, RTC_DIV2 | RTC_RATE6); @@ -66,12 +66,12 @@ rtcinit() int -rtcget(regs) -unsigned char *regs; +rtcget(struct rtc_st *st) { + unsigned char *regs = (unsigned char *)st; if (first_rtcopen_ever) { rtcinit(); - first_rtcopen_ever = 0; + first_rtcopen_ever = FALSE; } outb(RTC_ADDR, RTC_D); if ((inb(RTC_DATA) & RTC_VRT) == 0) return(-1); @@ -83,14 +83,14 @@ unsigned char *regs; } void -rtcput(regs) -unsigned char *regs; +rtcput(struct rtc_st *st) { - register unsigned char x; + unsigned char *regs = (unsigned char *)st; + unsigned char x; if (first_rtcopen_ever) { rtcinit(); - first_rtcopen_ever = 0; + first_rtcopen_ever = FALSE; } outb(RTC_ADDR, RTC_B); x = inb(RTC_DATA); @@ -103,34 +103,29 @@ unsigned char *regs; extern struct timeval time; -extern struct timezone tz; static int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int -yeartoday(year) -int year; +yeartoday(int year) { return((year%4) ? 365 : 366); } int -hexdectodec(n) -char n; +hexdectodec(char n) { return(((n>>4)&0x0F)*10 + (n&0x0F)); } char -dectohexdec(n) -int n; +dectohexdec(int n) { return((char)(((n/10)<<4)&0xF0) | ((n%10)&0x0F)); } int -readtodc(tp) - u_int *tp; +readtodc(u_int *tp) { struct rtc_st rtclk; time_t n; @@ -172,7 +167,7 @@ readtodc(tp) } int -writetodc() +writetodc(void) { struct rtc_st rtclk; time_t n; diff --git a/i386/i386at/rtc.h b/i386/i386at/rtc.h index ced39b98..97eabe95 100644 --- a/i386/i386at/rtc.h +++ b/i386/i386at/rtc.h @@ -45,6 +45,9 @@ NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#ifndef _RTC_H_ +#define _RTC_H_ + #define RTC_ADDR 0x70 /* I/O port address for register select */ #define RTC_DATA 0x71 /* I/O port address for data read/write */ @@ -114,7 +117,7 @@ struct rtc_st { */ #define load_rtc(regs) \ {\ - register int i; \ + int i; \ \ for (i = 0; i < RTC_NREG; i++) { \ outb(RTC_ADDR, i); \ @@ -127,7 +130,7 @@ struct rtc_st { */ #define save_rtc(regs) \ { \ - register int i; \ + int i; \ for (i = 0; i < RTC_NREGP; i++) { \ outb(RTC_ADDR, i); \ outb(RTC_DATA, regs[i]);\ @@ -136,3 +139,5 @@ struct rtc_st { extern int readtodc(u_int *tp); extern int writetodc(void); + +#endif /* _RTC_H_ */ |