Przeglądaj źródła

Kernel: Apply changes to use LibBareMetal definitions

Liav A 5 lat temu
rodzic
commit
e559af2008
43 zmienionych plików z 84 dodań i 892 usunięć
  1. 2 2
      Kernel/ACPI/ACPIStaticParser.cpp
  2. 1 1
      Kernel/ACPI/DMIDecoder.cpp
  3. 23 26
      Kernel/Arch/i386/APIC.cpp
  4. 1 1
      Kernel/Arch/i386/CPU.h
  5. 1 2
      Kernel/Arch/i386/PIC.cpp
  6. 1 1
      Kernel/Arch/i386/PIT.cpp
  7. 1 1
      Kernel/Assertions.h
  8. 1 1
      Kernel/CMOS.cpp
  9. 0 93
      Kernel/Console.cpp
  10. 0 64
      Kernel/Console.h
  11. 1 1
      Kernel/Devices/BXVGADevice.cpp
  12. 1 1
      Kernel/Devices/DebugLogDevice.cpp
  13. 1 1
      Kernel/Devices/FloppyDiskDevice.cpp
  14. 1 1
      Kernel/Devices/KeyboardDevice.cpp
  15. 1 1
      Kernel/Devices/PATAChannel.cpp
  16. 1 1
      Kernel/Devices/PCSpeaker.cpp
  17. 1 1
      Kernel/Devices/PS2MouseDevice.cpp
  18. 1 1
      Kernel/Devices/SB16.cpp
  19. 3 3
      Kernel/Devices/SerialDevice.cpp
  20. 1 1
      Kernel/Devices/VMWareBackdoor.cpp
  21. 2 2
      Kernel/FileSystem/ProcFS.cpp
  22. 2 3
      Kernel/Heap/kmalloc.cpp
  23. 0 100
      Kernel/IO.h
  24. 4 4
      Kernel/Makefile
  25. 1 1
      Kernel/Net/E1000NetworkAdapter.cpp
  26. 1 1
      Kernel/Net/LocalSocket.cpp
  27. 2 2
      Kernel/Net/MACAddress.h
  28. 1 1
      Kernel/Net/NetworkAdapter.cpp
  29. 1 1
      Kernel/Net/RTL8139NetworkAdapter.cpp
  30. 1 1
      Kernel/PCI/IOAccess.cpp
  31. 1 1
      Kernel/PCI/Initializer.cpp
  32. 3 4
      Kernel/PCI/MMIOAccess.cpp
  33. 3 3
      Kernel/Process.cpp
  34. 0 254
      Kernel/StdLib.cpp
  35. 0 76
      Kernel/StdLib.h
  36. 3 3
      Kernel/TTY/VirtualConsole.cpp
  37. 1 1
      Kernel/TTY/VirtualConsole.h
  38. 1 1
      Kernel/TestModule.cpp
  39. 1 1
      Kernel/VM/MemoryManager.cpp
  40. 12 8
      Kernel/VM/RangeAllocator.cpp
  41. 1 1
      Kernel/init.cpp
  42. 0 163
      Kernel/kprintf.cpp
  43. 0 56
      Kernel/kstdio.h

+ 2 - 2
Kernel/ACPI/ACPIStaticParser.cpp

@@ -25,9 +25,9 @@
  */
 
 #include <Kernel/ACPI/ACPIStaticParser.h>
-#include <Kernel/IO.h>
-#include <Kernel/StdLib.h>
 #include <Kernel/VM/MemoryManager.h>
+#include <LibBareMetal/IO.h>
+#include <LibBareMetal/StdLib.h>
 
 //#define ACPI_DEBUG
 

+ 1 - 1
Kernel/ACPI/DMIDecoder.cpp

@@ -25,8 +25,8 @@
  */
 
 #include <Kernel/ACPI/DMIDecoder.h>
-#include <Kernel/StdLib.h>
 #include <Kernel/VM/MemoryManager.h>
+#include <LibBareMetal/StdLib.h>
 
 static DMIDecoder* s_dmi_decoder;
 

+ 23 - 26
Kernel/Arch/i386/APIC.cpp

@@ -26,10 +26,10 @@
 
 #include <AK/Assertions.h>
 #include <AK/Types.h>
-#include <Kernel/Arch/i386/CPU.h>
 #include <Kernel/Arch/i386/APIC.h>
-#include <Kernel/IO.h>
+#include <Kernel/Arch/i386/CPU.h>
 #include <Kernel/VM/MemoryManager.h>
+#include <LibBareMetal/IO.h>
 
 #define IRQ_APIC_SPURIOUS 0x1f
 
