Commit 5aded270 authored by marco_g's avatar marco_g

2003-12-03 Marco Gerards <metgerards@student.han.nl>

	* fs/ext2.c (pupa_ext2_label): New function.
	(pupa_ext2_fs): Added label.
	* fs/fat.c (pupa_fat_label): New function.
	(pupa_fat_fs): Added label.
	* include/pupa/fs.h (struct pupa_fs): Added prototype label.

	* kern/misc.c (pupa_strndup): New function.
	* include/pupa/misc.h (pupa_strndup): New prototype.

	* include/pupa/normal.h: Include <pupa/err.h>.
	(pupa_set_history): New prototype.
	(pupa_iterate_commands): New prototype.
	* normal/cmdline.c: Include <pupa/machine/partition.h>,
	<pupa/disk.h>, <pupa/file.h>.
	(hist_size): New variable.
	(hist_lines): Likewise.
	(hist_end): Likewise.
	(hist_used): Likewise.
	(pupa_set_history): New function.
	(pupa_history_get): Likewise.
	(pupa_history_add): Likewise.
	(pupa_history_replace): Likewise.
	(pupa_tab_complete): Likewise.
	(pupa_cmdline_run): Added tab completion and history buffer.  Tab
	completion shows partitionnames while completing partitions, this
	feature was suggested by Jeff Bailey.
	* normal/command.c (pupa_iterate_commands): New function.
	* normal/main.c (PUPA_DEFAULT_HISTORY_SIZE): New macro.
	(pupa_normal_init): Initialize history buffer.
	(PUPA_MOD_INIT): Likewise.
	(pupa_normal_fini): Free the history buffer.
	(PUPA_MOD_FINI): Likewise.

	* util/console.c (pupa_ncurses_getkey): Accept 127 as backspace
	key.

	* aclocal.m4 (pupa_I386_CHECK_REGPARM_BUG): New DEFUN.
	* configure.ac [i386]: Check for regparam bug.
	(NESTED_FUNC_ATTR) [! i386]: Defined.
