[haiku-commits] haiku: hrev44164 - src/system/boot/platform/raspberrypi_arm

  • From: kallisti5@xxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Wed, 16 May 2012 02:34:58 +0200 (CEST)

hrev44164 adds 2 changesets to branch 'master'
old head: 3af608ada59d12d73608a045de66d425eedf7003
new head: 6e11d185ae02c18318f4aecf3a080771544b14cc

----------------------------------------------------------------------------

aeb2376: rpi: Add debug code from u-boot code
  
  * Cleaned up a bit
  * Add panic function
  * Add printd function
  
  Signed-off-by: Alexander von Gluck IV <kallisti5@xxxxxxxxxxx>

                                [ Johannes Wischert <johanneswi@xxxxxxxxx> ]

6e11d18: rpi: Add console code
  
  * Pretty much cleaned up 1:1 u-boot code
  * Thanks to Johannes Wischert for the initial work here

                          [ Alexander von Gluck IV <kallisti5@xxxxxxxxxxx> ]

----------------------------------------------------------------------------

2 files changed, 177 insertions(+), 38 deletions(-)
.../boot/platform/raspberrypi_arm/console.cpp      |  170 ++++++++++++----
src/system/boot/platform/raspberrypi_arm/debug.cpp |   45 +++-

############################################################################

Commit:      aeb2376cdd3f91c1c1a202a91b6b53cdd4442c5a
URL:         http://cgit.haiku-os.org/haiku/commit/?id=aeb2376
Author:      Johannes Wischert <johanneswi@xxxxxxxxx>
Date:        Wed May 16 00:02:54 2012 UTC
Committer:   Alexander von Gluck IV <kallisti5@xxxxxxxxxxx>
Commit-Date: Wed May 16 00:05:54 2012 UTC

rpi: Add debug code from u-boot code

* Cleaned up a bit
* Add panic function
* Add printd function

Signed-off-by: Alexander von Gluck IV <kallisti5@xxxxxxxxxxx>

----------------------------------------------------------------------------

diff --git a/src/system/boot/platform/raspberrypi_arm/debug.cpp 
b/src/system/boot/platform/raspberrypi_arm/debug.cpp
index 091cb41..4e47bc7 100644
--- a/src/system/boot/platform/raspberrypi_arm/debug.cpp
+++ b/src/system/boot/platform/raspberrypi_arm/debug.cpp
@@ -1,25 +1,62 @@
 /*
+ * Copyright 2004-2005, Axel Dörfler, axeld@xxxxxxxxxxxxxxxxx
+ * All rights reserved. Distributed under the terms of the MIT License.
+ *
  * Copyright 2009 Jonas Sundström, jonas@xxxxxxxxxxx
  * All rights reserved. Distributed under the terms of the MIT License.
  */
 
 
+#include "serial.h"
+
 #include <boot/platform.h>
 #include <boot/stdio.h>
 #include <stdarg.h>
 
 
-void
+extern "C" void
 panic(const char* format, ...)
 {
-#warning IMPLEMENT panic
+       const char hint[] = "*** PANIC ***";
+       char buffer[512];
+       va_list list;
+       int length;
+
+       serial_puts(hint, sizeof(hint));
+       va_start(list, format);
+       length = vsnprintf(buffer, sizeof(buffer), format, list);
+       va_end(list);
+
+       if (length >= (int)sizeof(buffer))
+               length = sizeof(buffer) - 1;
+
+       serial_puts(buffer, length);
+       //fprintf(stderr, "%s", buffer);
+
+       serial_puts("\nPress key to reboot.", 21);
+
+       platform_exit();
 }
 
 
-void
+extern "C" void
 dprintf(const char* format, ...)
 {
-#warning IMPLEMENT dprintf
+       char buffer[512];
+       va_list list;
+       int length;
+
+       va_start(list, format);
+       length = vsnprintf(buffer, sizeof(buffer), format, list);
+       va_end(list);
+
+       if (length >= (int)sizeof(buffer))
+               length = sizeof(buffer) - 1;
+
+       serial_puts(buffer, length);
+
+       if (platform_boot_options() & BOOT_OPTION_DEBUG_OUTPUT)
+               fprintf(stderr, "%s", buffer);
 }
 
 

############################################################################

Revision:    hrev44164
Commit:      6e11d185ae02c18318f4aecf3a080771544b14cc
URL:         http://cgit.haiku-os.org/haiku/commit/?id=6e11d18
Author:      Alexander von Gluck IV <kallisti5@xxxxxxxxxxx>
Date:        Wed May 16 00:33:41 2012 UTC

rpi: Add console code

* Pretty much cleaned up 1:1 u-boot code
* Thanks to Johannes Wischert for the initial work here

----------------------------------------------------------------------------

diff --git a/src/system/boot/platform/raspberrypi_arm/console.cpp 
b/src/system/boot/platform/raspberrypi_arm/console.cpp
index a79b0ea..5a12a31 100644
--- a/src/system/boot/platform/raspberrypi_arm/console.cpp
+++ b/src/system/boot/platform/raspberrypi_arm/console.cpp
@@ -1,32 +1,57 @@
 /*
+ * Copyright 2004-2005, Axel D?rfler, axeld@xxxxxxxxxxxxxxxxx
+ * All rights reserved. Distributed under the terms of the MIT License.
+ *
  * Copyright 2009 Jonas Sundström, jonas@xxxxxxxxxxx
  * All rights reserved. Distributed under the terms of the MIT License.
  */
 
 
 #include "console.h"
+#include "keyboard.h"
+#include "serial.h"
 
 #include <SupportDefs.h>
+#include <util/kernel_cpp.h>
+#include <boot/stage2.h>
 
-#include "keyboard.h"
+#include <string.h>
 
 
 class Console : public ConsoleNode {
 public:
-                                                               Console();
+                                                       Console();
+
+       virtual ssize_t                 ReadAt(void* cookie, off_t pos, void* 
buffer,
+                                                               size_t 
bufferSize);
+       virtual ssize_t                 WriteAt(void* cookie, off_t pos,
+                                                               const void* 
buffer, size_t bufferSize);
+};
+
+
+class VTConsole : public ConsoleNode {
+public:
+                                                       VTConsole();
+                       void                    ClearScreen();
+                       void                    SetCursor(int32 x, int32 y);
+                       void                    SetColor(int32 foreground, 
int32 background);
+};
+
+
+class SerialConsole : public VTConsole {
+public:
+                                                       SerialConsole();
 
-       virtual ssize_t                         ReadAt(void* cookie, off_t pos, 
void* buffer,
-                                                                       size_t 
bufferSize);
-       virtual ssize_t                         WriteAt(void* cookie, off_t pos,
-                                                                       const 
void* buffer, size_t bufferSize);
+       virtual ssize_t                 ReadAt(void *cookie, off_t pos, void 
*buffer,
+                                                               size_t 
bufferSize);
+       virtual ssize_t                 WriteAt(void *cookie, off_t pos, const 
void *buffer,
+                                                               size_t 
bufferSize);
 };
 
-static uint32 sScreenWidth = 80;
-static uint32 sScreenHeight = 25;
-static uint32 sScreenOffset = 0;
-static uint16 sColor = 0x0f00;
 
-static Console sInput, sOutput;
+static Console sInput;
+static Console sOutput;
+static SerialConsole sSerial;
 
 FILE* stdin;
 FILE* stdout;
@@ -37,7 +62,8 @@ FILE* stderr;
 
 
 Console::Console()
-       : ConsoleNode()
+       :
+       ConsoleNode()
 {
 }
 
@@ -45,8 +71,9 @@ Console::Console()
 ssize_t
 Console::ReadAt(void* cookie, off_t pos, void* buffer, size_t bufferSize)
 {
-#warning IMPLEMENT ReadAt
-       return 0;
+       // don't seek in character devices
+       // not implemented (and not yet? needed)
+       return B_ERROR;
 }
 
 