@@ -56,12 +56,11 @@ asm(
 
 namespace APIC {
 
-class ICRReg
-{
-    u32 m_reg{0};
+class ICRReg {
+    u32 m_reg { 0 };
+
 public:
-    enum DeliveryMode
-    {
+    enum DeliveryMode {
         Fixed = 0x0,
         LowPriority = 0x1,
         SMI = 0x2,
@@ -69,31 +68,27 @@ public:
         INIT = 0x5,
         StartUp = 0x6,
     };
-    enum DestinationMode
-    {
+    enum DestinationMode {
         Physical = 0x0,
         Logical = 0x0,
     };
-    enum Level
-    {
+    enum Level {
         DeAssert = 0x0,
         Assert = 0x1
     };
-    enum class TriggerMode
-    {
+    enum class TriggerMode {
         Edge = 0x0,
         Level = 0x1,
     };
-    enum DestinationShorthand
-    {
+    enum DestinationShorthand {
         NoShorthand = 0x0,
         Self = 0x1,
         AllIncludingSelf = 0x2,
         AllExcludingSelf = 0x3,
     };
 
-    ICRReg(u8 vector, DeliveryMode delivery_mode, DestinationMode destination_mode, Level level, TriggerMode trigger_mode, DestinationShorthand destination):
-        m_reg(vector | (delivery_mode << 8) | (destination_mode << 11) | (level << 14) | (static_cast<u32>(trigger_mode) << 15) | (destination << 18))
+    ICRReg(u8 vector, DeliveryMode delivery_mode, DestinationMode destination_mode, Level level, TriggerMode trigger_mode, DestinationShorthand destination)
+        : m_reg(vector | (delivery_mode << 8) | (destination_mode << 11) | (level << 14) | (static_cast<u32>(trigger_mode) << 15) | (destination << 18))
     {
     }
 
@@ -180,38 +175,40 @@ bool init()
 void enable(u32 cpu)
 {
     kprintf("Enabling local APIC for cpu #%u\n", cpu);
-    
+
     // set spurious interrupt vector
     apic_write(APIC_REG_SIV, apic_read(APIC_REG_SIV) | 0x100);
-    
+
     // local destination mode (flat mode)
     apic_write(APIC_REG_DF, 0xf000000);
-    
+
     // set destination id (note that this limits it to 8 cpus)
     apic_write(APIC_REG_LD, (1 << cpu) << 24);
-    
+
     register_interrupt_handler(IRQ_APIC_SPURIOUS, apic_spurious_interrupt_entry);
-    
+
     apic_write(APIC_REG_LVT_TIMER, APIC_LVT(0xff, 0) | APIC_LVT_MASKED);
     apic_write(APIC_REG_LVT_THERMAL, APIC_LVT(0xff, 0) | APIC_LVT_MASKED);
     apic_write(APIC_REG_LVT_PERFORMANCE_COUNTER, APIC_LVT(0xff, 0) | APIC_LVT_MASKED);
     apic_write(APIC_REG_LVT_LINT0, APIC_LVT(0x1f, 7) | APIC_LVT_MASKED);
     apic_write(APIC_REG_LVT_LINT1, APIC_LVT(0xff, 4) | APIC_LVT_TRIGGER_LEVEL); // nmi
     apic_write(APIC_REG_LVT_ERR, APIC_LVT(0xe3, 0) | APIC_LVT_MASKED);
-    
+
     if (cpu == 0) {
         static volatile u32 foo = 0;
-        
+
         // INIT
         apic_write_icr(ICRReg(0, ICRReg::INIT, ICRReg::Physical, ICRReg::Assert, ICRReg::TriggerMode::Edge, ICRReg::AllExcludingSelf));
 
-        for (foo = 0; foo < 0x800000; foo++); // TODO: 10 millisecond delay
+        for (foo = 0; foo < 0x800000; foo++)
+            ; // TODO: 10 millisecond delay
 
         for (int i = 0; i < 2; i++) {
             // SIPI
             apic_write_icr(ICRReg(0x08, ICRReg::StartUp, ICRReg::Physical, ICRReg::Assert, ICRReg::TriggerMode::Edge, ICRReg::AllExcludingSelf)); // start execution at P8000
 
-            for (foo = 0; foo < 0x80000; foo++); // TODO: 200 microsecond delay
+            for (foo = 0; foo < 0x80000; foo++)
+                ; // TODO: 200 microsecond delay
         }
     }
 }

+ 1 - 1
Kernel/Arch/i386/CPU.h

@@ -30,7 +30,7 @@
 #include <AK/Noncopyable.h>
 #include <Kernel/VM/PhysicalAddress.h>
 #include <Kernel/VM/VirtualAddress.h>
-#include <Kernel/kstdio.h>
+#include <LibBareMetal/Output/kstdio.h>
 
 #define PAGE_SIZE 4096
 #define PAGE_MASK ((uintptr_t)0xfffff000u)

+ 1 - 2
Kernel/Arch/i386/PIC.cpp

@@ -28,7 +28,7 @@
 #include <AK/Types.h>
 #include <Kernel/Arch/i386/CPU.h>
 #include <Kernel/Arch/i386/PIC.h>
-#include <Kernel/IO.h>
+#include <LibBareMetal/IO.h>
 
 // The slave 8259 is connected to the master's IRQ2 line.
 // This is really only to enhance clarity.
@@ -137,4 +137,3 @@ u16 get_irr()
 }
 
 }
-

+ 1 - 1
Kernel/Arch/i386/PIT.cpp

@@ -27,8 +27,8 @@
 #include <Kernel/Arch/i386/CPU.h>
 #include <Kernel/Arch/i386/PIC.h>
 #include <Kernel/Arch/i386/PIT.h>
-#include <Kernel/IO.h>
 #include <Kernel/Scheduler.h>
+#include <LibBareMetal/IO.h>
 
 #define IRQ_TIMER 0
 

+ 1 - 1
Kernel/Assertions.h

@@ -27,7 +27,7 @@
 #pragma once
 
 #include <Kernel/Arch/i386/CPU.h>
-#include <Kernel/kstdio.h>
+#include <LibBareMetal/Output/kstdio.h>
 
 #ifdef DEBUG
 [[noreturn]] void __assertion_failed(const char* msg, const char* file, unsigned line, const char* func);

+ 1 - 1
Kernel/CMOS.cpp

@@ -25,7 +25,7 @@
  */
 
 #include <Kernel/CMOS.h>
-#include <Kernel/IO.h>
+#include <LibBareMetal/IO.h>
 
 namespace CMOS {
 

+ 0 - 93
Kernel/Console.cpp

@@ -1,93 +0,0 @@
-/*
- * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this
- *    list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- *    this list of conditions and the following disclaimer in the documentation
- *    and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <Kernel/Console.h>
-#include <Kernel/IO.h>
-#include <Kernel/kstdio.h>
-
-// Bytes output to 0xE9 end up on the Bochs console. It's very handy.
-#define CONSOLE_OUT_TO_E9
-
-static Console* s_the;
-
-Console& Console::the()
-{
-    ASSERT(s_the);
-    return *s_the;
-}
-
-bool Console::is_initialized()
-{
-    return s_the != nullptr;
-}
-
-Console::Console()
-    : CharacterDevice(5, 1)
-{
-    s_the = this;
-}
-
-Console::~Console()
-{
-}
-
-bool Console::can_read(const FileDescription&) const
-{
-    return false;
-}
-
-ssize_t Console::read(FileDescription&, u8*, ssize_t)
-{
-    // FIXME: Implement reading from the console.
-    //        Maybe we could use a ring buffer for this device?
-    return 0;
-}
-
-ssize_t Console::write(FileDescription&, const u8* data, ssize_t size)
-{
-    if (!size)
-        return 0;
-    if (!m_implementation)
-        return 0;
-    for (ssize_t i = 0; i < size; ++i)
-        put_char(data[i]);
-    return size;
-}
-
-void Console::put_char(char ch)
-{
-#ifdef CONSOLE_OUT_TO_E9
-    //if (ch != 27)
-    IO::out8(0xe9, ch);
-#endif
-    m_logbuffer.enqueue(ch);
-    if (m_implementation)
-        m_implementation->on_sysconsole_receive(ch);
-}
-
-ConsoleImplementation::~ConsoleImplementation()
-{
-}

+ 0 - 64
Kernel/Console.h

@@ -1,64 +0,0 @@
-/*
- * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this
- *    list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- *    this list of conditions and the following disclaimer in the documentation
- *    and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#pragma once
-
-#include <AK/CircularQueue.h>
-#include <AK/Vector.h>
-#include <Kernel/Devices/CharacterDevice.h>
-
-class ConsoleImplementation {
-public:
-    virtual ~ConsoleImplementation();
-    virtual void on_sysconsole_receive(u8) = 0;
-};
-
-class Console final : public CharacterDevice {
-    AK_MAKE_ETERNAL
-public:
-    static Console& the();
-    static bool is_initialized();
-
-    Console();
-    virtual ~Console() override;
-
-    // ^CharacterDevice
-    virtual bool can_read(const FileDescription&) const override;
-    virtual bool can_write(const FileDescription&) const override { return true; }
-    virtual ssize_t read(FileDescription&, u8*, ssize_t) override;
-    virtual ssize_t write(FileDescription&, const u8*, ssize_t) override;
-    virtual const char* class_name() const override { return "Console"; }
-
-    void set_implementation(ConsoleImplementation* implementation) { m_implementation = implementation; }
-
-    void put_char(char);
-
-    const CircularQueue<char, 16384>& logbuffer() const { return m_logbuffer; }
-
-private:
-    ConsoleImplementation* m_implementation { nullptr };
-    CircularQueue<char, 16384> m_logbuffer;
-};

+ 1 - 1
Kernel/Devices/BXVGADevice.cpp

@@ -25,11 +25,11 @@
  */
 
 #include <Kernel/Devices/BXVGADevice.h>
-#include <Kernel/IO.h>
 #include <Kernel/PCI/Access.h>
 #include <Kernel/Process.h>
 #include <Kernel/VM/AnonymousVMObject.h>
 #include <Kernel/VM/MemoryManager.h>
+#include <LibBareMetal/IO.h>
 #include <LibC/errno_numbers.h>
 #include <LibC/sys/ioctl_numbers.h>
 

+ 1 - 1
Kernel/Devices/DebugLogDevice.cpp

@@ -25,7 +25,7 @@
  */
 
 #include <Kernel/Devices/DebugLogDevice.h>
-#include <Kernel/IO.h>
+#include <LibBareMetal/IO.h>
 
 static DebugLogDevice* s_the;
 

+ 1 - 1
Kernel/Devices/FloppyDiskDevice.cpp

@@ -27,9 +27,9 @@
 #include <Kernel/Arch/i386/PIT.h>
 #include <Kernel/Devices/FloppyDiskDevice.h>
 #include <Kernel/FileSystem/ProcFS.h>
-#include <Kernel/IO.h>
 #include <Kernel/Process.h>
 #include <Kernel/VM/MemoryManager.h>
+#include <LibBareMetal/IO.h>
 
 // Uncomment me for a LOT of output
 //#define FLOPPY_DEBUG

+ 1 - 1
Kernel/Devices/KeyboardDevice.cpp

@@ -29,8 +29,8 @@
 #include <Kernel/Arch/i386/CPU.h>
 #include <Kernel/Arch/i386/PIC.h>
 #include <Kernel/Devices/KeyboardDevice.h>
-#include <Kernel/IO.h>
 #include <Kernel/TTY/VirtualConsole.h>
+#include <LibBareMetal/IO.h>
 
 //#define KEYBOARD_DEBUG
 

+ 1 - 1
Kernel/Devices/PATAChannel.cpp

@@ -28,9 +28,9 @@
 #include <AK/ByteBuffer.h>
 #include <Kernel/Devices/PATAChannel.h>
 #include <Kernel/FileSystem/ProcFS.h>
-#include <Kernel/IO.h>
 #include <Kernel/Process.h>
 #include <Kernel/VM/MemoryManager.h>
+#include <LibBareMetal/IO.h>
 
 #define PATA_PRIMARY_IRQ 14
 #define PATA_SECONDARY_IRQ 15

+ 1 - 1
Kernel/Devices/PCSpeaker.cpp

@@ -27,7 +27,7 @@
 #include <Kernel/Arch/i386/CPU.h>
 #include <Kernel/Arch/i386/PIT.h>
 #include <Kernel/Devices/PCSpeaker.h>
-#include <Kernel/IO.h>
+#include <LibBareMetal/IO.h>
 
 void PCSpeaker::tone_on(int frequency)
 {

+ 1 - 1
Kernel/Devices/PS2MouseDevice.cpp

@@ -26,7 +26,7 @@
 
 #include <Kernel/Devices/PS2MouseDevice.h>
 #include <Kernel/Devices/VMWareBackdoor.h>
-#include <Kernel/IO.h>
+#include <LibBareMetal/IO.h>
 
 #define IRQ_MOUSE 12
 #define I8042_BUFFER 0x60

+ 1 - 1
Kernel/Devices/SB16.cpp

@@ -25,10 +25,10 @@
  */
 
 #include <Kernel/Devices/SB16.h>
-#include <Kernel/IO.h>
 #include <Kernel/Thread.h>
 #include <Kernel/VM/AnonymousVMObject.h>
 #include <Kernel/VM/MemoryManager.h>
+#include <LibBareMetal/IO.h>
 
 //#define SB16_DEBUG
 

+ 3 - 3
Kernel/Devices/SerialDevice.cpp

@@ -25,7 +25,7 @@
  */
 
 #include <Kernel/Devices/SerialDevice.h>
-#include <Kernel/IO.h>
+#include <LibBareMetal/IO.h>
 
 SerialDevice::SerialDevice(int base_addr, unsigned minor)
     : CharacterDevice(4, minor)
@@ -95,8 +95,8 @@ void SerialDevice::set_baud(Baud baud)
     m_baud = baud;
 
     IO::out8(m_base_addr + 3, IO::in8(m_base_addr + 3) | 0x80); // turn on DLAB
-    IO::out8(m_base_addr + 0, ((char)(baud)) >> 2); // lower half of divisor
-    IO::out8(m_base_addr + 1, ((char)(baud)) & 0xff); // upper half of divisor
+    IO::out8(m_base_addr + 0, ((char)(baud)) >> 2);             // lower half of divisor
+    IO::out8(m_base_addr + 1, ((char)(baud)) & 0xff);           // upper half of divisor
     IO::out8(m_base_addr + 3, IO::in8(m_base_addr + 3) & 0x7f); // turn off DLAB
 }
 

+ 1 - 1
Kernel/Devices/VMWareBackdoor.cpp

@@ -28,7 +28,7 @@
 #include <AK/String.h>
 #include <Kernel/Arch/i386/CPU.h>
 #include <Kernel/Devices/VMWareBackdoor.h>
-#include <Kernel/IO.h>
+#include <LibBareMetal/IO.h>
 
 #define VMWARE_CMD_GETVERSION 0x0a
 

+ 2 - 2
Kernel/FileSystem/ProcFS.cpp

@@ -25,11 +25,9 @@
  */
 
 #include "ProcFS.h"
-#include "Console.h"
 #include "KSyms.h"
 #include "Process.h"
 #include "Scheduler.h"
-#include "StdLib.h"
 #include <AK/JsonArraySerializer.h>
 #include <AK/JsonObject.h>
 #include <AK/JsonObjectSerializer.h>
@@ -52,6 +50,8 @@
 #include <Kernel/Profiling.h>
 #include <Kernel/VM/MemoryManager.h>
 #include <Kernel/VM/PurgeableVMObject.h>
+#include <LibBareMetal/Output/Console.h>
+#include <LibBareMetal/StdLib.h>
 #include <LibC/errno_numbers.h>
 
 enum ProcParentDirectory {

+ 2 - 3
Kernel/Heap/kmalloc.cpp

@@ -32,11 +32,11 @@
 #include <AK/Assertions.h>
 #include <AK/Types.h>
 #include <Kernel/Arch/i386/CPU.h>
+#include <Kernel/Heap/kmalloc.h>
 #include <Kernel/KSyms.h>
 #include <Kernel/Process.h>
 #include <Kernel/Scheduler.h>
-#include <Kernel/StdLib.h>
-#include <Kernel/Heap/kmalloc.h>
+#include <LibBareMetal/StdLib.h>
 
 #define SANITIZE_KMALLOC
 
@@ -231,4 +231,3 @@ void* operator new[](size_t size)
 {
     return kmalloc(size);
 }
-

+ 0 - 100
Kernel/IO.h

@@ -1,100 +0,0 @@
-/*
- * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this
- *    list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- *    this list of conditions and the following disclaimer in the documentation
- *    and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#pragma once
-
-#include <AK/Types.h>
-#include <Kernel/Arch/i386/CPU.h>
-#include <Kernel/Devices/VMWareBackdoor.h>
-
-namespace IO {
-
-inline u8 in8(u16 port)
-{
-    u8 value;
-    asm volatile("inb %1, %0"
-                 : "=a"(value)
-                 : "Nd"(port));
-    return value;
-}
-
-inline u16 in16(u16 port)
-{
-    u16 value;
-    asm volatile("inw %1, %0"
-                 : "=a"(value)
-                 : "Nd"(port));
-    return value;
-}
-
-inline u32 in32(u16 port)
-{
-    u32 value;
-    asm volatile("inl %1, %0"
-                 : "=a"(value)
-                 : "Nd"(port));
-    return value;
-}
-
-inline void repeated_in16(u16 port, u8* buffer, int buffer_size)
-{
-    asm volatile("rep insw"
-                 : "+D"(buffer), "+c"(buffer_size)
-                 : "d"(port)
-                 : "memory");
-}
-
-inline void out8(u16 port, u8 value)
-{
-    asm volatile("outb %0, %1" ::"a"(value), "Nd"(port));
-}
-
-inline void out16(u16 port, u16 value)
-{
-    asm volatile("outw %0, %1" ::"a"(value), "Nd"(port));
-}
-
-inline void out32(u16 port, u32 value)
-{
-    asm volatile("outl %0, %1" ::"a"(value), "Nd"(port));
-}
-
-inline void repeated_out16(u16 port, const u8* data, int data_size)
-{
-    asm volatile("rep outsw"
-                 : "+S"(data), "+c"(data_size)
-                 : "d"(port));
-}
-
-inline void delay()
-{
-    // ~3 microsecs
-    for (auto i = 0; i < 32; i++) {
-        IO::in8(0x80);
-    }
-}
-
-}

+ 4 - 4
Kernel/Makefile

@@ -9,12 +9,14 @@ OBJS = \
     ../AK/StringView.o \
     ../Libraries/LibELF/ELFImage.o \
     ../Libraries/LibELF/ELFLoader.o \
+    ../Libraries/LibBareMetal/Output/Console.o \
+    ../Libraries/LibBareMetal/Output/kprintf.o \
+    ../Libraries/LibBareMetal/StdLib.o \
     Arch/i386/APIC.o \
     Arch/i386/CPU.o \
     Arch/i386/PIC.o \
     Arch/i386/PIT.o \
     CMOS.o \
-    Console.o \
     Devices/BXVGADevice.o \
     Devices/BlockDevice.o \
     Devices/CharacterDevice.o \
@@ -83,7 +85,6 @@ OBJS = \
     Random.o \
     Scheduler.o \
     SharedBuffer.o \
-    StdLib.o \
     Syscall.o \
     TimerQueue.o \
     TTY/MasterPTY.o \
@@ -107,8 +108,7 @@ OBJS = \
     ACPI/ACPIDynamicParser.o \
     ACPI/DMIDecoder.o \
     WaitQueue.o \
-    init.o \
-    kprintf.o
+    init.o
 
 OBJ_SUFFIX = .kernel
 

+ 1 - 1
Kernel/Net/E1000NetworkAdapter.cpp

@@ -24,9 +24,9 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <Kernel/IO.h>
 #include <Kernel/Net/E1000NetworkAdapter.h>
 #include <Kernel/Thread.h>
+#include <LibBareMetal/IO.h>
 
 //#define E1000_DEBUG
 

+ 1 - 1
Kernel/Net/LocalSocket.cpp

@@ -29,8 +29,8 @@
 #include <Kernel/FileSystem/VirtualFileSystem.h>
 #include <Kernel/Net/LocalSocket.h>
 #include <Kernel/Process.h>
-#include <Kernel/StdLib.h>
 #include <Kernel/UnixTypes.h>
+#include <LibBareMetal/StdLib.h>
 #include <LibC/errno_numbers.h>
 
 //#define DEBUG_LOCAL_SOCKET

+ 2 - 2
Kernel/Net/MACAddress.h

@@ -26,10 +26,10 @@
 
 #pragma once
 
-#include <AK/String.h>
 #include <AK/Assertions.h>
+#include <AK/String.h>
 #include <AK/Types.h>
-#include <Kernel/StdLib.h>
+#include <LibBareMetal/StdLib.h>
 
 class [[gnu::packed]] MACAddress
 {

+ 1 - 1
Kernel/Net/NetworkAdapter.cpp

@@ -32,7 +32,7 @@
 #include <Kernel/Net/EthernetFrameHeader.h>
 #include <Kernel/Net/LoopbackAdapter.h>
 #include <Kernel/Net/NetworkAdapter.h>
-#include <Kernel/StdLib.h>
+#include <LibBareMetal/StdLib.h>
 
 static Lockable<HashTable<NetworkAdapter*>>& all_adapters()
 {

+ 1 - 1
Kernel/Net/RTL8139NetworkAdapter.cpp

@@ -24,8 +24,8 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <Kernel/IO.h>
 #include <Kernel/Net/RTL8139NetworkAdapter.h>
+#include <LibBareMetal/IO.h>
 
 //#define RTL8139_DEBUG
 

+ 1 - 1
Kernel/PCI/IOAccess.cpp

@@ -24,8 +24,8 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <Kernel/IO.h>
 #include <Kernel/PCI/IOAccess.h>
+#include <LibBareMetal/IO.h>
 
 void PCI::IOAccess::initialize()
 {

+ 1 - 1
Kernel/PCI/Initializer.cpp

@@ -25,13 +25,13 @@
  */
 
 #include <Kernel/ACPI/ACPIParser.h>
-#include <Kernel/IO.h>
 #include <Kernel/KParams.h>
 #include <Kernel/Net/E1000NetworkAdapter.h>
 #include <Kernel/Net/RTL8139NetworkAdapter.h>
 #include <Kernel/PCI/IOAccess.h>
 #include <Kernel/PCI/Initializer.h>
 #include <Kernel/PCI/MMIOAccess.h>
+#include <LibBareMetal/IO.h>
 
 static PCI::Initializer* s_pci_initializer;
 

+ 3 - 4
Kernel/PCI/MMIOAccess.cpp

@@ -25,7 +25,6 @@
  */
 
 #include <AK/Optional.h>
-#include <Kernel/IO.h>
 #include <Kernel/PCI/MMIOAccess.h>
 #include <Kernel/VM/MemoryManager.h>
 
@@ -60,11 +59,11 @@ PCI::MMIOAccess::MMIOAccess(ACPI_RAW::MCFG& raw_mcfg)
     kprintf("PCI: Using MMIO Mechanism for PCI Configuartion Space Access\n");
     m_mmio_window_region = MM.allocate_kernel_region(PAGE_ROUND_UP(PCI_MMIO_CONFIG_SPACE_SIZE), "PCI MMIO", Region::Access::Read | Region::Access::Write);
 
-    auto checkup_region = MM.allocate_kernel_region(PhysicalAddress(page_base_of((u32)&raw_mcfg)),(PAGE_SIZE * 2), "PCI MCFG Checkup", Region::Access::Read | Region::Access::Write);
+    auto checkup_region = MM.allocate_kernel_region(PhysicalAddress(page_base_of((u32)&raw_mcfg)), (PAGE_SIZE * 2), "PCI MCFG Checkup", Region::Access::Read | Region::Access::Write);
 #ifdef PCI_DEBUG
     dbgprintf("PCI: Checking MCFG Table length to choose the correct mapping size\n");
 #endif
-    
+
     ACPI_RAW::SDTHeader* sdt = (ACPI_RAW::SDTHeader*)checkup_region->vaddr().offset(offset_in_page((u32)&raw_mcfg)).as_ptr();
     u32 length = sdt->length;
     u8 revision = sdt->revision;
@@ -114,7 +113,7 @@ void PCI::MMIOAccess::map_device(Address address)
 #ifdef PCI_DEBUG
     dbgprintf("PCI: Mapping device @ pci (%w:%b:%b.%b), V 0x%x, P 0x%x\n", address.seg(), address.bus(), address.slot(), address.function(), m_mmio_window_region->vaddr().get(), device_physical_mmio_space.get());
 #endif
-    m_mmio_window_region->vmobject().physical_pages()[0] = PhysicalPage::create(device_physical_mmio_space,false,false);
+    m_mmio_window_region->vmobject().physical_pages()[0] = PhysicalPage::create(device_physical_mmio_space, false, false);
     m_mmio_window_region->remap();
     m_mapped_address = address;
 }

+ 3 - 3
Kernel/Process.cpp

@@ -33,7 +33,6 @@
 #include <AK/Types.h>
 #include <Kernel/Arch/i386/CPU.h>
 #include <Kernel/Arch/i386/PIT.h>
-#include <Kernel/Console.h>
 #include <Kernel/Devices/KeyboardDevice.h>
 #include <Kernel/Devices/NullDevice.h>
 #include <Kernel/Devices/PCSpeaker.h>
@@ -48,7 +47,6 @@
 #include <Kernel/FileSystem/TmpFS.h>
 #include <Kernel/FileSystem/VirtualFileSystem.h>
 #include <Kernel/Heap/kmalloc.h>
-#include <Kernel/IO.h>
 #include <Kernel/KBufferBuilder.h>
 #include <Kernel/KSyms.h>
 #include <Kernel/KernelInfoPage.h>
@@ -62,12 +60,14 @@
 #include <Kernel/Random.h>
 #include <Kernel/Scheduler.h>
 #include <Kernel/SharedBuffer.h>
-#include <Kernel/StdLib.h>
 #include <Kernel/Syscall.h>
 #include <Kernel/TTY/MasterPTY.h>
 #include <Kernel/Thread.h>
 #include <Kernel/VM/InodeVMObject.h>
 #include <Kernel/VM/PurgeableVMObject.h>
+#include <LibBareMetal/IO.h>
+#include <LibBareMetal/Output/Console.h>
+#include <LibBareMetal/StdLib.h>
 #include <LibC/errno_numbers.h>
 #include <LibC/limits.h>
 #include <LibC/signal_numbers.h>

+ 0 - 254
Kernel/StdLib.cpp

@@ -1,254 +0,0 @@
-/*
- * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this
- *    list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- *    this list of conditions and the following disclaimer in the documentation
- *    and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <AK/Assertions.h>
-#include <AK/String.h>
-#include <AK/Types.h>
-#include <Kernel/Arch/i386/CPU.h>
-#include <Kernel/Heap/kmalloc.h>
-#include <Kernel/StdLib.h>
-#include <Kernel/VM/MemoryManager.h>
-
-String copy_string_from_user(const char* user_str, size_t user_str_size)
-{
-    SmapDisabler disabler;
-    size_t length = strnlen(user_str, user_str_size);
-    return String(user_str, length);
-}
-
-extern "C" {
-
-void copy_to_user(void* dest_ptr, const void* src_ptr, size_t n)
-{
-    ASSERT(is_user_range(VirtualAddress(dest_ptr), n));
-    SmapDisabler disabler;
-    memcpy(dest_ptr, src_ptr, n);
-}
-
-void copy_from_user(void* dest_ptr, const void* src_ptr, size_t n)
-{
-    ASSERT(is_user_range(VirtualAddress(src_ptr), n));
-    SmapDisabler disabler;
-    memcpy(dest_ptr, src_ptr, n);
-}
-
-void* memcpy(void* dest_ptr, const void* src_ptr, size_t n)
-{
-    size_t dest = (size_t)dest_ptr;
-    size_t src = (size_t)src_ptr;
-    // FIXME: Support starting at an unaligned address.
-    if (!(dest & 0x3) && !(src & 0x3) && n >= 12) {
-        size_t size_ts = n / sizeof(size_t);
-        asm volatile(
-            "rep movsl\n"
-            : "=S"(src), "=D"(dest)
-            : "S"(src), "D"(dest), "c"(size_ts)
-            : "memory");
-        n -= size_ts * sizeof(size_t);
-        if (n == 0)
-            return dest_ptr;
-    }
-    asm volatile(
-        "rep movsb\n" ::"S"(src), "D"(dest), "c"(n)
-        : "memory");
-    return dest_ptr;
-}
-
-void* memmove(void* dest, const void* src, size_t n)
-{
-    if (dest < src)
-        return memcpy(dest, src, n);
-
-    u8* pd = (u8*)dest;
-    const u8* ps = (const u8*)src;
-    for (pd += n, ps += n; n--;)
-        *--pd = *--ps;
-    return dest;
-}
-
-char* strcpy(char* dest, const char* src)
-{
-    auto* dest_ptr = dest;
-    auto* src_ptr = src;
-    while ((*dest_ptr++ = *src_ptr++) != '\0')
-        ;
-    return dest;
-}
-
-char* strncpy(char* dest, const char* src, size_t n)
-{
-    size_t i;
-    for (i = 0; i < n && src[i] != '\0'; ++i)
-        dest[i] = src[i];
-    for (; i < n; ++i)
-        dest[i] = '\0';
-    return dest;
-}
-
-void memset_user(void* dest_ptr, int c, size_t n)
-{
-    ASSERT(is_user_range(VirtualAddress(dest_ptr), n));
-    SmapDisabler disabler;
-    memset(dest_ptr, c, n);
-}
-
-void* memset(void* dest_ptr, int c, size_t n)
-{
-    size_t dest = (size_t)dest_ptr;
-    // FIXME: Support starting at an unaligned address.
-    if (!(dest & 0x3) && n >= 12) {
-        size_t size_ts = n / sizeof(size_t);
-        size_t expanded_c = (u8)c;
-        expanded_c |= expanded_c << 8;
-        expanded_c |= expanded_c << 16;
-        asm volatile(
-            "rep stosl\n"
-            : "=D"(dest)
-            : "D"(dest), "c"(size_ts), "a"(expanded_c)
-            : "memory");
-        n -= size_ts * sizeof(size_t);
-        if (n == 0)
-            return dest_ptr;
-    }
-    asm volatile(
-        "rep stosb\n"
-        : "=D"(dest), "=c"(n)
-        : "0"(dest), "1"(n), "a"(c)
-        : "memory");
-    return dest_ptr;
-}
-
-char* strrchr(const char* str, int ch)
-{
-    char* last = nullptr;
-    char c;
-    for (; (c = *str); ++str) {
-        if (c == ch)
-            last = const_cast<char*>(str);
-    }
-    return last;
-}
-
-size_t strlen(const char* str)
-{
-    size_t len = 0;
-    while (*(str++))
-        ++len;
-    return len;
-}
-
-size_t strnlen(const char* str, size_t maxlen)
-{
-    size_t len = 0;
-    for (; len < maxlen && *str; str++)
-        len++;
-    return len;
-}
-
-int strcmp(const char* s1, const char* s2)
-{
-    for (; *s1 == *s2; ++s1, ++s2) {
-        if (*s1 == 0)
-            return 0;
-    }
-    return *(const u8*)s1 < *(const u8*)s2 ? -1 : 1;
-}
-
-char* strdup(const char* str)
-{
-    size_t len = strlen(str);
-    char* new_str = (char*)kmalloc(len + 1);
-    strcpy(new_str, str);
-    return new_str;
-}
-
-int memcmp(const void* v1, const void* v2, size_t n)
-{
-    auto* s1 = (const u8*)v1;
-    auto* s2 = (const u8*)v2;
-    while (n-- > 0) {
-        if (*s1++ != *s2++)
-            return s1[-1] < s2[-1] ? -1 : 1;
-    }
-    return 0;
-}
-
-int strncmp(const char* s1, const char* s2, size_t n)
-{
-    if (!n)
-        return 0;
-    do {
-        if (*s1 != *s2++)
-            return *(const unsigned char*)s1 - *(const unsigned char*)--s2;
-        if (*s1++ == 0)
-            break;
-    } while (--n);
-    return 0;
-}
-
-char* strstr(const char* haystack, const char* needle)
-{
-    char nch;
-    char hch;
-
-    if ((nch = *needle++) != 0) {
-        size_t len = strlen(needle);
-        do {
-            do {
-                if ((hch = *haystack++) == 0)
-                    return nullptr;
-            } while (hch != nch);
-        } while (strncmp(haystack, needle, len) != 0);
-        --haystack;
-    }
-    return const_cast<char*>(haystack);
-}
-
-[[noreturn]] void __cxa_pure_virtual()
-{
-    ASSERT_NOT_REACHED();
-}
-
-void* realloc(void* p, size_t s)
-{
-    return krealloc(p, s);
-}
-
-void free(void* p)
-{
-    return kfree(p);
-}
-
-[[noreturn]] void __stack_chk_fail()
-{
-    ASSERT_NOT_REACHED();
-}
-
-[[noreturn]] void __stack_chk_fail_local()
-{
-    ASSERT_NOT_REACHED();
-}
-}

+ 0 - 76
Kernel/StdLib.h

@@ -1,76 +0,0 @@
-/*
- * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this
- *    list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- *    this list of conditions and the following disclaimer in the documentation
- *    and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#pragma once
-
-#include <AK/Types.h>
-
-namespace AK {
-class String;
-}
-
-namespace Syscall {
-struct StringArgument;
-}
-
-AK::String copy_string_from_user(const char*, size_t);
-
-extern "C" {
-
-static_assert(sizeof(size_t) == 4);
-
-void copy_to_user(void*, const void*, size_t);
-void copy_from_user(void*, const void*, size_t);
-void memset_user(void*, int, size_t);
-
-void* memcpy(void*, const void*, size_t);
-char* strcpy(char*, const char*);
-char* strncpy(char*, const char*, size_t);
-int strncmp(const char* s1, const char* s2, size_t n);
-int strcmp(char const*, const char*);
-size_t strlen(const char*);
-size_t strnlen(const char*, size_t);
-void* memset(void*, int, size_t);
-char* strdup(const char*);
-int memcmp(const void*, const void*, size_t);
-char* strrchr(const char* str, int ch);
-void* memmove(void* dest, const void* src, size_t n);
-
-inline u16 ntohs(u16 w) { return (w & 0xff) << 8 | ((w >> 8) & 0xff); }
-inline u16 htons(u16 w) { return (w & 0xff) << 8 | ((w >> 8) & 0xff); }
-}
-
-template<typename T>
-inline void copy_from_user(T* dest, const T* src)
-{
-    copy_from_user(dest, src, sizeof(T));
-}
-
-template<typename T>
-inline void copy_to_user(T* dest, const T* src)
-{
-    copy_to_user(dest, src, sizeof(T));
-}

+ 3 - 3
Kernel/TTY/VirtualConsole.cpp

@@ -25,12 +25,12 @@
  */
 
 #include "VirtualConsole.h"
-#include "IO.h"
-#include "StdLib.h"
-#include <Kernel/Heap/kmalloc.h>
 #include <AK/String.h>
 #include <Kernel/Arch/i386/CPU.h>
 #include <Kernel/Devices/KeyboardDevice.h>
+#include <Kernel/Heap/kmalloc.h>
+#include <LibBareMetal/IO.h>
+#include <LibBareMetal/StdLib.h>
 
 static u8* s_vga_buffer;
 static VirtualConsole* s_consoles[6];

+ 1 - 1
Kernel/TTY/VirtualConsole.h

@@ -26,9 +26,9 @@
 
 #pragma once
 
-#include "Console.h"
 #include <Kernel/Devices/KeyboardDevice.h>
 #include <Kernel/TTY/TTY.h>
+#include <LibBareMetal/Output/Console.h>
 
 class VirtualConsole final : public TTY
     , public KeyboardClient

+ 1 - 1
Kernel/TestModule.cpp

@@ -24,8 +24,8 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <Kernel/kstdio.h>
 #include <Kernel/Process.h>
+#include <LibBareMetal/Output/kstdio.h>
 
 extern "C" const char module_name[] = "TestModule";
 

+ 1 - 1
Kernel/VM/MemoryManager.cpp

@@ -26,7 +26,6 @@
 
 #include "CMOS.h"
 #include "Process.h"
-#include "StdLib.h"
 #include <AK/Assertions.h>
 #include <AK/kstdio.h>
 #include <Kernel/Arch/i386/CPU.h>
@@ -36,6 +35,7 @@
 #include <Kernel/VM/InodeVMObject.h>
 #include <Kernel/VM/MemoryManager.h>
 #include <Kernel/VM/PurgeableVMObject.h>
+#include <LibBareMetal/StdLib.h>
 
 //#define MM_DEBUG
 //#define PAGE_FAULT_DEBUG

+ 12 - 8
Kernel/VM/RangeAllocator.cpp

@@ -27,9 +27,9 @@
 #include <AK/BinarySearch.h>
 #include <AK/QuickSort.h>
 #include <Kernel/Random.h>
-#include <Kernel/VM/RangeAllocator.h>
-#include <Kernel/kstdio.h>
 #include <Kernel/Thread.h>
+#include <Kernel/VM/RangeAllocator.h>
+#include <LibBareMetal/Output/kstdio.h>
 
 //#define VRA_DEBUG
 #define VM_GUARD_PAGES
@@ -162,18 +162,22 @@ void RangeAllocator::deallocate(Range range)
     ASSERT(!m_available_ranges.is_empty());
 
     int nearby_index = 0;
-    auto* existing_range = binary_search(m_available_ranges.data(), m_available_ranges.size(), range, [](auto& a, auto& b) {
-        return a.base().get() - b.end().get();
-    }, &nearby_index);
+    auto* existing_range = binary_search(
+        m_available_ranges.data(), m_available_ranges.size(), range, [](auto& a, auto& b) {
+            return a.base().get() - b.end().get();
+        },
+        &nearby_index);
 
     int inserted_index = 0;
     if (existing_range) {
         existing_range->m_size += range.size();
         inserted_index = nearby_index;
     } else {
-        m_available_ranges.insert_before_matching(Range(range), [&](auto& entry) {
-            return entry.base() >= range.end();
-        }, nearby_index, &inserted_index);
+        m_available_ranges.insert_before_matching(
+            Range(range), [&](auto& entry) {
+                return entry.base() >= range.end();
+            },
+            nearby_index, &inserted_index);
     }
 
     if (inserted_index < (m_available_ranges.size() - 1)) {

+ 1 - 1
Kernel/init.cpp

@@ -29,7 +29,6 @@
 #include "Process.h"
 #include "RTC.h"
 #include "Scheduler.h"
-#include "kstdio.h"
 #include <AK/Types.h>
 #include <Kernel/ACPI/ACPIDynamicParser.h>
 #include <Kernel/ACPI/ACPIStaticParser.h>
@@ -71,6 +70,7 @@
 #include <Kernel/TTY/PTYMultiplexer.h>
 #include <Kernel/TTY/VirtualConsole.h>
 #include <Kernel/VM/MemoryManager.h>
+#include <LibBareMetal/Output/kstdio.h>
 
 [[noreturn]] static void init_stage2();
 static void setup_serial_debug();

+ 0 - 163
Kernel/kprintf.cpp

@@ -1,163 +0,0 @@
-/*
- * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this
- *    list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- *    this list of conditions and the following disclaimer in the documentation
- *    and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <AK/PrintfImplementation.h>
-#include <AK/Types.h>
-#include <Kernel/Console.h>
-#include <Kernel/IO.h>
-#include <Kernel/Process.h>
-#include <Kernel/kstdio.h>
-#include <LibC/stdarg.h>
-
-static bool serial_debug;
-
-void set_serial_debug(bool on_or_off)
-{
-    serial_debug = on_or_off;
-}
-
-int get_serial_debug()
-{
-    return serial_debug;
-}
-
-static void color_on()
-{
-    IO::out8(0xe9, 0x1b);
-    IO::out8(0xe9, '[');
-    IO::out8(0xe9, '3');
-    IO::out8(0xe9, '6');
-    IO::out8(0xe9, 'm');
-}
-
-static void color_off()
-{
-    IO::out8(0xe9, 0x1b);
-    IO::out8(0xe9, '[');
-    IO::out8(0xe9, '0');
-    IO::out8(0xe9, 'm');
-}
-
-static void serial_putch(char ch)
-{
-    static bool serial_ready = false;
-    static bool was_cr = false;
-
-    if (!serial_ready) {
-        IO::out8(0x3F8 + 1, 0x00);
-        IO::out8(0x3F8 + 3, 0x80);
-        IO::out8(0x3F8 + 0, 0x02);
-        IO::out8(0x3F8 + 1, 0x00);
-        IO::out8(0x3F8 + 3, 0x03);
-        IO::out8(0x3F8 + 2, 0xC7);
-        IO::out8(0x3F8 + 4, 0x0B);
-
-        serial_ready = true;
-    }
-
-    while ((IO::in8(0x3F8 + 5) & 0x20) == 0)
-        ;
-
-    if (ch == '\n' && !was_cr)
-        IO::out8(0x3F8, '\r');
-
-    IO::out8(0x3F8, ch);
-
-    if (ch == '\r')
-        was_cr = true;
-    else
-        was_cr = false;
-}
-
-static void console_putch(char*&, char ch)
-{
-    if (serial_debug)
-        serial_putch(ch);
-
-    // It would be bad to reach the assert in Console()::the() and do a stack overflow
-
-    if (Console::is_initialized()) {
-        Console::the().put_char(ch);
-    } else {
-        IO::out8(0xe9, ch);
-    }
-}
-
-int kprintf(const char* fmt, ...)
-{
-    color_on();
-    va_list ap;
-    va_start(ap, fmt);
-    int ret = printf_internal(console_putch, nullptr, fmt, ap);
-    va_end(ap);
-    color_off();
-    return ret;
-}
-
-static void buffer_putch(char*& bufptr, char ch)
-{
-    *bufptr++ = ch;
-}
-
-int sprintf(char* buffer, const char* fmt, ...)
-{
-    va_list ap;
-    va_start(ap, fmt);
-    int ret = printf_internal(buffer_putch, buffer, fmt, ap);
-    buffer[ret] = '\0';
-    va_end(ap);
-    return ret;
-}
-
-static void debugger_out(char ch)
-{
-    if (serial_debug)
-        serial_putch(ch);
-    IO::out8(0xe9, ch);
-}
-
-static void debugger_putch(char*&, char ch)
-{
-    debugger_out(ch);
-}
-
-extern "C" int dbgputstr(const char* characters, int length)
-{
-    for (int i = 0; i < length; ++i)
-        debugger_out(characters[i]);
-    return 0;
-}
-
-extern "C" int dbgprintf(const char* fmt, ...)
-{
-    color_on();
-    va_list ap;
-    va_start(ap, fmt);
-    int ret = printf_internal(debugger_putch, nullptr, fmt, ap);
-    va_end(ap);
-    color_off();
-    return ret;
-}

+ 0 - 56
Kernel/kstdio.h

@@ -1,56 +0,0 @@
-/*
- * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this
- *    list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- *    this list of conditions and the following disclaimer in the documentation
- *    and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#pragma once
-
-#include <AK/Types.h>
-
-extern "C" {
-int dbgprintf(const char* fmt, ...);
-int dbgputstr(const char*, int);
-int kprintf(const char* fmt, ...);
-int sprintf(char* buf, const char* fmt, ...);
-void set_serial_debug(bool on_or_off);
-int get_serial_debug();
-}
-
-#ifdef KERNEL
-#    define printf dbgprintf
-#endif
-
-#ifndef __serenity__
-#define dbgprintf printf
-#endif
-
-#ifdef __cplusplus
-
-template <size_t N>
-inline int dbgputstr(const char (&array)[N])
-{
-    return ::dbgputstr(array, N);
-}
-
-#endif