Skip to content

Commit

Permalink
Refactored boot server & made it work (#117)
Browse files Browse the repository at this point in the history
Also added much more error handling and similar.

Fixes #102, fixes #79. 🎉
Fixes #116.
  • Loading branch information
perlun authored Dec 25, 2017
1 parent 726202c commit 1ada4b8
Show file tree
Hide file tree
Showing 19 changed files with 240 additions and 110 deletions.
5 changes: 4 additions & 1 deletion libraries/constants.rake
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

DEFINES = (ENV['DEFINES'] || '') + ' -DPACKAGE=\\"storm\\" -DVERSION=\\"git\\"'

# For a saner gdb experience, you typically want to compile without optimizations unless specifically making a release.
OPTIMIZATION_FLAG = ENV['RELEASE'] ? '-O3' : '-O0'

COMMON_CFLAGS =
"-Wall -Wextra -Wshadow -Wpointer-arith -Waggregate-return -Wredundant-decls \
-Winline -Werror -Wcast-align -Wsign-compare -Wmissing-declarations \
-Wmissing-noreturn -pipe -O3 -fno-builtin -funsigned-char \
-Wmissing-noreturn -pipe #{OPTIMIZATION_FLAG} -fno-builtin -funsigned-char \
-g -m32 -fomit-frame-pointer -ffreestanding #{ENV['EXTRA_CFLAGS']} #{DEFINES} ".freeze

CFLAGS = COMMON_CFLAGS +
Expand Down
2 changes: 1 addition & 1 deletion libraries/file/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ return_type file_open(ipc_structure_type *vfs_structure, char *file_name, file_m
}

// Read from a file.
return_type file_read(ipc_structure_type *vfs_structure, file_handle_type file_handle, unsigned int length, void *buffer)
return_type file_read(ipc_structure_type *vfs_structure, file_handle_type file_handle, unsigned int length, uint8_t *buffer)
{
message_parameter_type message_parameter;
file_read_type read;
Expand Down
2 changes: 1 addition & 1 deletion libraries/file/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ extern return_type file_init(ipc_structure_type *vfs_structure, tag_type *tag);
extern return_type file_directory_entry_read(ipc_structure_type *vfs_structure, file_directory_entry_read_type *directory_entry);
extern return_type file_get_info(ipc_structure_type *vfs_structure, file_verbose_directory_entry_type *directory_entry);
extern return_type file_open(ipc_structure_type *vfs_structure, char *file_name, file_mode_type mode, file_handle_type *handle);
extern return_type file_read(ipc_structure_type *vfs_structure, file_handle_type file_handle, unsigned int length, void *buffer);
extern return_type file_read(ipc_structure_type *vfs_structure, file_handle_type file_handle, unsigned int length, uint8_t *buffer);
3 changes: 3 additions & 0 deletions libraries/ipc/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ typedef struct
{
// The location where we want this volume to be mounted.
char location[MAX_PATH_NAME_LENGTH];

// The mailbox ID of the mailbox for talking to the block device server.
mailbox_id_type mailbox_id;
} file_mount_type;

typedef struct
Expand Down
10 changes: 0 additions & 10 deletions libraries/ipc/virtual_file_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,6 @@ enum
IPC_RETURN_VIRTUAL_FILE_SYSTEM_FUNCTION_UNSUPPORTED,
};

// Type definitions.
typedef struct
{
// The location where we want this volume to be mounted.
char location[MAX_PATH_NAME_LENGTH];

// The mailbox ID of the mailbox for talking to the block device server.
mailbox_id_type mailbox_id;
} virtual_file_system_mount_type;

typedef struct
{
char meta_location[MAX_PATH_NAME_LENGTH];
Expand Down
5 changes: 1 addition & 4 deletions menu.lst
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,5 @@ module /servers/ipv4.gz
module /servers/pci.gz
module /servers/virtual_file_system.gz

# Boot server last, since it kind of expects everything else to be up and running.
# Boot server last, since it more-or-less expects everything else to be up and running.
module /servers/boot.gz

# Cluido temporarily here, until we have resolved https://github.com/chaos4ever/chaos/issues/45
module /programs/cluido.gz
6 changes: 3 additions & 3 deletions programs/programs.rake
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ task :clean do
end

task install: OUTPUT do
target_path = INSTALL_ROOT + '/programs'
target_path = 'u:/programs'

sh "mcopy -o #{OUTPUT} #{target_path}"

sh "#{INSTALL_COMMAND} #{OUTPUT} #{target_path}/#{OUTPUT}"
sh "gzip -9f #{target_path}/#{OUTPUT}"
puts " Installed #{OUTPUT} in #{target_path}".gray
end
2 changes: 1 addition & 1 deletion programs/startup
Original file line number Diff line number Diff line change
@@ -1 +1 @@
programs/cluido
//ramdisk/PROGRAMS/CLUIDO
1 change: 1 addition & 0 deletions servers/block/initial_ramdisk/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ LIBRARIES = %w[

OUTPUT = 'initial_ramdisk'.freeze
RAMDISK_IMAGE = 'ramdisk.image'.freeze
EXTRA_LDFLAGS_PRE = '-Wl,--defsym=PROCESS_VM_BASE=0x50000000'.freeze

desc 'Creates the initial ramdisk image'
task :create_ramdisk_image do
Expand Down
2 changes: 1 addition & 1 deletion servers/block/initial_ramdisk/initial_ramdisk.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static void handle_connection(mailbox_id_type *reply_mailbox_id)
ipc_structure_type ipc_structure;
bool done = FALSE;
uint32_t *data;
unsigned int data_size = 1024;
unsigned int data_size = 2048;

memory_allocate((void **) &data, data_size);

Expand Down
53 changes: 48 additions & 5 deletions servers/file_system/virtual_file_system/virtual_file_system.c
Original file line number Diff line number Diff line change
Expand Up @@ -477,16 +477,49 @@ static bool vfs_file_read(file_read_type *read, void *buffer)
}

// Mount the given service at the given location.
static bool vfs_mount(file_mount_type *mount, ipc_structure_type *ipc_structure)
static bool vfs_mount(file_mount_type *mount)
{
memory_copy(&mount_point[mounted_volumes].ipc_structure, ipc_structure, sizeof(ipc_structure_type));
// FIXME: We only support one file_system implementation for now. A proper implementation would gather a more comprehensive
// list of file system services, attempt to mount the volume with them all and see which one is successful.
mailbox_id_type mailbox_id[1];
unsigned int services = 1;

if (ipc_service_resolve("file_system", mailbox_id, &services, 5, &empty_tag) != IPC_RETURN_SUCCESS)
{
log_print_formatted(&log_structure, LOG_URGENCY_ERROR, "vfs_mount: Failed to resolve file_system service");
return FALSE;
}

mount_point[mounted_volumes].ipc_structure.output_mailbox_id = mailbox_id[0];
if (ipc_service_connection_request(&mount_point[mounted_volumes].ipc_structure) != IPC_RETURN_SUCCESS)
{
log_print_formatted(&log_structure, LOG_URGENCY_ERROR,
"vfs_mount: Failed to establish connection with file system service with mailbox ID %u",
mailbox_id[0]);
return FALSE;
}

message_parameter_type message_parameter;
message_parameter.protocol = IPC_PROTOCOL_FILE;
message_parameter.message_class = IPC_FILE_MOUNT_VOLUME;
message_parameter.length = sizeof(mailbox_id_type);
message_parameter.data = &mount->mailbox_id;

if (ipc_send(mount_point[mounted_volumes].ipc_structure.output_mailbox_id, &message_parameter) != IPC_RETURN_SUCCESS)
{
log_print_formatted(&log_structure, LOG_URGENCY_ERROR,
"vfs_mount: Failed to send IPC message to mailbox ID %u",
mailbox_id[0]);
return FALSE;
}

mount_point[mounted_volumes].handled_by_vfs = FALSE;
string_copy_max(mount_point[mounted_volumes].location, mount->location, MAX_PATH_NAME_LENGTH);
mounted_volumes++;

log_print_formatted(&log_structure, LOG_URGENCY_INFORMATIVE,
"Mounting mailbox %u at //%s.",
ipc_structure->output_mailbox_id, mount->location);
mount->mailbox_id, mount->location);
return TRUE;
}

Expand Down Expand Up @@ -552,7 +585,17 @@ static void handle_connection(mailbox_id_type *reply_mailbox_id)
{
file_verbose_directory_entry_type *directory_entry = (file_verbose_directory_entry_type *) data;

vfs_file_get_info(directory_entry);
if (directory_entry->path_name[0] == '\0')
{
log_print(&log_structure, LOG_URGENCY_ERROR,
"IPC_FILE_GET_INFO: Attempted to get info for a file with an empty path");
directory_entry->success = FALSE;
}
else
{
vfs_file_get_info(directory_entry);
}

ipc_send(ipc_structure.output_mailbox_id, &message_parameter);
break;
}
Expand All @@ -561,7 +604,7 @@ static void handle_connection(mailbox_id_type *reply_mailbox_id)
{
file_mount_type *mount = (file_mount_type *) data;

vfs_mount(mount, &ipc_structure);
vfs_mount(mount);
break;
}

Expand Down
10 changes: 7 additions & 3 deletions servers/servers.rake
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ Rake.application.options.rakelib = ["#{File.dirname(__FILE__)}/../rakelib"] if R

LIBRARIES_DIR = "#{File.dirname(__FILE__)}/../libraries".freeze

COMMON_CFLAGS = %w[
# For a saner gdb experience, you typically want to compile without optimizations unless specifically making a release.
OPTIMIZATION_FLAG = ENV['RELEASE'] ? '-O3' : '-O0'

COMMON_CFLAGS = %W[
-Wall
-Wextra
-Wshadow
Expand All @@ -16,14 +19,15 @@ COMMON_CFLAGS = %w[
-Winline
-Werror
-Wcast-align
-Wno-pointer-sign
-Wsign-compare
-Wmissing-declarations
-Wmissing-noreturn
-pipe
-O3
#{OPTIMIZATION_FLAG}
-fno-builtin
-funsigned-char
-g
-ggdb3
-m32
-fomit-frame-pointer
-ffreestanding
Expand Down
1 change: 1 addition & 0 deletions servers/system/boot/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ LIBRARIES = %w[
].freeze

OUTPUT = 'boot'.freeze
EXTRA_LDFLAGS_PRE = '-Wl,--defsym=PROCESS_VM_BASE=0x49000000'.freeze

load '../../servers.rake'
Loading

0 comments on commit 1ada4b8

Please sign in to comment.