added 12 changesets to branch 'refs/remotes/weinhold-github/new-hpkg-format' old head: 90e85a9dbd0e860b42ec8b13b112a004bd711db0 new head: ffba501a8a70da82e12173dcfe64e6b44038b174 overview: https://github.com/weinhold/HaikuPM/compare/90e85a9...ffba501 ---------------------------------------------------------------------------- 1f034f7: ReaderImplBase: Fix gcc 4 build e5c27a2: PackageFileHeapWriter: Add error message ... in case compression fails unexpectedly. 6fd98a1: libroot_build: Fix fs_read_attr() in fs_attr_untyped.cpp * With a specified buffer size smaller than the attribute size the function would fail with ERANGE on Linux although it should just read as much as possible. Now we always read into our temporary data buffer with the full buffer size. * Fix return value in case pos is > 0. pos must be subtracted from the bytes actually read. fa5967b: Add padding in HPKG/HPKR headers ... so that the different alignment on 32 and 64 bit machines doesn't change the layout. bf543aa: ReaderImplBase: Fix strings subsection validity check A strings section with 0 strings is still 1 byte long. Also improve the error output in the error case. 9fb109d: packagefs: Fix debug build 0b56ad1: Add dvprintf() d4d54fc: packagefs: Add va-args version ERRORV() to DebugSupport 5128205: packagefs: Resolve error output TODOs 63b1d4d: packagefs: PackageData: Fix copy and paste error 0a93873: BuildHaikuPackage rule: Add grist to package info file ... to avoids clashes with equally named targets. ffba501: Support booting with a packaged boot loader * Add new package haiku_loader.hpkg and move haiku_loader there. The package is built without compression, so that the stage 1 boot loader has a chance of loading it. * Adjust the stage 1 boot loader to load the haiku_loader package and relocate the boot loader code accordingly. [ Ingo Weinhold <ingo_weinhold@xxxxxx> ] ---------------------------------------------------------------------------- 22 files changed, 182 insertions(+), 64 deletions(-) build/jam/HaikuImage | 6 +- build/jam/HaikuPackages | 1 + build/jam/PackageRules | 4 +- build/jam/packages/Haiku | 3 - build/jam/packages/HaikuLoader | 13 ++++ headers/os/drivers/KernelExport.h | 1 + headers/private/package/hpkg/HPKGDefsPrivate.h | 2 + headers/private/package/hpkg/ReaderImplBase.h | 1 + .../file_systems/packagefs/indices/Index.cpp | 6 +- .../file_systems/packagefs/package/Package.cpp | 4 +- .../file_systems/packagefs/package/PackageData.h | 2 +- .../file_systems/packagefs/util/DebugSupport.cpp | 27 ++++--- .../file_systems/packagefs/util/DebugSupport.h | 38 ++++++---- src/build/libroot/fs_attr_untyped.cpp | 20 +++-- src/data/package_infos/haiku_loader | 18 +++++ src/kits/package/hpkg/PackageFileHeapWriter.cpp | 7 +- src/kits/package/hpkg/PackageReaderImpl.cpp | 1 - src/kits/package/hpkg/ReaderImplBase.cpp | 7 +- src/kits/package/hpkg/RepositoryReaderImpl.cpp | 1 - src/system/boot/platform/bios_ia32/stage1.S | 74 ++++++++++++++++--- src/system/boot/platform/bios_ia32/stage1.bin | Bin 1024 -> 1024 bytes src/system/kernel/debug/debug.cpp | 10 +++ ############################################################################ Commit: 1f034f7f7ecfdd78246cdc8a759ba3bd96f4f9b7 Author: Ingo Weinhold <ingo_weinhold@xxxxxx> Date: Sun May 19 08:44:11 2013 UTC ReaderImplBase: Fix gcc 4 build ---------------------------------------------------------------------------- diff --git a/headers/private/package/hpkg/ReaderImplBase.h b/headers/private/package/hpkg/ReaderImplBase.h index 0ed343e..a8f6830 100644 --- a/headers/private/package/hpkg/ReaderImplBase.h +++ b/headers/private/package/hpkg/ReaderImplBase.h @@ -15,6 +15,7 @@ #include <util/SinglyLinkedList.h> +#include <package/hpkg/ErrorOutput.h> #include <package/hpkg/PackageAttributeValue.h> #include <package/hpkg/PackageContentHandler.h> #include <package/hpkg/PackageInfoAttributeValue.h> diff --git a/src/kits/package/hpkg/PackageReaderImpl.cpp b/src/kits/package/hpkg/PackageReaderImpl.cpp index 1446c31..bc21926 100644 --- a/src/kits/package/hpkg/PackageReaderImpl.cpp +++ b/src/kits/package/hpkg/PackageReaderImpl.cpp @@ -23,7 +23,6 @@ #include <package/hpkg/HPKGDefsPrivate.h> #include <package/hpkg/DataOutput.h> -#include <package/hpkg/ErrorOutput.h> #include <package/hpkg/PackageData.h> #include <package/hpkg/PackageEntry.h> #include <package/hpkg/PackageEntryAttribute.h> diff --git a/src/kits/package/hpkg/ReaderImplBase.cpp b/src/kits/package/hpkg/ReaderImplBase.cpp index 434d6ef..37e23d6 100644 --- a/src/kits/package/hpkg/ReaderImplBase.cpp +++ b/src/kits/package/hpkg/ReaderImplBase.cpp @@ -20,7 +20,6 @@ #include <package/hpkg/HPKGDefsPrivate.h> #include <package/hpkg/DataOutput.h> -#include <package/hpkg/ErrorOutput.h> #include <package/hpkg/PackageFileHeapReader.h> #include <package/hpkg/ZlibDecompressor.h> diff --git a/src/kits/package/hpkg/RepositoryReaderImpl.cpp b/src/kits/package/hpkg/RepositoryReaderImpl.cpp index 13f78a1..0dc6467 100644 --- a/src/kits/package/hpkg/RepositoryReaderImpl.cpp +++ b/src/kits/package/hpkg/RepositoryReaderImpl.cpp @@ -18,7 +18,6 @@ #include <ByteOrder.h> #include <Message.h> -#include <package/hpkg/ErrorOutput.h> #include <package/hpkg/HPKGDefsPrivate.h> #include <package/hpkg/PackageFileHeapReader.h> #include <package/hpkg/RepositoryContentHandler.h> ############################################################################ Commit: e5c27a248fadf97f4d0a2c6098771f409c917bf5 Author: Ingo Weinhold <ingo_weinhold@xxxxxx> Date: Sun May 19 08:47:44 2013 UTC PackageFileHeapWriter: Add error message ... in case compression fails unexpectedly. ---------------------------------------------------------------------------- diff --git a/src/kits/package/hpkg/PackageFileHeapWriter.cpp b/src/kits/package/hpkg/PackageFileHeapWriter.cpp index 096ee3d..5c24945 100644 --- a/src/kits/package/hpkg/PackageFileHeapWriter.cpp +++ b/src/kits/package/hpkg/PackageFileHeapWriter.cpp @@ -549,8 +549,13 @@ PackageFileHeapWriter::_WriteDataCompressed(const void* data, size_t size) size_t compressedSize; status_t error = ZlibCompressor::CompressSingleBuffer(data, size, fCompressedDataBuffer, size, compressedSize, fCompressionLevel); - if (error != B_OK) + if (error != B_OK) { + if (error != B_BUFFER_OVERFLOW) { + fErrorOutput->PrintError("Failed to compress chunk data: %s\n", + strerror(error)); + } return error; + } // only use compressed data when we've actually saved space if (compressedSize == size) ############################################################################ Commit: 6fd98a14339f76fd003b84e346015a96bc2f3636 Author: Ingo Weinhold <ingo_weinhold@xxxxxx> Date: Sun May 19 08:55:14 2013 UTC libroot_build: Fix fs_read_attr() in fs_attr_untyped.cpp * With a specified buffer size smaller than the attribute size the function would fail with ERANGE on Linux although it should just read as much as possible. Now we always read into our temporary data buffer with the full buffer size. * Fix return value in case pos is > 0. pos must be subtracted from the bytes actually read. ---------------------------------------------------------------------------- diff --git a/src/build/libroot/fs_attr_untyped.cpp b/src/build/libroot/fs_attr_untyped.cpp index 02ea2af..aeffdca 100644 --- a/src/build/libroot/fs_attr_untyped.cpp +++ b/src/build/libroot/fs_attr_untyped.cpp @@ -523,8 +523,7 @@ fs_read_attr(int fd, const char *_attribute, uint32 type, off_t pos, // read the attribute char attributeBuffer[sizeof(AttributeHeader) + kMaxAttributeLength]; - ssize_t bytesRead = min_c((size_t)kMaxAttributeLength, readBytes) - + sizeof(AttributeHeader); + ssize_t bytesRead = sizeof(attributeBuffer); if (localFD.Path()) { bytesRead = get_attribute(-1, localFD.Path(), attribute.c_str(), attributeBuffer, bytesRead); @@ -549,12 +548,19 @@ fs_read_attr(int fd, const char *_attribute, uint32 type, off_t pos, } // copy the result into the provided buffer - bytesRead -= sizeof(AttributeHeader); - if (bytesRead > pos) { + bytesRead -= sizeof(AttributeHeader) + pos; + if (bytesRead < 0) { + // that means pos > <attribute size> + errno = B_BAD_VALUE; + return -1; + } + + if (bytesRead > 0) { + if ((size_t)bytesRead > readBytes) + bytesRead = readBytes; memcpy(buffer, attributeBuffer + sizeof(AttributeHeader) + pos, - bytesRead - pos); - } else - bytesRead = 0; + bytesRead); + } return bytesRead; } ############################################################################ Commit: fa5967be339bd4244c62cfcec3abbdfb82e96644 Author: Ingo Weinhold <ingo_weinhold@xxxxxx> Date: Mon May 20 12:22:39 2013 UTC Add padding in HPKG/HPKR headers ... so that the different alignment on 32 and 64 bit machines doesn't change the layout. ---------------------------------------------------------------------------- diff --git a/headers/private/package/hpkg/HPKGDefsPrivate.h b/headers/private/package/hpkg/HPKGDefsPrivate.h index dd2b820..ce8837d 100644 --- a/headers/private/package/hpkg/HPKGDefsPrivate.h +++ b/headers/private/package/hpkg/HPKGDefsPrivate.h @@ -35,6 +35,7 @@ struct hpkg_header { uint32 attributes_length; uint32 attributes_strings_length; uint32 attributes_strings_count; + uint32 reserved1; // TOC section uint64 toc_length; @@ -58,6 +59,7 @@ struct hpkg_repo_header { // repository info section uint32 info_length; + uint32 reserved1; // package attributes section uint64 packages_length; ############################################################################ Commit: bf543aae75771a728da2caf203c108f6971b98b3 Author: Ingo Weinhold <ingo_weinhold@xxxxxx> Date: Mon May 20 12:25:31 2013 UTC ReaderImplBase: Fix strings subsection validity check A strings section with 0 strings is still 1 byte long. Also improve the error output in the error case. ---------------------------------------------------------------------------- diff --git a/src/kits/package/hpkg/ReaderImplBase.cpp b/src/kits/package/hpkg/ReaderImplBase.cpp index 37e23d6..ad83419 100644 --- a/src/kits/package/hpkg/ReaderImplBase.cpp +++ b/src/kits/package/hpkg/ReaderImplBase.cpp @@ -617,11 +617,11 @@ ReaderImplBase::InitSection(PackageFileSection& section, uint64 endOffset, } // check strings subsection size/count - if ((stringsLength == 0) != (stringsCount == 0) || stringsLength > length) { + if ((stringsLength <= 1) != (stringsCount == 0) || stringsLength > length) { ErrorOutput()->PrintError("Error: strings subsection description of %s " "file %s section is invalid (%" B_PRIu64 " strings, length: %" - B_PRIu64 ")\n", - fFileType, section.name, length, stringsCount, stringsLength); + B_PRIu64 ", section length: %" B_PRIu64 ")\n", + fFileType, section.name, stringsCount, stringsLength, length); return B_BAD_DATA; } ############################################################################ Commit: 9fb109dcb7eb64aad799332032ff2c4ebffe0f58 Author: Ingo Weinhold <ingo_weinhold@xxxxxx> Date: Mon May 20 12:45:13 2013 UTC packagefs: Fix debug build ---------------------------------------------------------------------------- diff --git a/src/add-ons/kernel/file_systems/packagefs/indices/Index.cpp b/src/add-ons/kernel/file_systems/packagefs/indices/Index.cpp index efdf4da..82e15ed 100644 --- a/src/add-ons/kernel/file_systems/packagefs/indices/Index.cpp +++ b/src/add-ons/kernel/file_systems/packagefs/indices/Index.cpp @@ -72,12 +72,12 @@ void Index::Dump() { D( - PRINT("Index: `%s', type: %" B_PRIx32 "\n", Name(), Type()); + PRINT("Index: `%s', type: %" B_PRIx32 "\n", Name().Data(), Type()); IndexIterator it; if (GetIterator(it)) { while (Node* node = it.Next()) { - PRINT(" node: `%s', dir: %" B_PRIdINO "\n", node->Name(), - node->Parent()->ID()); + PRINT(" node: `%s', dir: %" B_PRIdINO "\n", + node->Name().Data(), node->Parent()->ID()); } } ) ############################################################################ Commit: 0b56ad17c27a645778d7c32e478d997b2f35a7c2 Author: Ingo Weinhold <ingo_weinhold@xxxxxx> Date: Mon May 20 17:07:46 2013 UTC Add dvprintf() ---------------------------------------------------------------------------- diff --git a/headers/os/drivers/KernelExport.h b/headers/os/drivers/KernelExport.h index 3e2e584..98e5938 100644 --- a/headers/os/drivers/KernelExport.h +++ b/headers/os/drivers/KernelExport.h @@ -160,6 +160,7 @@ extern area_id map_physical_memory(const char *areaName, /* kernel debugging facilities */ extern void dprintf(const char *format, ...) _PRINTFLIKE(1, 2); +extern void dvprintf(const char *format, va_list args); extern void kprintf(const char *fmt, ...) _PRINTFLIKE(1, 2); extern void dump_block(const char *buffer, int size, const char *prefix); diff --git a/src/system/kernel/debug/debug.cpp b/src/system/kernel/debug/debug.cpp index df7e2ef..caa90d1 100644 --- a/src/system/kernel/debug/debug.cpp +++ b/src/system/kernel/debug/debug.cpp @@ -2112,6 +2112,16 @@ dprintf(const char* format, ...) void +dvprintf(const char* format, va_list args) +{ + if (!sSerialDebugEnabled && !sSyslogOutputEnabled && !sBlueScreenEnabled) + return; + + dprintf_args(format, args, true); +} + + +void dprintf_no_syslog(const char* format, ...) { va_list args; ############################################################################ Commit: d4d54fcea5b06466a4e32afb8618d956daa5e54a Author: Ingo Weinhold <ingo_weinhold@xxxxxx> Date: Mon May 20 17:09:20 2013 UTC packagefs: Add va-args version ERRORV() to DebugSupport ---------------------------------------------------------------------------- diff --git a/src/add-ons/kernel/file_systems/packagefs/util/DebugSupport.cpp b/src/add-ons/kernel/file_systems/packagefs/util/DebugSupport.cpp index 8377cf3..23f683e 100644 --- a/src/add-ons/kernel/file_systems/packagefs/util/DebugSupport.cpp +++ b/src/add-ons/kernel/file_systems/packagefs/util/DebugSupport.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2009, Ingo Weinhold, ingo_weinhold@xxxxxx. + * Copyright 2003-2013, Ingo Weinhold, ingo_weinhold@xxxxxx. * Distributed under the terms of the MIT License. */ @@ -127,24 +127,29 @@ dbg_printf_end() #if DEBUG_PRINT + void -dbg_printf(const char *format,...) +dbg_vprintf(const char* format, va_list args) { if (!dbg_printf_lock()) return; + char buffer[1024]; + vsnprintf(buffer, sizeof(buffer) - 1, format, args); + write(out, buffer, strlen(buffer)); + + dbg_printf_unlock(); +} + + +void +dbg_printf(const char* format,...) +{ va_list args; va_start(args, format); - // no vsnprintf() on PPC and in kernel - #if defined(__INTEL__) && USER - vsnprintf(buffer, sizeof(buffer) - 1, format, args); - #else - vsprintf(buffer, format, args); - #endif + dbg_vprintf(format, args); va_end(args); - buffer[sizeof(buffer) - 1] = '\0'; - write(out, buffer, strlen(buffer)); - dbg_printf_unlock(); } + #endif // DEBUG_PRINT diff --git a/src/add-ons/kernel/file_systems/packagefs/util/DebugSupport.h b/src/add-ons/kernel/file_systems/packagefs/util/DebugSupport.h index 8e0dc49..cb8ec3a 100644 --- a/src/add-ons/kernel/file_systems/packagefs/util/DebugSupport.h +++ b/src/add-ons/kernel/file_systems/packagefs/util/DebugSupport.h @@ -44,16 +44,20 @@ # include <stdio.h> # if DEBUG_PRINT # define __out dbg_printf +# define __outv dbg_vprintf # else # define __out printf +# define __outv vprintf # endif #else # include <KernelExport.h> # include <null.h> # if DEBUG_PRINT # define __out dbg_printf +# define __outv dbg_vprintf # else # define __out dprintf +# define __outv dvprintf # endif #endif @@ -74,18 +78,23 @@ status_t exit_debugging(); void dbg_printf_begin(); void dbg_printf_end(); #if DEBUG_PRINT - void dbg_printf(const char *format,...); + void dbg_vprintf(const char* format, va_list args); + void dbg_printf(const char* format,...); #else - static inline void dbg_printf(const char *,...) {} + static inline void dbg_vprintf(const char*, va_list) {} + static inline void dbg_printf(const char*,...) {} #endif -// Short overview over the debug output macros: +// Short overview of the debug output macros: // PRINT() -// is for general messages that very unlikely should appear in a release -// build +// general messages that shouldn't appear in a release build // FATAL() -// this is for fatal messages, when something has really gone wrong +// fatal messages, when something has really gone wrong +// ERROR() +// non-fatal error messages +// WARN() +// warning messages // INFORM() // general information, as disk size, etc. // REPORT_ERROR(status_t) @@ -121,7 +130,8 @@ void dbg_printf_end(); dbg_printf_end(); \ } -#define TPRINT(x...) DEBUG_CONTEXT( __out(x) ) +#define TPRINT(x...) DEBUG_CONTEXT( __out(x) ) +#define TPRINTV(format, args) DEBUG_CONTEXT( __outv(format, args) ) #define TREPORT_ERROR(status) \ DEBUG_CONTEXT_LINE( __out("%s\n", strerror(status)) ) #define TRETURN_ERROR(err) \ @@ -147,10 +157,6 @@ void dbg_printf_end(); #define REPORT_ERROR(status) TREPORT_ERROR(status) #define RETURN_ERROR(err) TRETURN_ERROR(err) #define SET_ERROR(var, err) TSET_ERROR(var, err) - #define FATAL(x...) DEBUG_CONTEXT( __out(x) ) - #define ERROR(x...) DEBUG_CONTEXT( __out(x) ) - #define WARN(x...) DEBUG_CONTEXT( __out(x) ) - #define INFORM(x...) DEBUG_CONTEXT( __out(x) ) #define FUNCTION(x...) TFUNCTION(x) #define FUNCTION_START() TFUNCTION_START() #define FUNCTION_END() TFUNCTION_END() @@ -161,10 +167,6 @@ void dbg_printf_end(); #define REPORT_ERROR(status) ; #define RETURN_ERROR(status) return status; #define SET_ERROR(var, err) var = err; - #define FATAL(x...) DEBUG_CONTEXT( __out(x) ) - #define ERROR(x...) DEBUG_CONTEXT( __out(x) ) - #define WARN(x...) DEBUG_CONTEXT( __out(x) ) - #define INFORM(x...) DEBUG_CONTEXT( __out(x) ) #define FUNCTION(x...) ; #define FUNCTION_START() ; #define FUNCTION_END() ; @@ -172,6 +174,12 @@ void dbg_printf_end(); #define D(x) ; #endif +#define FATAL(x...) TPRINT(x) +#define ERROR(x...) TPRINT(x) +#define ERRORV(format, args) TPRINTV(format, args) +#define WARN(x...) TPRINT(x) +#define INFORM(x...) TPRINT(x) + #ifndef TOUCH #define TOUCH(var) (void)var #endif ############################################################################ Commit: 5128205f1a4cd3be555a892f4e812b4f467f9293 Author: Ingo Weinhold <ingo_weinhold@xxxxxx> Date: Mon May 20 17:10:09 2013 UTC packagefs: Resolve error output TODOs ---------------------------------------------------------------------------- diff --git a/src/add-ons/kernel/file_systems/packagefs/package/Package.cpp b/src/add-ons/kernel/file_systems/packagefs/package/Package.cpp index 094b231..643aa44 100644 --- a/src/add-ons/kernel/file_systems/packagefs/package/Package.cpp +++ b/src/add-ons/kernel/file_systems/packagefs/package/Package.cpp @@ -75,7 +75,7 @@ struct Package::LoaderErrorOutput : BErrorOutput { virtual void PrintErrorVarArgs(const char* format, va_list args) { -// TODO:... + ERRORV(format, args); } private: @@ -702,7 +702,7 @@ private: virtual void PrintErrorVarArgs(const char* format, va_list args) { -// TODO:... + ERRORV(format, args); } private: ############################################################################ Commit: 63b1d4d0dad33af6563ef3d0e24eecf506d6bc24 Author: Ingo Weinhold <ingo_weinhold@xxxxxx> Date: Mon May 20 17:10:46 2013 UTC packagefs: PackageData: Fix copy and paste error ---------------------------------------------------------------------------- diff --git a/src/add-ons/kernel/file_systems/packagefs/package/PackageData.h b/src/add-ons/kernel/file_systems/packagefs/package/PackageData.h index 6597aa3..7968c3e 100644 --- a/src/add-ons/kernel/file_systems/packagefs/package/PackageData.h +++ b/src/add-ons/kernel/file_systems/packagefs/package/PackageData.h @@ -58,7 +58,7 @@ PackageData::PackageData(const PackageDataV1& data) inline PackageData::PackageData(const PackageDataV2& data) : - fVersion(1) + fVersion(2) { memcpy(&fData, &data, sizeof(data)); } ############################################################################ Commit: 0a938735772c1a6fd7f26c49b51c1fc2f9ae12ee Author: Ingo Weinhold <ingo_weinhold@xxxxxx> Date: Mon May 20 17:30:54 2013 UTC BuildHaikuPackage rule: Add grist to package info file ... to avoids clashes with equally named targets. ---------------------------------------------------------------------------- diff --git a/build/jam/PackageRules b/build/jam/PackageRules index 602cef0..a6cb302 100644 --- a/build/jam/PackageRules +++ b/build/jam/PackageRules @@ -289,6 +289,8 @@ rule HaikuPackage package rule BuildHaikuPackage package : packageInfo { + packageInfo = $(packageInfo:G=package-info) ; + local grist = [ FHaikuPackageGrist $(package) ] ; local tempDir = [ FDirName $(HAIKU_PACKAGES_BUILD_DIR) $(grist) ] ; @@ -311,7 +313,7 @@ rule BuildHaikuPackage package : packageInfo AddVariableToScript $(script) : addBuildCompatibilityLibDir : $(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR) ; AddVariableToScript $(script) : compressionLevel - : $(HAIKU_PACKAGE_COMPRESSION_LEVEL) ; + : [ on $(package) return $(HAIKU_PACKAGE_COMPRESSION_LEVEL) ] ; AddVariableToScript $(script) : updateOnly : [ on $(package) return $(HAIKU_CONTAINER_UPDATE_ONLY) ] ; AddTargetVariableToScript $(script) : <build>addattr ; ############################################################################ Commit: ffba501a8a70da82e12173dcfe64e6b44038b174 Author: Ingo Weinhold <ingo_weinhold@xxxxxx> Date: Mon May 20 17:37:40 2013 UTC Support booting with a packaged boot loader * Add new package haiku_loader.hpkg and move haiku_loader there. The package is built without compression, so that the stage 1 boot loader has a chance of loading it. * Adjust the stage 1 boot loader to load the haiku_loader package and relocate the boot loader code accordingly. ---------------------------------------------------------------------------- diff --git a/build/jam/HaikuImage b/build/jam/HaikuImage index ea469b1..c5c2a79 100644 --- a/build/jam/HaikuImage +++ b/build/jam/HaikuImage @@ -197,10 +197,11 @@ SYSTEM_ADD_ONS_FILE_SYSTEMS = bfs bindfs btrfs cdda exfat ext2 fat iso9660 nfs googlefs ; -# build the haiku system package and add it +# build the haiku system packages and add them include [ FDirName $(HAIKU_BUILD_RULES_DIR) HaikuPackages ] ; AddPackageFilesToHaikuImage system : haiku.hpkg ; +AddPackageFilesToHaikuImage system : haiku_loader.hpkg ; AddSymlinkToHaikuImage . : /boot/common/apps ; @@ -315,9 +316,6 @@ SEARCH on <post-install>fresh_install = [ FDirName $(HAIKU_TOP) data common settings ] ; AddFilesToHaikuImage common settings : <post-install>fresh_install ; -# boot loader -AddFilesToHaikuImage system : haiku_loader ; - # decorators AddDirectoryToHaikuImage home config non-packaged add-ons decorators ; #AddFilesToHaikuImage home config add-ons decorators : ; diff --git a/build/jam/HaikuPackages b/build/jam/HaikuPackages index 52bcf5e..06f82f3 100644 --- a/build/jam/HaikuPackages +++ b/build/jam/HaikuPackages @@ -3,6 +3,7 @@ local packages = Haiku HaikuDevel + HaikuLoader HaikuUserguide HaikuWelcome MakefileEngine diff --git a/build/jam/packages/Haiku b/build/jam/packages/Haiku index a9fd70c..435363f 100644 --- a/build/jam/packages/Haiku +++ b/build/jam/packages/Haiku @@ -280,9 +280,6 @@ SEARCH on $(thinkPadFiles) = $(thinkpadDir) ; AddFilesToPackage data KeyboardLayouts ThinkPad : $(thinkPadFiles) ; -# boot loader -AddFilesToPackage : haiku_loader ; - # boot module links AddBootModuleSymlinksToPackage acpi@x86 ata@ata pci isa@x86 config_manager dpc diff --git a/build/jam/packages/HaikuLoader b/build/jam/packages/HaikuLoader new file mode 100644 index 0000000..3129845 --- /dev/null +++ b/build/jam/packages/HaikuLoader @@ -0,0 +1,13 @@ +local haikuLoaderPackage = haiku_loader.hpkg ; +HaikuPackage $(haikuLoaderPackage) ; + + +# boot loader +AddFilesToPackage : haiku_loader ; + + +# Force no compression, so the stage one loader can directly execute the boot +# loader. +HAIKU_PACKAGE_COMPRESSION_LEVEL on $(haikuLoaderPackage) = 0 ; + +BuildHaikuPackage $(haikuLoaderPackage) : haiku_loader ; diff --git a/src/data/package_infos/haiku_loader b/src/data/package_infos/haiku_loader new file mode 100644 index 0000000..b9bb561 --- /dev/null +++ b/src/data/package_infos/haiku_loader @@ -0,0 +1,18 @@ +name haiku_loader +version R1~alpha4_pm-1 +architecture x86_gcc2 +summary "The Haiku boot loader" +description "The Haiku boot loader." + +packager "The Haiku build system" +vendor "Haiku Project" + +copyrights "2001-2013 Haiku, Inc. et al" +licenses "MIT" + +provides { + haiku_loader=R1~alpha4_pm-1 +} + +requires { +} diff --git a/src/system/boot/platform/bios_ia32/stage1.S b/src/system/boot/platform/bios_ia32/stage1.S index af46369..bbfeca4 100644 --- a/src/system/boot/platform/bios_ia32/stage1.S +++ b/src/system/boot/platform/bios_ia32/stage1.S @@ -1,11 +1,11 @@ -; Copyright 2005, Ingo Weinhold, bonefish@xxxxxxxxxxxx. +; Copyright 2005-2013, Ingo Weinhold, ingo_weinhold@xxxxxx. ; Distributed under the terms of the MIT License. ; ; Stage 1 boot code for the good (?) old BIOS for use as boot block of HD ; partitions. The offset of the partition in 512 byte blocks must be written at ; position PARTITION_OFFSET_OFFSET (32 bit little endian; makebootable does ; that) or otherwise the code can't find the partition. -; The partition must be a BFS formatted. The file "system/haiku_loader" +; The partition must be BFS formatted. The file "system/haiku_loader" ; (the stage 2 boot loader) loaded into memory at 0x1000:0x0000 (linear address ; 0x10000) and entered at 0x:1000:0x0200 with parameters eax - partition offset ; in 512 byte blocks and dl - BIOS ID of the boot drive. @@ -193,6 +193,12 @@ struc BPlusTreeNode .all_key_length resw 1 endstruc +; The beginning of a HPKG header +struc HPKGHeader + .magic resd 1 + .header_size resw 1 + ; ... + ; That's what esp points to after a "pushad". struc PushadStack .edi resd 1 @@ -631,7 +637,7 @@ kReadErrorString db "read error", 0 kBadSuperBlockMagicString db "bad superblock", 0 kNotADirectoryString db "not a directory", 0 kBadInodeMagicString db "bad inode", 0 -kNoZbeosString db "haiku_loader not found", 0 +kNoZbeosString db "no loader", 0 %else kErrorString db "Failed to load OS. Press any key to reboot..." db 0 @@ -640,7 +646,8 @@ kErrorString db "Failed to load OS. Press any key to reboot..." ; the path to the boot loader kPathComponents: pathComponent "system" -pathComponent "haiku_loader" +pathComponent "packages" +pathComponent "haiku_loader.hpkg" db 0 @@ -706,20 +713,65 @@ readBootLoader: and ax, ax jnz .read_loop - ; We have successfully read the complete boot loader. Set up the + ; We have successfully read the complete boot loader package. The actual + ; code is located at the beginning of the package file heap which starts + ; directly after the header. Since the boot loader code expects to be + ; located at a fixed address, we have to move it there. + + ; First set up the source and target segment registers. We keep the current + ; value also in bx, since it is easier to do arithmetics with it. We keep + ; the increment value for the segment registers in dx. + mov bx, 0x1000 ; initial ds and es value + push bx + pop ds + push bx + pop es + mov dx, bx ; the increment value for the segment registers + + ; Determine how much we have to copy and from where to where. si will be + ; the source and di the destination pointer (both segment relative) and + ; ecx is our byte count. To save instructions we only approximate the count. + ; It may be almost a full segment greater than necessary. But that doesn't + ; really harm. + mov ecx, edi + shr ecx, 12 ; byte count + xor di, di ; target + mov ax, [di + HPKGHeader.header_size] ; header size (big endian) + xchg ah, al + mov si, ax ; source + +.move_loop: + movsb + test si, si + jnz .move_no_source_overflow + add bx, dx + push bx + pop ds +.move_no_source_overflow: + test di, di + jnz .move_no_destination_overflow + push bx + pop es + ; Using bx (the value of ds) is fine, since we assume that the + ; source is less than a segment ahead of the destination. +.move_no_destination_overflow: + dec ecx + jnz .move_loop + + ; We have successfully prepared the boot loader code. Set up the ; environment for it. ; eax - partition offset in sectors + push cs + pop ds + ; temporarily reset ds, so we can access our variables mov dword eax, [kPartitionOffset] ; dl - BIOS drive ID xor edx, edx mov dl, [bios_drive_id] - ; ds, es - push 0x07c0 - pop ds - push 0x1000 - pop es + ; Note: We don't have to set ds and es, since the stage 2 sets them + ; anyway before accessing any data. ; enter the boot loader jmp 0x1000:0x200 @@ -949,6 +1001,7 @@ bfsBlockToDiskBlock: ret +%if 0 ; _writeInt32 ; Writes the given number in 8 digit hexadecimal representation to screen. ; Used for debugging only. @@ -988,6 +1041,7 @@ _writeInt32: popad ret +%endif ; check whether we are small enough diff --git a/src/system/boot/platform/bios_ia32/stage1.bin b/src/system/boot/platform/bios_ia32/stage1.bin index 0a6d92a..e348e81 100644 Binary files a/src/system/boot/platform/bios_ia32/stage1.bin and b/src/system/boot/platform/bios_ia32/stage1.bin differ