Separate debug console code from normal console code, see details:

- consoleDebugInit now lives in a separate source code file
- The devoptab for debugDevice_CONSOLE is now loaded weakly, so that
  normal console code isn't linked in by explicit means
- consoleInit no longer sets up stderr. If stderr to console is desired,
  explicitly use consoleDebugInit(debugDevice_CONSOLE)
- This change makes it possible to use debugDevice_SVC without linking
  in the entire console runtime, which in turn also enabled default
  native window handling (and this can be undesirable)
This commit is contained in:
fincs 2020-04-15 18:32:16 +02:00
parent 763b1694ec
commit 4c9b2ac048
No known key found for this signature in database
GPG Key ID: 62C7609ADA219C60
2 changed files with 56 additions and 68 deletions

View File

@ -2,7 +2,6 @@
#include <string.h>
#include <sys/iosupport.h>
#include "runtime/devices/console.h"
#include "kernel/svc.h"
#include "default_font_bin.h"
@ -450,62 +449,26 @@ static ssize_t con_write(struct _reent *r,void *fd,const char *ptr, size_t len)
}
static const devoptab_t dotab_stdout = {
"con",
0,
NULL,
NULL,
con_write,
NULL,
NULL,
NULL
.name = "con",
.write_r = con_write,
};
//---------------------------------------------------------------------------------
static ssize_t debug_write(struct _reent *r, void *fd, const char *ptr, size_t len) {
//---------------------------------------------------------------------------------
svcOutputDebugString(ptr,len);
return len;
const devoptab_t* __nx_get_console_dotab(void) {
return &dotab_stdout;
}
static const devoptab_t dotab_svc = {
"svc",
0,
NULL,
NULL,
debug_write,
NULL,
NULL,
NULL
};
static const devoptab_t dotab_null = {
"null",
0,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL
};
ConsoleRenderer* getDefaultConsoleRenderer(void);
//---------------------------------------------------------------------------------
PrintConsole* consoleInit(PrintConsole* console) {
//---------------------------------------------------------------------------------
static bool firstConsoleInit = true;
static bool didFirstConsoleInit = false;
if(firstConsoleInit) {
if(!didFirstConsoleInit) {
devoptab_list[STD_OUT] = &dotab_stdout;
devoptab_list[STD_ERR] = &dotab_stdout;
setvbuf(stdout, NULL , _IONBF, 0);
setvbuf(stderr, NULL , _IONBF, 0);
firstConsoleInit = false;
setvbuf(stdout, NULL, _IONBF, 0);
didFirstConsoleInit = true;
}
if(console) {
@ -551,29 +514,6 @@ void consoleUpdate(PrintConsole* console) {
}
}
//---------------------------------------------------------------------------------
void consoleDebugInit(debugDevice device) {
//---------------------------------------------------------------------------------
int buffertype = _IONBF;
switch(device) {
case debugDevice_SVC:
devoptab_list[STD_ERR] = &dotab_svc;
buffertype = _IOLBF;
break;
case debugDevice_CONSOLE:
devoptab_list[STD_ERR] = &dotab_stdout;
break;
case debugDevice_NULL:
devoptab_list[STD_ERR] = &dotab_null;
break;
}
setvbuf(stderr, NULL , buffertype, 0);
}
//---------------------------------------------------------------------------------
PrintConsole *consoleSelect(PrintConsole* console) {
//---------------------------------------------------------------------------------

View File

@ -0,0 +1,48 @@
#include <stdio.h>
#include <string.h>
#include <sys/iosupport.h>
#include "runtime/devices/console.h"
#include "kernel/svc.h"
//---------------------------------------------------------------------------------
static ssize_t debug_write(struct _reent *r, void *fd, const char *ptr, size_t len) {
//---------------------------------------------------------------------------------
svcOutputDebugString(ptr,len);
return len;
}
static const devoptab_t dotab_svc = {
.name = "svc",
.write_r = debug_write,
};
static const devoptab_t dotab_null = {
.name = "null",
};
__attribute__((weak)) const devoptab_t* __nx_get_console_dotab(void) {
return &dotab_null;
}
//---------------------------------------------------------------------------------
void consoleDebugInit(debugDevice device) {
//---------------------------------------------------------------------------------
int buffertype = _IONBF;
switch(device) {
case debugDevice_SVC:
devoptab_list[STD_ERR] = &dotab_svc;
buffertype = _IOLBF;
break;
case debugDevice_CONSOLE:
devoptab_list[STD_ERR] = __nx_get_console_dotab();
break;
case debugDevice_NULL:
devoptab_list[STD_ERR] = &dotab_null;
break;
}
setvbuf(stderr, NULL, buffertype, 0);
}