parent 1f7315a3
2003-12-03 Marco Gerards <metgerards@student.han.nl>
* fs/ext2.c (pupa_ext2_label): New function.
(pupa_ext2_fs): Added label.
* fs/fat.c (pupa_fat_label): New function.
(pupa_fat_fs): Added label.
* include/pupa/fs.h (struct pupa_fs): Added prototype label.
* kern/misc.c (pupa_strndup): New function.
* include/pupa/misc.h (pupa_strndup): New prototype.
* include/pupa/normal.h: Include <pupa/err.h>.
(pupa_set_history): New prototype.
(pupa_iterate_commands): New prototype.
* normal/cmdline.c: Include <pupa/machine/partition.h>,
<pupa/disk.h>, <pupa/file.h>.
(hist_size): New variable.
(hist_lines): Likewise.
(hist_end): Likewise.
(hist_used): Likewise.
(pupa_set_history): New function.
(pupa_history_get): Likewise.
(pupa_history_add): Likewise.
(pupa_history_replace): Likewise.
(pupa_tab_complete): Likewise.
(pupa_cmdline_run): Added tab completion and history buffer. Tab
completion shows partitionnames while completing partitions, this
feature was suggested by Jeff Bailey.
* normal/command.c (pupa_iterate_commands): New function.
* normal/main.c (PUPA_DEFAULT_HISTORY_SIZE): New macro.
(pupa_normal_init): Initialize history buffer.
(PUPA_MOD_INIT): Likewise.
(pupa_normal_fini): Free the history buffer.
(PUPA_MOD_FINI): Likewise.
* util/console.c (pupa_ncurses_getkey): Accept 127 as backspace
key.
* aclocal.m4 (pupa_I386_CHECK_REGPARM_BUG): New DEFUN.
* configure.ac [i386]: Check for regparam bug.
(NESTED_FUNC_ATTR) [! i386]: Defined.
2003-11-17 Marco Gerards <metgerards@student.han.nl>
* conf/i386-pc.rmk (sbin_UTILITIES): Added pupa-emu.
......
......@@ -290,3 +290,42 @@ else
AC_MSG_ERROR([neither end nor _end is defined])
fi
])
dnl Check if the C compiler has a bug while using nested functions when
dnl mregparm is used on the i386. Some gcc versions do not pass the third
dnl parameter correctly to the nested function.
dnl Written by Marco Gerards.
AC_DEFUN(pupa_I386_CHECK_REGPARM_BUG,
[AC_REQUIRE([AC_PROG_CC])
AC_MSG_CHECKING([if GCC has the regparm=3 bug])
AC_CACHE_VAL(pupa_cv_i386_check_nested_functions,
[AC_RUN_IFELSE([AC_LANG_SOURCE(
[[int *p;
int
main ()
{
int test;
int __attribute__ ((__regparm__ (3))) nestedfunc (int a, int b, int c)
{
return (&test == p);
}
p = &test;
return nestedfunc (0, 0, 0);
}
]])],
[pupa_cv_i386_check_nested_functions=yes],
[pupa_cv_i386_check_nested_functions=no])])
AC_MSG_RESULT([$pupa_cv_i386_check_nested_functions])
if test "x$pupa_cv_i386_check_nested_functions" = xyes; then
AC_DEFINE([NESTED_FUNC_ATTR],
[__attribute__ ((__regparm__ (2)))],
[Catch gcc bug])
else
AC_DEFINE([NESTED_FUNC_ATTR], [], [Catch gcc bug])
fi
])
......@@ -49,6 +49,9 @@
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
/* Catch gcc bug */
#undef NESTED_FUNC_ATTR
/* Define to the address where bug reports for this package should be sent. */
#undef PACKAGE_BUGREPORT
......
......@@ -3253,8 +3253,92 @@ fi
echo "$as_me:$LINENO: result: $pupa_cv_i386_asm_absolute_without_asterisk" >&5
echo "${ECHO_T}$pupa_cv_i386_asm_absolute_without_asterisk" >&6
echo "$as_me:$LINENO: checking if GCC has the regparm=3 bug" >&5
echo $ECHO_N "checking if GCC has the regparm=3 bug... $ECHO_C" >&6
if test "${pupa_cv_i386_check_nested_functions+set}" = set; then
echo $ECHO_N "(cached) $ECHO_C" >&6
else
if test "$cross_compiling" = yes; then
{ { echo "$as_me:$LINENO: error: cannot run test program while cross compiling
See \`config.log' for more details." >&5
echo "$as_me: error: cannot run test program while cross compiling
See \`config.log' for more details." >&2;}
{ (exit 1); exit 1; }; }
else
cat >conftest.$ac_ext <<_ACEOF
#line $LINENO "configure"
/* confdefs.h. */
_ACEOF
cat confdefs.h >>conftest.$ac_ext
cat >>conftest.$ac_ext <<_ACEOF
/* end confdefs.h. */
int *p;
int
main ()
{
int test;
int __attribute__ ((__regparm__ (3))) nestedfunc (int a, int b, int c)
{
return (&test == p);
}
p = &test;
return nestedfunc (0, 0, 0);
}
_ACEOF
rm -f conftest$ac_exeext
if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
(eval $ac_link) 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } && { ac_try='./conftest$ac_exeext'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); }; }; then
pupa_cv_i386_check_nested_functions=yes
else
echo "$as_me: program exited with status $ac_status" >&5
echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
( exit $ac_status )
pupa_cv_i386_check_nested_functions=no
fi
rm -f core core.* *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
fi
fi
echo "$as_me:$LINENO: result: $pupa_cv_i386_check_nested_functions" >&5
echo "${ECHO_T}$pupa_cv_i386_check_nested_functions" >&6
if test "x$pupa_cv_i386_check_nested_functions" = xyes; then
cat >>confdefs.h <<\_ACEOF
#define NESTED_FUNC_ATTR __attribute__ ((__regparm__ (2)))
_ACEOF
else
cat >>confdefs.h <<\_ACEOF
#define NESTED_FUNC_ATTR
_ACEOF
fi
else
cat >>confdefs.h <<\_ACEOF
#define NESTED_FUNC_ATTR
_ACEOF
fi
# Find a good install program. We prefer a C program (faster),
# so one script is as good as another. But avoid the broken or
......
......@@ -88,9 +88,11 @@ if test "x$host_cpu" = xi386; then
pupa_I386_ASM_PREFIX_REQUIREMENT
pupa_I386_ASM_ADDR32
pupa_I386_ASM_ABSOLUTE_WITHOUT_ASTERISK
pupa_I386_CHECK_REGPARM_BUG
else
AC_DEFINE([NESTED_FUNC_ATTR], [],[Catch gcc bug])
fi
AC_PROG_INSTALL
AC_PROG_MAKE_SET
AC_CHECK_TOOL(OBJCOPY, objcopy)
......
......@@ -687,6 +687,31 @@ pupa_ext2_dir (pupa_device_t device, const char *path,
return pupa_errno;
}
static pupa_err_t
pupa_ext2_label (pupa_device_t device, char **label)
{
struct pupa_ext2_data *data;
pupa_disk_t disk = device->disk;
#ifndef PUPA_UTIL
pupa_dl_ref (my_mod);
#endif
data = pupa_ext2_mount (disk);
if (data)
*label = pupa_strndup (data->sblock.volume_name, 14);
else
*label = 0;
#ifndef PUPA_UTIL
pupa_dl_unref (my_mod);
#endif
pupa_free (data);
return pupa_errno;
}
static struct pupa_fs pupa_ext2_fs =
{
......@@ -695,6 +720,7 @@ static struct pupa_fs pupa_ext2_fs =
.open = pupa_ext2_open,
.read = pupa_ext2_read,
.close = pupa_ext2_close,
.label = pupa_ext2_label,
.next = 0
};
......
......@@ -3,6 +3,7 @@
* PUPA -- Preliminary Universal Programming Architecture for GRUB
* Copyright (C) 2000,2001 Free Software Foundation, Inc.
* Copyright (C) 2002 Yoshinori K. Okuji <okuji@enbug.org>
* Copyright (C) 2003 Marco Gerards <metgerards@student.han.nl>.
*
* 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
......@@ -771,6 +772,70 @@ pupa_fat_close (pupa_file_t file)
return pupa_errno;
}
static pupa_err_t
pupa_fat_label (pupa_device_t device, char **label)
{
struct pupa_fat_data *data;
pupa_disk_t disk = device->disk;
pupa_ssize_t offset = -sizeof(struct pupa_fat_dir_entry);
#ifndef PUPA_UTIL
pupa_dl_ref (my_mod);
#endif
data = pupa_fat_mount (disk);
if (! data)
goto fail;
if (! (data->attr & PUPA_FAT_ATTR_DIRECTORY))
{
pupa_error (PUPA_ERR_BAD_FILE_TYPE, "not a directory");
return 0;
}
while (1)
{
struct pupa_fat_dir_entry dir;
/* Adjust the offset. */
offset += sizeof (dir);
/* Read a directory entry. */
if ((pupa_fat_read_data (disk, data, 0,
offset, sizeof (dir), (char *) &dir)
!= sizeof (dir))
|| dir.name[0] == 0)
{
if (pupa_errno != PUPA_ERR_NONE)
goto fail;
else
{
*label = 0;
return PUPA_ERR_NONE;
}
}
if (dir.attr == PUPA_FAT_ATTR_VOLUME_ID)
{
*label = pupa_strndup (dir.name, 11);
return PUPA_ERR_NONE;
}
}
*label = 0;
fail:
#ifndef PUPA_UTIL
pupa_dl_unref (my_mod);
#endif
pupa_free (data);
return pupa_errno;
}
static struct pupa_fs pupa_fat_fs =
{
.name = "fat",
......@@ -778,6 +843,7 @@ static struct pupa_fs pupa_fat_fs =
.open = pupa_fat_open,
.read = pupa_fat_read,
.close = pupa_fat_close,
.label = pupa_fat_label,
.next = 0
};
......
......@@ -2,6 +2,7 @@
/*
* PUPA -- Preliminary Universal Programming Architecture for GRUB
* Copyright (C) 2002 Yoshinori K. Okuji <okuji@enbug.org>
* Copyright (C) 2003 Marco Gerards <metgerards@student.han.nl>.
*
* PUPA is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -46,6 +47,11 @@ struct pupa_fs
/* Close the file FILE. */
pupa_err_t (*close) (struct pupa_file *file);
/* Return the label of the device DEVICE in LABEL. The label is
returned in a pupa_malloc'ed buffer and should be freed by the
caller. */
pupa_err_t (*label) (pupa_device_t device, char **label);
/* The next filesystem. */
struct pupa_fs *next;
......
......@@ -47,6 +47,7 @@ int EXPORT_FUNC(pupa_isalpha) (int c);
int EXPORT_FUNC(pupa_tolower) (int c);
unsigned long EXPORT_FUNC(pupa_strtoul) (const char *str, char **end, int base);
char *EXPORT_FUNC(pupa_strdup) (const char *s);
char *EXPORT_FUNC(pupa_strndup) (const char *s, pupa_size_t n);
void *EXPORT_FUNC(pupa_memset) (void *s, int c, pupa_size_t n);
pupa_size_t EXPORT_FUNC(pupa_strlen) (const char *s);
int EXPORT_FUNC(pupa_printf) (const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
......
......@@ -2,6 +2,7 @@
/*
* PUPA -- Preliminary Universal Programming Architecture for GRUB
* Copyright (C) 2002,2003 Yoshinori K. Okuji <okuji@enbug.org>
* Copyright (C) 2003 Marco Gerards <metgerards@student.han.nl>.
*
* 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
......@@ -23,6 +24,7 @@
#include <pupa/setjmp.h>
#include <pupa/symbol.h>
#include <pupa/err.h>
/* The maximum size of a command-line. */
#define PUPA_MAX_CMDLINE 1600
......@@ -125,6 +127,8 @@ void EXPORT_FUNC(pupa_register_command) (const char *name,
const char *description);
void EXPORT_FUNC(pupa_unregister_command) (const char *name);
pupa_command_t pupa_command_find (char *cmdline);
pupa_err_t pupa_set_history (int newsize);
int pupa_iterate_commands (int (*iterate) (pupa_command_t));
int pupa_command_execute (char *cmdline);
void pupa_command_init (void);
void pupa_normal_init_page (void);
......
......@@ -301,6 +301,23 @@ pupa_strdup (const char *s)
return pupa_memcpy (p, s, len);
}
char *
pupa_strndup (const char *s, pupa_size_t n)
{
pupa_size_t len = 0;
char *p = (char *) s;
while (*(p++) && len < n)
len++;
len = pupa_strlen (s) + 1;
p = (char *) pupa_malloc (len);
if (! p)
return 0;
return pupa_memcpy (p, s, len);
}
void *
pupa_memset (void *s, int c, pupa_size_t n)
{
......
This diff is collapsed.
/*
* PUPA -- Preliminary Universal Programming Architecture for GRUB
* Copyright (C) 2003 Yoshinori K. Okuji <okuji@enbug.org>
* Copyright (C) 2003 Marco Gerards <metgerards@student.han.nl>.
*
* 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
......@@ -95,6 +96,15 @@ pupa_command_find (char *cmdline)
return cmd;
}
int
pupa_iterate_commands (int (*iterate) (pupa_command_t))
{
pupa_command_t cmd;
for (cmd = pupa_command_list; cmd; cmd = cmd->next)
iterate (cmd);
return 0;
}
int
pupa_command_execute (char *cmdline)
{
......
......@@ -3,6 +3,7 @@
* PUPA -- Preliminary Universal Programming Architecture for GRUB
* Copyright (C) 2000,2001,2002 Free Software Foundation, Inc.
* Copyright (C) 2002,2003 Yoshinori K. Okuji <okuji@enbug.org>
* Copyright (C) 2003 Marco Gerards <metgerards@student.han.nl>.
*
* 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
......@@ -30,6 +31,8 @@
pupa_jmp_buf pupa_exit_env;
#define PUPA_DEFAULT_HISTORY_SIZE 50
/* Read a line from the file FILE. */
static int
get_line (pupa_file_t file, char cmdline[], int max_len)
......@@ -332,11 +335,12 @@ pupa_rescue_cmd_normal (int argc, char *argv[])
pupa_enter_normal_mode (argv[0]);
}
#ifdef PUPA_UTIL
void
pupa_normal_init (void)
{
pupa_set_history (PUPA_DEFAULT_HISTORY_SIZE);
/* Register a command "normal" for the rescue mode. */
pupa_rescue_register_command ("normal", pupa_rescue_cmd_normal,
"enter normal mode");
......@@ -349,6 +353,7 @@ pupa_normal_init (void)
void
pupa_normal_fini (void)
{
pupa_set_history (0);
pupa_rescue_unregister_command ("normal");
}
......@@ -358,6 +363,8 @@ PUPA_MOD_INIT
/* Normal mode shouldn't be unloaded. */
pupa_dl_ref (mod);
pupa_set_history (PUPA_DEFAULT_HISTORY_SIZE);
/* Register a command "normal" for the rescue mode. */
pupa_rescue_register_command ("normal", pupa_rescue_cmd_normal,
"enter normal mode");
......@@ -368,6 +375,7 @@ PUPA_MOD_INIT
PUPA_MOD_FINI
{
pupa_set_history (0);
pupa_rescue_unregister_command ("normal");
}
#endif /* ! PUPA_UTIL */
......@@ -95,6 +95,9 @@ pupa_ncurses_getkey (void)
break;
case KEY_BACKSPACE:
/* XXX: For some reason ncurses on xterm does not return
KEY_BACKSPACE. */
case 127:
c = PUPA_CONSOLE_KEY_BACKSPACE;
break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment