summaryrefslogtreecommitdiff
path: root/console-client/vga-support.c
diff options
context:
space:
mode:
authorMarcus Brinkmann <marcus@gnu.org>2002-11-18 07:35:47 +0000
committerMarcus Brinkmann <marcus@gnu.org>2002-11-18 07:35:47 +0000
commitcc2742affd7433812e9a3b5407990700be8ebf55 (patch)
treeff289cebad4ce9210c668e7d10170d052c137886 /console-client/vga-support.c
parentd75b31ece55771c9462336a0a31ae22c68d038c6 (diff)
2002-11-18 Marcus Brinkmann <marcus@gnu.org>
* console.c (main): Pass ERR to error invocation. * generic-speaker.c (generic_spaker_beep): Use currently active beep's next pointer, instead index 0. * pc-kbd.c: New global variables led_state and gnumach_v1_compat. (enum scancode): Change to set 2 encoding. (enum scancode_x1): Likewise. (enum scancode_x2): New type. (sc_to_kc): Change to set 2 encoding. (sc_x1_to_kc): Likewise. (sc_set1_to_set2): New variable. (sc_set1_to_set2_x1): Likewise. (gnumach_v1_input_next): New function. (update_leds): Likewise. (input_next): Likewise. (input_loop): Use input_next or gnumach_v1_input_next to read next key code. (pc_kbd_start): Add support for current GNU Mach @>=kbd interface. Call update_leds and toggle led_state. (pc_kbd_fini): Add support for current GNU Mach. (pc_kbd_set_scroll_lock_status): Toggle led_state and call update_leds. * vga-support.c (vga_init): Add support for current GNU Mach's I/O permission bitmap handling and its mem device.
Diffstat (limited to 'console-client/vga-support.c')
-rw-r--r--console-client/vga-support.c101
1 files changed, 56 insertions, 45 deletions
diff --git a/console-client/vga-support.c b/console-client/vga-support.c
index 717663ce..c7e9e914 100644
--- a/console-client/vga-support.c
+++ b/console-client/vga-support.c
@@ -76,59 +76,70 @@ error_t
vga_init (void)
{
error_t err;
-#if OSKIT_MACH
int fd;
-#else
- device_t device_master = MACH_PORT_NULL;
- memory_object_t kd_mem = MACH_PORT_NULL;
- static device_t kd_device = MACH_PORT_NULL;
- vm_address_t mapped;
-#endif
-#if OSKIT_MACH
+ /* Acquire I/O port access. */
if (ioperm (VGA_MIN_REG, VGA_MAX_REG - VGA_MIN_REG + 1, 1) < 0)
{
- free (vga_state);
- return errno;
+ /* GNU Mach v1 is broken in that it doesn't implement an I/O
+ perm interface and just allows all tasks to access any I/O
+ port. */
+ if (errno != EMIG_BAD_ID && errno != ENOSYS)
+ {
+ free (vga_state);
+ return errno;
+ }
}
fd = open ("/dev/mem", O_RDWR);
- if (fd < 0)
+ if (fd >= 0)
+ {
+ vga_videomem = mmap (0, VGA_VIDEO_MEM_LENGTH, PROT_READ | PROT_WRITE,
+ MAP_SHARED, fd, VGA_VIDEO_MEM_BASE_ADDR);
+ err = errno;
+ close (fd);
+ if (vga_videomem == (void *) -1)
+ return err;
+ }
+ else if (errno == ENXIO)
+ {
+ /* GNU Mach v1 does not provide /dev/mem, but allows direct
+ memory access to the video memory through the special "kd"
+ kernel device. */
+ device_t device_master = MACH_PORT_NULL;
+ memory_object_t kd_mem = MACH_PORT_NULL;
+ static device_t kd_device = MACH_PORT_NULL;
+ vm_address_t mapped;
+
+ err = get_privileged_ports (0, &device_master);
+ if (err)
+ return err;
+
+ err = device_open (device_master, D_WRITE, "kd", &kd_device);
+ if (err)
+ return err;
+
+ err = device_map (kd_device, VM_PROT_READ | VM_PROT_WRITE,
+ VIDMMAP_BEGIN - VIDMMAP_KDOFS, VIDMMAP_SIZE,
+ &kd_mem, 0);
+ if (err)
+ return err;
+
+ err = vm_map (mach_task_self (), &mapped, VIDMMAP_SIZE,
+ 0, 1, kd_mem, VIDMMAP_BEGIN - VIDMMAP_KDOFS, 0,
+ VM_PROT_READ | VM_PROT_WRITE, VM_PROT_READ | VM_PROT_WRITE,
+ VM_INHERIT_NONE);
+ if (err)
+ return err;
+
+ vga_videomem = (char *) mapped;
+ assert (vga_videomem != NULL);
+
+ mach_port_deallocate (mach_task_self (), device_master);
+ mach_port_deallocate (mach_task_self (), kd_mem);
+ }
+ else
return errno;
- vga_videomem = mmap (0, VGA_VIDEO_MEM_LENGTH, PROT_READ | PROT_WRITE,
- MAP_SHARED, fd, VGA_VIDEO_MEM_BASE_ADDR);
- err = errno;
- close (fd);
- if (vga_videomem == (void *) -1)
- return err;
-#else
- err = get_privileged_ports (0, &device_master);
- if (err)
- return err;
-
- err = device_open (device_master, D_WRITE, "kd", &kd_device);
- if (err)
- return err;
-
- err = device_map (kd_device, VM_PROT_READ | VM_PROT_WRITE,
- VIDMMAP_BEGIN - VIDMMAP_KDOFS, VIDMMAP_SIZE,
- &kd_mem, 0);
- if (err)
- return err;
-
- err = vm_map (mach_task_self (), &mapped, VIDMMAP_SIZE,
- 0, 1, kd_mem, VIDMMAP_BEGIN - VIDMMAP_KDOFS, 0,
- VM_PROT_READ | VM_PROT_WRITE, VM_PROT_READ | VM_PROT_WRITE,
- VM_INHERIT_NONE);
- if (err)
- return err;
-
- vga_videomem = (char *) mapped;
- assert (vga_videomem != NULL);
-
- mach_port_deallocate (mach_task_self (), device_master);
- mach_port_deallocate (mach_task_self (), kd_mem);
-#endif
/* Save the current state. */
vga_state = malloc (sizeof (*vga_state));