Skip to content

Commit

Permalink
Kernel: Absorb LibBareMetal back into the kernel
Browse files Browse the repository at this point in the history
This was supposed to be the foundation for some kind of pre-kernel
environment, but nobody is working on it right now, so let's move
everything back into the kernel and remove all the confusion.
  • Loading branch information
awesomekling committed May 16, 2020
1 parent c12cfde commit 21d5f4a
Show file tree
Hide file tree
Showing 75 changed files with 137 additions and 200 deletions.
2 changes: 0 additions & 2 deletions AK/Assertions.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@

# if defined(KERNEL)
# include <Kernel/Assertions.h>
# elif defined(BOOTSTRAPPER)
# include <Bootstrapper/Output/Assertions.h>
# else
# include <assert.h>
# ifndef __serenity__
Expand Down
2 changes: 1 addition & 1 deletion AK/JsonObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ inline void JsonValue::serialize(Builder& builder) const
case Type::Bool:
builder.append(m_value.as_bool ? "true" : "false");
break;
#if !defined(KERNEL) && !defined(BOOTSTRAPPER)
#if !defined(KERNEL)
case Type::Double:
builder.appendf("%g", m_value.as_double);
break;
Expand Down
4 changes: 2 additions & 2 deletions AK/JsonValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ bool JsonValue::equals(const JsonValue& other) const
if (is_string() && other.is_string() && as_string() == other.as_string())
return true;

#if !defined(KERNEL) && !defined(BOOTSTRAPPER)
#if !defined(KERNEL)
if (is_number() && other.is_number() && to_number<double>() == other.to_number<double>()) {
return true;
}
Expand Down Expand Up @@ -158,7 +158,7 @@ JsonValue::JsonValue(const char* cstring)
{
}

