mirror of
https://github.com/AmbiML/sparrow-kata-full.git
synced 2025-09-05 07:20:02 +00:00
Merge "apps: Extract crt0 from C apps"
GitOrigin-RevId: af8b6e41c39a9d5d0b85cb5f7b66d986e1bc3cf9
This commit is contained in:
committed by
Sam Leffler
parent
13799ab779
commit
6ee08d8b47
53
apps/c/libkata/printf.c
Normal file
53
apps/c/libkata/printf.c
Normal file
@@ -0,0 +1,53 @@
|
||||
// Copyright 2022 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <kata.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef CONFIG_PRINTING
|
||||
// only prints 32-bit "%x" hex values
|
||||
void _debug_printf(const char *fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
for (; *fmt; fmt++) {
|
||||
if (*fmt == '%') {
|
||||
fmt++;
|
||||
if (*fmt == 'd') {
|
||||
uint32_t arg = va_arg(args, uint32_t);
|
||||
// TODO(sleffler): total hack
|
||||
int printing = 0;
|
||||
for (int d = 1000000000; d > 1; d /= 10) {
|
||||
int n = (arg / d) % 10;
|
||||
if (printing || n > 0) {
|
||||
seL4_DebugPutChar('0' + n);
|
||||
printing = 1;
|
||||
}
|
||||
}
|
||||
seL4_DebugPutChar('0' + (arg % 10));
|
||||
} else if (*fmt == 'x') {
|
||||
uint32_t arg = va_arg(args, uint32_t);
|
||||
for (int i = 7; i >= 0; i--) {
|
||||
int n = (arg >> (4 * i)) & 0xF;
|
||||
seL4_DebugPutChar(n > 9 ? 'A' + n - 10 : '0' + n);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
seL4_DebugPutChar(*fmt);
|
||||
}
|
||||
}
|
||||
va_end(args);
|
||||
}
|
||||
#endif // CONFIG_PRINTING
|
Reference in New Issue
Block a user