@@ -54,7 +81,6 @@ ssize_t
 Console::WriteAt(void* cookie, off_t /*pos*/, const void* buffer,
        size_t bufferSize)
 {
-#warning IMPLEMENT WriteAt
        return 0;
 }
 
@@ -62,70 +88,146 @@ Console::WriteAt(void* cookie, off_t /*pos*/, const void* 
buffer,
 //     #pragma mark -
 
 
+VTConsole::VTConsole()
+       :
+       ConsoleNode()
+{
+}
+
+
+void
+VTConsole::ClearScreen()
+{
+       WriteAt(NULL, 0LL, "\033E", 2);
+}
+
+
+void
+VTConsole::SetCursor(int32 x, int32 y)
+{
+       char buff[] = "\033Y  ";
+       x = MIN(79, MAX(0, x));
+       y = MIN(24, MAX(0, y));
+       buff[3] += (char)x;
+       buff[2] += (char)y;
+       WriteAt(NULL, 0LL, buff, 4);
+}
+
+
+void
+VTConsole::SetColor(int32 foreground, int32 background)
+{
+       static const char cmap[] = {
+               15, 4, 2, 6, 1, 5, 3, 7,
+               8, 12, 10, 14, 9, 13, 11, 0 };
+       char buff[] = "\033b \033c ";
+
+       if (foreground < 0 && foreground >= 16)
+               return;
+       if (background < 0 && background >= 16)
+               return;
+
+       buff[2] += cmap[foreground];
+       buff[5] += cmap[background];
+       WriteAt(NULL, 0LL, buff, 6);
+}
+
+
+//     #pragma mark -
+
+
+SerialConsole::SerialConsole()
+       : VTConsole()
+{
+}
+
+
+ssize_t
+SerialConsole::ReadAt(void *cookie, off_t pos, void *buffer, size_t bufferSize)
+{
+       // don't seek in character devices
+       // not implemented (and not yet? needed)
+       return B_ERROR;
+}
+
+
+ssize_t
+SerialConsole::WriteAt(void *cookie, off_t /*pos*/, const void *buffer,
+       size_t bufferSize)
+{
+       serial_puts((const char *)buffer, bufferSize);
+       return bufferSize;
+}
+
+
+//     #pragma mark -
+
+
 void
 console_clear_screen(void)
 {
-#warning IMPLEMENT console_clear_screen
+       sSerial.ClearScreen();
 }
 
 
 int32
 console_width(void)
 {
-#warning IMPLEMENT console_width
-       return 0;
+       return 80;
 }
 
 
 int32
 console_height(void)
 {
-#warning IMPLEMENT console_height
-       return 0;
+       return 25;
 }
 
 
 void
 console_set_cursor(int32 x, int32 y)
 {
-#warning IMPLEMENT console_set_cursor
+       sSerial.SetCursor(x, y);
 }
 
 
 void
-console_set_color(int32 foreground, int32 background)
+console_show_cursor(void)
 {
-#warning IMPLEMENT console_set_color
 }
 
 
-int
-console_wait_for_key(void)
+void
+console_hide_cursor(void)
 {
-#warning IMPLEMENT console_wait_for_key
-       union key key;
-       return key.code.ascii;
 }
 
 
-void
-console_show_cursor(void)
+int
+console_wait_for_key(void)
 {
-#warning IMPLEMENT console_show_cursor
+       #warning IMPLEMENT console_wait_for_key
+       #if 0
+       union key key;
+       return key.code.ascii;
+       #endif
+       return 0;
 }
 
 
 void
-console_hide_cursor(void)
+console_set_color(int32 foreground, int32 background)
 {
-#warning IMPLEMENT console_hide_cursor
+       sSerial.SetColor(foreground, background);
 }
 
 
 status_t
 console_init(void)
 {
-#warning IMPLEMENT console_init
+       stdin = (FILE *)&sSerial;
+       stdout = (FILE *)&sSerial;
+       stderr = (FILE *)&sSerial;
        return B_OK;
 }
 


Other related posts:

  • » [haiku-commits] haiku: hrev44164 - src/system/boot/platform/raspberrypi_arm - kallisti5