#if !defined(BOOTSTRAPPER) && !defined(KERNEL)
#if !defined(KERNEL)
JsonValue::JsonValue(double value)
: m_type(Type::Double)
{
Expand Down
14 changes: 7 additions & 7 deletions AK/JsonValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class JsonValue {
UnsignedInt32,
Int64,
UnsignedInt64,
#if !defined(KERNEL) && !defined(BOOTSTRAPPER)
#if !defined(KERNEL)
Double,
#endif
Bool,
Expand All @@ -68,7 +68,7 @@ class JsonValue {
JsonValue(i64);
JsonValue(u64);

#if !defined(KERNEL) && !defined(BOOTSTRAPPER)
#if !defined(KERNEL)
JsonValue(double);
#endif
JsonValue(bool);
Expand Down Expand Up @@ -172,7 +172,7 @@ class JsonValue {
return *m_value.as_array;
}

#if !defined(KERNEL) && !defined(BOOTSTRAPPER)
#if !defined(KERNEL)
double as_double() const
{
ASSERT(is_double());
Expand All @@ -193,7 +193,7 @@ class JsonValue {
bool is_u32() const { return m_type == Type::UnsignedInt32; }
bool is_i64() const { return m_type == Type::Int64; }
bool is_u64() const { return m_type == Type::UnsignedInt64; }
#if !defined(KERNEL) && !defined(BOOTSTRAPPER)
#if !defined(KERNEL)
bool is_double() const
{
return m_type == Type::Double;
Expand All @@ -211,7 +211,7 @@ class JsonValue {
case Type::UnsignedInt32:
case Type::Int64:
case Type::UnsignedInt64:
#if !defined(KERNEL) && !defined(BOOTSTRAPPER)
#if !defined(KERNEL)
case Type::Double:
#endif
return true;
Expand All @@ -223,7 +223,7 @@ class JsonValue {
template<typename T>
T to_number(T default_value = 0) const
{
#if !defined(KERNEL) && !defined(BOOTSTRAPPER)
#if !defined(KERNEL)
if (is_double())
return (T)as_double();
#endif
Expand All @@ -250,7 +250,7 @@ class JsonValue {
StringImpl* as_string { nullptr };
JsonArray* as_array;
JsonObject* as_object;
#if !defined(KERNEL) && !defined(BOOTSTRAPPER)
#if !defined(KERNEL)
double as_double;
#endif
i32 as_i32;
Expand Down
21 changes: 9 additions & 12 deletions AK/LogStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
# include <Kernel/Thread.h>
#endif

#if !defined(KERNEL) && !defined(BOOTSTRAPPER)
#include <stdio.h>
#if !defined(KERNEL)
# include <stdio.h>
#endif

namespace AK {
Expand Down Expand Up @@ -106,15 +106,15 @@ const LogStream& operator<<(const LogStream& stream, const void* value)
return stream << buffer;
}

#if defined(__serenity__) && !defined(KERNEL) && !defined(BOOTSTRAPPER)
#if defined(__serenity__) && !defined(KERNEL)
static TriState got_process_name = TriState::Unknown;
static char process_name_buffer[256];
#endif

DebugLogStream dbg()
{
DebugLogStream stream;
#if defined(__serenity__) && !defined(KERNEL) && !defined(BOOTSTRAPPER)
#if defined(__serenity__) && !defined(KERNEL)
if (got_process_name == TriState::Unknown) {
if (get_process_name(process_name_buffer, sizeof(process_name_buffer)) == 0)
got_process_name = TriState::True;
Expand All @@ -124,19 +124,16 @@ DebugLogStream dbg()
if (got_process_name == TriState::True)
stream << "\033[33;1m" << process_name_buffer << '(' << getpid() << ")\033[0m: ";
#endif
#if defined(__serenity__) && defined(KERNEL) && !defined(BOOTSTRAPPER)
#if defined(__serenity__) && defined(KERNEL)
if (Kernel::Thread::current)
stream << "\033[34;1m[" << *Kernel::Thread::current << "]\033[0m: ";
else
stream << "\033[36;1m[Kernel]\033[0m: ";
#endif
#if defined(BOOTSTRAPPER) && !defined(__serenity__) && !defined(KERNEL)
stream << "\033[36;1m[Bootstrapper]\033[0m: ";
#endif
return stream;
}

#if defined(KERNEL)
#ifdef KERNEL
KernelLogStream klog()
{
KernelLogStream stream;
Expand All @@ -146,14 +143,14 @@ KernelLogStream klog()
stream << "\033[36;1m[Kernel]\033[0m: ";
return stream;
}
#elif !defined(BOOTSTRAPPER)
#else
DebugLogStream klog()
{
return dbg();
}
#endif

#if defined(KERNEL)
#ifdef KERNEL
KernelLogStream::~KernelLogStream()
{
char newline = '\n';
Expand All @@ -167,7 +164,7 @@ DebugLogStream::~DebugLogStream()
write(&newline, 1);
}

#if !defined(KERNEL) && !defined(BOOTSTRAPPER)
#ifndef KERNEL
StdLogStream::~StdLogStream()
{
char newline = '\n';
Expand Down
18 changes: 9 additions & 9 deletions AK/LogStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include <AK/Types.h>
#include <AK/kstdio.h>

#if !defined(KERNEL) && !defined(BOOTSTRAPPER)
#if !defined(KERNEL)
# include <AK/ScopedValueRollback.h>
# include <AK/StringView.h>
# include <errno.h>
Expand All @@ -42,7 +42,7 @@ namespace AK {
class LogStream {
public:
LogStream()
#if !defined(KERNEL) && !defined(BOOTSTRAPPER)
#if !defined(KERNEL)
: m_errno_restorer(errno)
#endif
{
Expand All @@ -52,7 +52,7 @@ class LogStream {
virtual void write(const char*, int) const = 0;

private:
#if !defined(KERNEL) && !defined(BOOTSTRAPPER)
#if !defined(KERNEL)
ScopedValueRollback<int> m_errno_restorer;
#endif
};
Expand All @@ -68,7 +68,7 @@ class DebugLogStream final : public LogStream {
}
};

#if !defined(KERNEL) && !defined(BOOTSTRAPPER)
#if !defined(KERNEL)
class StdLogStream final : public LogStream {
public:
StdLogStream(int fd)
Expand All @@ -86,7 +86,7 @@ inline StdLogStream out() { return StdLogStream(STDOUT_FILENO); }
inline StdLogStream warn() { return StdLogStream(STDERR_FILENO); }
#endif

#if !defined(BOOTSTRAPPER) && defined(KERNEL)
#ifdef KERNEL
class KernelLogStream final : public LogStream {
public:
KernelLogStream() {}
Expand Down Expand Up @@ -121,7 +121,7 @@ const LogStream& operator<<(const LogStream&, long long);
const LogStream& operator<<(const LogStream&, unsigned long);
const LogStream& operator<<(const LogStream&, unsigned long long);

#if !defined(KERNEL) && !defined(BOOTSTRAPPER)
#if !defined(KERNEL)
const LogStream& operator<<(const LogStream&, double);
const LogStream& operator<<(const LogStream&, float);
#endif
Expand All @@ -141,9 +141,9 @@ inline const LogStream& operator<<(const LogStream& stream, bool value)

DebugLogStream dbg();

#if defined(KERNEL)
#ifdef KERNEL
KernelLogStream klog();
#elif !defined(BOOTSTRAPPER)
#else
DebugLogStream klog();
#endif

Expand All @@ -153,7 +153,7 @@ using AK::dbg;
using AK::klog;
using AK::LogStream;

#if !defined(KERNEL) && !defined(BOOTSTRAPPER)
#if !defined(KERNEL)
using AK::out;
using AK::warn;
#endif
8 changes: 4 additions & 4 deletions AK/Memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@

#include <AK/Types.h>

#if defined(KERNEL) || defined(BOOTSTRAPPER)
# include <LibBareMetal/StdLib.h>
#if defined(KERNEL)
# include <Kernel/StdLib.h>
#else
# include <stdlib.h>
# include <string.h>
#endif

#if defined(__serenity__) && !defined(KERNEL) && !defined(BOOTSTRAPPER)
#if defined(__serenity__) && !defined(KERNEL)
extern "C" void* mmx_memcpy(void* to, const void* from, size_t);
#endif

ALWAYS_INLINE void fast_u32_copy(u32* dest, const u32* src, size_t count)
{
#if defined(__serenity__) && !defined(KERNEL) && !defined(BOOTSTRAPPER)
#if defined(__serenity__) && !defined(KERNEL)
if (count >= 256) {
mmx_memcpy(dest, src, count * sizeof(count));
return;
Expand Down
2 changes: 1 addition & 1 deletion AK/PrintfImplementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ ALWAYS_INLINE int printf_internal(PutChFunc putch, char* buffer, const char*& fm
ret += print_hex(putch, bufptr, va_arg(ap, u64), false, false, left_pad, zero_pad, 16);
break;

#if !defined(BOOTSTRAPPER) && !defined(KERNEL)
#if !defined(KERNEL)
case 'g':
case 'f':
ret += print_double(putch, bufptr, va_arg(ap, double), left_pad, zero_pad, field_width, fraction_length);
Expand Down
2 changes: 0 additions & 2 deletions AK/kmalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@

#if defined(KERNEL)
# include <Kernel/Heap/kmalloc.h>
#elif defined(BOOTSTRAPPER)
# include <Bootstrapper/Memory/malloc.h>
#else
# include <stdlib.h>

Expand Down
4 changes: 2 additions & 2 deletions AK/kstdio.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
#pragma once

#ifdef __serenity__
# if defined(KERNEL) || defined(BOOTSTRAPPER)
# include <LibBareMetal/Output/kstdio.h>
# ifdef KERNEL
# include <Kernel/kstdio.h>
# else
# include <AK/Types.h>
extern "C" {
Expand Down
2 changes: 1 addition & 1 deletion Kernel/ACPI/DMIDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <AK/StringView.h>
#include <Kernel/ACPI/DMIDecoder.h>
#include <Kernel/VM/MemoryManager.h>
#include <LibBareMetal/StdLib.h>
#include <Kernel/StdLib.h>

namespace Kernel {

Expand Down
4 changes: 2 additions & 2 deletions Kernel/ACPI/DMIDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
#include <AK/Types.h>
#include <AK/Vector.h>
#include <Kernel/VM/Region.h>
#include <LibBareMetal/Memory/PhysicalAddress.h>
#include <LibBareMetal/Memory/VirtualAddress.h>
#include <Kernel/PhysicalAddress.h>
#include <Kernel/VirtualAddress.h>

namespace Kernel {

Expand Down
2 changes: 1 addition & 1 deletion Kernel/ACPI/Definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include <AK/RefCounted.h>
#include <AK/Types.h>
#include <AK/Vector.h>
#include <LibBareMetal/Memory/PhysicalAddress.h>
#include <Kernel/PhysicalAddress.h>

namespace Kernel {

Expand Down
2 changes: 1 addition & 1 deletion Kernel/ACPI/DynamicParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include <Kernel/Interrupts/IRQHandler.h>
#include <Kernel/Lock.h>
#include <Kernel/VM/PhysicalPage.h>
#include <LibBareMetal/Memory/PhysicalAddress.h>
#include <Kernel/PhysicalAddress.h>

namespace Kernel {
namespace ACPI {
Expand Down
2 changes: 1 addition & 1 deletion Kernel/ACPI/MultiProcessorParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <Kernel/ACPI/MultiProcessorParser.h>
#include <Kernel/Interrupts/IOAPIC.h>
#include <Kernel/VM/MemoryManager.h>
#include <LibBareMetal/StdLib.h>
#include <Kernel/StdLib.h>

//#define MULTIPROCESSOR_DEBUG

Expand Down
4 changes: 2 additions & 2 deletions Kernel/ACPI/MultiProcessorParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@

#include <AK/Types.h>
#include <Kernel/VM/Region.h>
#include <LibBareMetal/Memory/PhysicalAddress.h>
#include <LibBareMetal/Memory/VirtualAddress.h>
#include <Kernel/PhysicalAddress.h>
#include <Kernel/VirtualAddress.h>

namespace Kernel {
namespace MultiProcessor {
Expand Down
4 changes: 2 additions & 2 deletions Kernel/ACPI/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
#include <Kernel/PCI/Access.h>
#include <Kernel/VM/MemoryManager.h>
#include <Kernel/VM/TypedMapping.h>
#include <LibBareMetal/IO.h>
#include <LibBareMetal/StdLib.h>
#include <Kernel/IO.h>
#include <Kernel/StdLib.h>

namespace Kernel {
namespace ACPI {
Expand Down
4 changes: 2 additions & 2 deletions Kernel/ACPI/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
#include <Kernel/ACPI/Initialize.h>
#include <Kernel/FileSystem/File.h>
#include <Kernel/VM/Region.h>
#include <LibBareMetal/Memory/PhysicalAddress.h>
#include <LibBareMetal/Memory/VirtualAddress.h>
#include <Kernel/PhysicalAddress.h>
#include <Kernel/VirtualAddress.h>

namespace Kernel {
namespace ACPI {
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Arch/i386/CPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#include <Kernel/KSyms.h>
#include <Kernel/Process.h>
#include <Kernel/VM/MemoryManager.h>
#include <LibBareMetal/IO.h>
#include <Kernel/IO.h>
#include <LibC/mallocdefs.h>

//#define PAGE_FAULT_DEBUG
Expand Down
Loading

0 comments on commit 21d5f4a

Please sign in to comment.