[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 27/41] boot: Port to x64_64
From: |
Sergey Bugaev |
Subject: |
[PATCH 27/41] boot: Port to x64_64 |
Date: |
Tue, 9 May 2023 00:31:22 +0300 |
---
boot/boot.c | 68 +++++++++++++++++++++++---------------------
boot/boot_script.c | 32 ++++++++++-----------
boot/boot_script.h | 4 +--
boot/userland-boot.c | 11 +++++--
4 files changed, 61 insertions(+), 54 deletions(-)
diff --git a/boot/boot.c b/boot/boot.c
index 144ca1c3..f7935697 100644
--- a/boot/boot.c
+++ b/boot/boot.c
@@ -644,18 +644,18 @@ main (int argc, char **argv, char **envp)
/* Initialize boot script variables. */
if (boot_script_set_variable ("host-port", VAL_PORT,
privileged
- ? (int) privileged_host_port
- : (int) pseudo_privileged_host_port)
+ ? privileged_host_port
+ : pseudo_privileged_host_port)
|| boot_script_set_variable ("device-port", VAL_PORT,
- (integer_t) pseudo_master_device_port)
+ pseudo_master_device_port)
|| boot_script_set_variable ("kernel-task", VAL_PORT,
- (integer_t) pseudo_kernel)
+ pseudo_kernel)
|| boot_script_set_variable ("kernel-command-line", VAL_STR,
- (integer_t) kernel_command_line)
+ (intptr_t) kernel_command_line)
|| boot_script_set_variable ("root-device",
- VAL_STR, (integer_t) bootdevice)
+ VAL_STR, (intptr_t) bootdevice)
|| boot_script_set_variable ("boot-args",
- VAL_STR, (integer_t) bootstrap_args))
+ VAL_STR, (intptr_t) bootstrap_args))
{
static const char msg[] = "error setting variable";
@@ -676,7 +676,7 @@ main (int argc, char **argv, char **envp)
if (eq == 0)
continue;
*eq++ = '\0';
- err = boot_script_set_variable (word, VAL_STR, (integer_t) eq);
+ err = boot_script_set_variable (word, VAL_STR, (intptr_t) eq);
if (err)
{
char *msg;
@@ -1020,7 +1020,7 @@ ds_device_write (device_t device,
dev_mode_t mode,
recnum_t recnum,
io_buf_ptr_t data,
- size_t datalen,
+ mach_msg_type_number_t datalen,
int *bytes_written)
{
if (device == pseudo_console)
@@ -1057,7 +1057,7 @@ ds_device_write_inband (device_t device,
dev_mode_t mode,
recnum_t recnum,
const io_buf_ptr_inband_t data,
- size_t datalen,
+ mach_msg_type_number_t datalen,
int *bytes_written)
{
if (device == pseudo_console)
@@ -1095,8 +1095,9 @@ ds_device_read (device_t device,
recnum_t recnum,
int bytes_wanted,
io_buf_ptr_t *data,
- size_t *datalen)
+ mach_msg_type_number_t *datalen)
{
+ error_t err;
if (device == pseudo_console)
{
int avail;
@@ -1121,8 +1122,6 @@ ds_device_read (device_t device,
}
else
{
- kern_return_t err;
-
unlock_readlock ();
err = queue_read (DEV_READ, reply_port, reply_type, bytes_wanted);
if (err)
@@ -1132,11 +1131,12 @@ ds_device_read (device_t device,
}
else if (device == pseudo_root)
{
- *datalen = 0;
- return
- (store_read (root_store, recnum, bytes_wanted, (void **)data, datalen)
== 0
- ? D_SUCCESS
- : D_IO_ERROR);
+ size_t data_size = 0;
+ err = store_read (root_store, recnum, bytes_wanted, (void **)data,
&data_size);
+ if (err)
+ return D_IO_ERROR;
+ *datalen = data_size;
+ return D_SUCCESS;
}
else
return D_NO_SUCH_DEVICE;
@@ -1150,7 +1150,7 @@ ds_device_read_inband (device_t device,
recnum_t recnum,
int bytes_wanted,
io_buf_ptr_inband_t data,
- size_t *datalen)
+ mach_msg_type_number_t *datalen)
{
if (device == pseudo_console)
{
@@ -1188,17 +1188,18 @@ ds_device_read_inband (device_t device,
{
error_t err;
void *returned = data;
+ size_t data_size = bytes_wanted;
- *datalen = bytes_wanted;
- err =
- store_read (root_store, recnum, bytes_wanted, (void **)&returned,
datalen);
+ err = store_read (root_store, recnum, bytes_wanted,
+ (void **)&returned, &data_size);
+ *datalen = data_size;
if (! err)
{
if (returned != data)
{
- memcpy ((void *)data, returned, *datalen);
- munmap ((caddr_t) returned, *datalen);
+ memcpy ((void *)data, returned, data_size);
+ munmap ((caddr_t) returned, data_size);
}
return D_SUCCESS;
}
@@ -1243,7 +1244,7 @@ kern_return_t
ds_device_set_status (device_t device,
dev_flavor_t flavor,
dev_status_t status,
- size_t statuslen)
+ mach_msg_type_number_t statuslen)
{
if (device != pseudo_console && device != pseudo_root)
return D_NO_SUCH_DEVICE;
@@ -1254,7 +1255,7 @@ kern_return_t
ds_device_get_status (device_t device,
dev_flavor_t flavor,
dev_status_t status,
- size_t *statuslen)
+ mach_msg_type_number_t *statuslen)
{
if (device == pseudo_console)
return D_INVALID_OPERATION;
@@ -1289,7 +1290,7 @@ ds_device_set_filter (device_t device,
mach_port_t receive_port,
int priority,
filter_array_t filter,
- size_t filterlen)
+ mach_msg_type_number_t filterlen)
{
if (device != pseudo_console && device != pseudo_root)
return D_NO_SUCH_DEVICE;
@@ -1663,7 +1664,7 @@ S_io_reauthenticate (mach_port_t object,
{
uid_t *gu, *au;
gid_t *gg, *ag;
- size_t gulen = 0, aulen = 0, gglen = 0, aglen = 0;
+ mach_msg_type_number_t gulen = 0, aulen = 0, gglen = 0, aglen = 0;
error_t err;
/* XXX: This cannot possibly work, authserver is 0. */
@@ -1702,9 +1703,9 @@ S_io_restrict_auth (mach_port_t object,
mach_port_t *newobject,
mach_msg_type_name_t *newobjtype,
const uid_t *uids,
- size_t nuids,
+ mach_msg_type_number_t nuids,
const uid_t *gids,
- size_t ngids)
+ mach_msg_type_number_t ngids)
{
if (object != pseudo_console)
return EOPNOTSUPP;
@@ -2023,7 +2024,7 @@ static void
task_ihash_cleanup (hurd_ihash_value_t value, void *cookie)
{
(void) cookie;
- mach_port_deallocate (mach_task_self (), (mach_port_t) value);
+ mach_port_deallocate (mach_task_self (), (mach_port_t)(uintptr_t) value);
}
static struct hurd_ihash task_ihash =
@@ -2065,7 +2066,8 @@ S_mach_notify_new_task (mach_port_t notify,
mach_port_mod_refs (mach_task_self (), task, MACH_PORT_RIGHT_SEND, +1);
err = hurd_ihash_add (&task_ihash,
- (hurd_ihash_key_t) task, (hurd_ihash_value_t) task);
+ (hurd_ihash_key_t) task,
+ (hurd_ihash_value_t)(uintptr_t) task);
if (err)
{
mach_port_deallocate (mach_task_self (), task);
@@ -2110,7 +2112,7 @@ S_processor_set_tasks(mach_port_t processor_set,
i = 1;
HURD_IHASH_ITERATE (&task_ihash, value)
{
- task_t task = (task_t) value;
+ task_t task = (task_t)(uintptr_t) value;
if (task == pseudo_kernel)
continue;
diff --git a/boot/boot_script.c b/boot/boot_script.c
index 54007e6b..2897d0e7 100644
--- a/boot/boot_script.c
+++ b/boot/boot_script.c
@@ -19,7 +19,7 @@ struct sym
int type;
/* Symbol value. */
- integer_t val;
+ intptr_t val;
/* For function symbols; type of value returned by function. */
int ret_type;
@@ -46,7 +46,7 @@ struct arg
int type;
/* Argument value. */
- integer_t val;
+ intptr_t val;
};
/* List of commands. */
@@ -93,10 +93,10 @@ prompt_resume_task (struct cmd *cmd, int *val)
/* List of builtin symbols. */
static struct sym builtin_symbols[] =
{
- { "task-create", VAL_FUNC, (integer_t) create_task, VAL_TASK, 0 },
- { "task-resume", VAL_FUNC, (integer_t) resume_task, VAL_NONE, 1 },
+ { "task-create", VAL_FUNC, (intptr_t) create_task, VAL_TASK, 0 },
+ { "task-resume", VAL_FUNC, (intptr_t) resume_task, VAL_NONE, 1 },
{ "prompt-task-resume",
- VAL_FUNC, (integer_t) prompt_resume_task, VAL_NONE, 1 },
+ VAL_FUNC, (intptr_t) prompt_resume_task, VAL_NONE, 1 },
};
#define NUM_BUILTIN (sizeof (builtin_symbols) / sizeof (builtin_symbols[0]))
@@ -298,7 +298,7 @@ boot_script_parse_line (void *hook, char *cmdline)
{
char c;
int i, type;
- integer_t val;
+ intptr_t val;
struct sym *s;
/* Parse symbol name. */
@@ -353,7 +353,7 @@ boot_script_parse_line (void *hook, char *cmdline)
if (! s->run_on_exec)
{
(error
- = ((*((int (*) (struct cmd *, integer_t *)) s->val))
+ = ((*((int (*) (struct cmd *, intptr_t *)) s->val))
(cmd, &val)));
if (error)
goto bad;
@@ -375,7 +375,7 @@ boot_script_parse_line (void *hook, char *cmdline)
else if (s->type == VAL_NONE)
{
type = VAL_SYM;
- val = (integer_t) s;
+ val = (intptr_t) s;
}
else
{
@@ -645,7 +645,7 @@ boot_script_exec (void)
for (i = 0; i < cmd->exec_funcs_index; i++)
{
struct sym *sym = cmd->exec_funcs[i];
- int error = ((*((int (*) (struct cmd *, integer_t *)) sym->val))
+ int error = ((*((int (*) (struct cmd *, intptr_t *)) sym->val))
(cmd, 0));
if (error)
{
@@ -662,7 +662,7 @@ boot_script_exec (void)
/* Create an entry for the variable NAME with TYPE and value VAL,
in the symbol table. */
int
-boot_script_set_variable (const char *name, int type, integer_t val)
+boot_script_set_variable (const char *name, int type, intptr_t val)
{
struct sym *sym = sym_enter (name);
@@ -679,14 +679,14 @@ boot_script_set_variable (const char *name, int type,
integer_t val)
int
boot_script_define_function (const char *name, int ret_type,
int (*func) (const struct cmd *cmd,
- integer_t *val))
+ intptr_t *val))
{
struct sym *sym = sym_enter (name);
if (sym)
{
sym->type = VAL_FUNC;
- sym->val = (integer_t) func;
+ sym->val = (intptr_t) func;
sym->ret_type = ret_type;
sym->run_on_exec = ret_type == VAL_NONE;
}
@@ -765,10 +765,10 @@ main (int argc, char **argv)
}
host_port = 1;
device_port = 2;
- boot_script_set_variable ("host-port", VAL_PORT, (int) host_port);
- boot_script_set_variable ("device-port", VAL_PORT, (int) device_port);
- boot_script_set_variable ("root-device", VAL_STR, (int) "hd0a");
- boot_script_set_variable ("boot-args", VAL_STR, (int) "-ad");
+ boot_script_set_variable ("host-port", VAL_PORT, host_port);
+ boot_script_set_variable ("device-port", VAL_PORT, device_port);
+ boot_script_set_variable ("root-device", VAL_STR, (intptr_t) "hd0a");
+ boot_script_set_variable ("boot-args", VAL_STR, (intptr_t) "-ad");
p = buf;
len = sizeof (buf);
while (fgets (p, len, fp))
diff --git a/boot/boot_script.h b/boot/boot_script.h
index da52e6f0..045dc949 100644
--- a/boot/boot_script.h
+++ b/boot/boot_script.h
@@ -98,12 +98,12 @@ int boot_script_exec (void);
/* Create an entry in the symbol table for variable NAME,
whose type is TYPE and value is VAL. Returns 0 on success,
non-zero otherwise. */
-int boot_script_set_variable (const char *name, int type, integer_t val);
+int boot_script_set_variable (const char *name, int type, intptr_t val);
/* Define the function NAME, which will return type RET_TYPE. */
int boot_script_define_function (const char *name, int ret_type,
int (*func) (const struct cmd *cmd,
- integer_t *val));
+ intptr_t *val));
/* Returns a string describing the error ERR. */
char *boot_script_error_string (int err);
diff --git a/boot/userland-boot.c b/boot/userland-boot.c
index 2f9bd8cd..f407f0a6 100644
--- a/boot/userland-boot.c
+++ b/boot/userland-boot.c
@@ -257,7 +257,7 @@ boot_script_exec_cmd (void *hook,
{
char *args, *p;
int arg_len, i;
- size_t reg_size;
+ mach_msg_type_number_t reg_size;
void *arg_pos;
vm_offset_t stack_start, stack_end;
vm_address_t startpc, str_start;
@@ -313,8 +313,13 @@ boot_script_exec_cmd (void *hook,
reg_size = i386_THREAD_STATE_COUNT;
thread_get_state (thread, i386_THREAD_STATE,
(thread_state_t) ®s, ®_size);
- regs.eip = (int) startpc;
- regs.uesp = (int) arg_pos;
+#ifdef __x86_64__
+ regs.rip = (uintptr_t) startpc;
+ regs.ursp = (uintptr_t) arg_pos;
+#else
+ regs.eip = (uintptr_t) startpc;
+ regs.uesp = (uintptr_t) arg_pos;
+#endif
thread_set_state (thread, i386_THREAD_STATE,
(thread_state_t) ®s, reg_size);
}
--
2.40.1
- [PATCH 17/41] proc: Port to x86_64, (continued)
- [PATCH 17/41] proc: Port to x86_64, Sergey Bugaev, 2023/05/08
- [PATCH 16/41] auth: Port to x86_64, Sergey Bugaev, 2023/05/08
- [PATCH 26/41] boot: Fix use-after-realloc, Sergey Bugaev, 2023/05/08
- [PATCH 20/41] elfcore: Add support for saving x86_64 registers, Sergey Bugaev, 2023/05/08
- [PATCH 22/41] sutils: Avoid warnings about prototype mismatch, Sergey Bugaev, 2023/05/08
- [PATCH 35/41] procfs: Port to x86_64, Sergey Bugaev, 2023/05/08
- [PATCH 41/41] Style tweaks, Sergey Bugaev, 2023/05/08
- [PATCH 34/41] ext2fs: Port to x86_64, Sergey Bugaev, 2023/05/08
- [PATCH 33/41] fatfs: Port to x86_64, Sergey Bugaev, 2023/05/08
- [PATCH 21/41] sutils: Port to x86_64, Sergey Bugaev, 2023/05/08
- [PATCH 27/41] boot: Port to x64_64,
Sergey Bugaev <=
- [PATCH 37/41] console-client: Port to x86_64, Sergey Bugaev, 2023/05/08
- [PATCH 30/41] startup: Port to x86_64, Sergey Bugaev, 2023/05/08
- [PATCH 15/41] utils: Avoid warnings about prototype mismatch, Sergey Bugaev, 2023/05/08
- [PATCH 18/41] proc: Fix use-after-realloc, Sergey Bugaev, 2023/05/08
- [PATCH 31/41] mach-defpager: Port to x86_64, Sergey Bugaev, 2023/05/08
- [PATCH 38/41] trans: Port to x86_64, Sergey Bugaev, 2023/05/08
- [PATCH 19/41] exec: Port to x86_64, Sergey Bugaev, 2023/05/08
- [PATCH 25/41] daemons: Port to x86_64, Sergey Bugaev, 2023/05/08
- [PATCH 40/41] Disable Linux-based pfinet on x86_64, Sergey Bugaev, 2023/05/08
- [PATCH 23/41] storeio: Port to x86_64, Sergey Bugaev, 2023/05/08