Browse Source
We are already using the libc from SLOF for the s390-netboot.img, and
this libc implementation is way more complete and accurate than the
simple implementation that we currently use for the s390-ccw.img binary.
Since we are now always assuming that the SLOF submodule is available
when building the s390-ccw bios (see commit bf6903f694), we can drop
the simple implementation and use the SLOF libc for the s390-ccw.img
binary, too.
Additionally replace sclp_print calls with puts/printf now that it is
available.
Co-authored by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Jared Rossi <jrossi@linux.ibm.com>
Message-ID: <20241020012953.1380075-3-jrossi@linux.ibm.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
pull/275/head
committed by
Thomas Huth
19 changed files with 140 additions and 336 deletions
@ -1,88 +0,0 @@ |
|||
/*
|
|||
* libc-style definitions and functions |
|||
* |
|||
* Copyright 2018 IBM Corp. |
|||
* Author(s): Collin L. Walling <walling@linux.vnet.ibm.com> |
|||
* |
|||
* This code is free software; you can redistribute it and/or modify it |
|||
* under the terms of the GNU General Public License as published by the |
|||
* Free Software Foundation; either version 2 of the License, or (at your |
|||
* option) any later version. |
|||
*/ |
|||
|
|||
#include "libc.h" |
|||
#include "s390-ccw.h" |
|||
|
|||
/**
|
|||
* atoui: |
|||
* @str: the string to be converted. |
|||
* |
|||
* Given a string @str, convert it to an integer. Leading spaces are |
|||
* ignored. Any other non-numerical value will terminate the conversion |
|||
* and return 0. This function only handles numbers between 0 and |
|||
* UINT64_MAX inclusive. |
|||
* |
|||
* Returns: an integer converted from the string @str, or the number 0 |
|||
* if an error occurred. |
|||
*/ |
|||
uint64_t atoui(const char *str) |
|||
{ |
|||
int val = 0; |
|||
|
|||
if (!str || !str[0]) { |
|||
return 0; |
|||
} |
|||
|
|||
while (*str == ' ') { |
|||
str++; |
|||
} |
|||
|
|||
while (*str) { |
|||
if (!isdigit(*(unsigned char *)str)) { |
|||
break; |
|||
} |
|||
val = val * 10 + *str - '0'; |
|||
str++; |
|||
} |
|||
|
|||
return val; |
|||
} |
|||
|
|||
/**
|
|||
* uitoa: |
|||
* @num: an integer (base 10) to be converted. |
|||
* @str: a pointer to a string to store the conversion. |
|||
* @len: the length of the passed string. |
|||
* |
|||
* Given an integer @num, convert it to a string. The string @str must be |
|||
* allocated beforehand. The resulting string will be null terminated and |
|||
* returned. This function only handles numbers between 0 and UINT64_MAX |
|||
* inclusive. |
|||
* |
|||
* Returns: the string @str of the converted integer @num |
|||
*/ |
|||
char *uitoa(uint64_t num, char *str, size_t len) |
|||
{ |
|||
long num_idx = 1; /* account for NUL */ |
|||
uint64_t tmp = num; |
|||
|
|||
IPL_assert(str != NULL, "uitoa: no space allocated to store string"); |
|||
|
|||
/* Count indices of num */ |
|||
while ((tmp /= 10) != 0) { |
|||
num_idx++; |
|||
} |
|||
|
|||
/* Check if we have enough space for num and NUL */ |
|||
IPL_assert(len > num_idx, "uitoa: array too small for conversion"); |
|||
|
|||
str[num_idx--] = '\0'; |
|||
|
|||
/* Convert int to string */ |
|||
while (num_idx >= 0) { |
|||
str[num_idx--] = num % 10 + '0'; |
|||
num /= 10; |
|||
} |
|||
|
|||
return str; |
|||
} |
|||
@ -1,89 +0,0 @@ |
|||
/*
|
|||
* libc-style definitions and functions |
|||
* |
|||
* Copyright (c) 2013 Alexander Graf <agraf@suse.de> |
|||
* |
|||
* This code is free software; you can redistribute it and/or modify it |
|||
* under the terms of the GNU General Public License as published by the |
|||
* Free Software Foundation; either version 2 of the License, or (at your |
|||
* option) any later version. |
|||
*/ |
|||
|
|||
#ifndef S390_CCW_LIBC_H |
|||
#define S390_CCW_LIBC_H |
|||
|
|||
typedef unsigned long size_t; |
|||
typedef int bool; |
|||
typedef unsigned char uint8_t; |
|||
typedef unsigned short uint16_t; |
|||
typedef unsigned int uint32_t; |
|||
typedef unsigned long long uint64_t; |
|||
|
|||
static inline void *memset(void *s, int c, size_t n) |
|||
{ |
|||
size_t i; |
|||
unsigned char *p = s; |
|||
|
|||
for (i = 0; i < n; i++) { |
|||
p[i] = c; |
|||
} |
|||
|
|||
return s; |
|||
} |
|||
|
|||
static inline void *memcpy(void *s1, const void *s2, size_t n) |
|||
{ |
|||
uint8_t *dest = s1; |
|||
const uint8_t *src = s2; |
|||
size_t i; |
|||
|
|||
for (i = 0; i < n; i++) { |
|||
dest[i] = src[i]; |
|||
} |
|||
|
|||
return s1; |
|||
} |
|||
|
|||
static inline int memcmp(const void *s1, const void *s2, size_t n) |
|||
{ |
|||
size_t i; |
|||
const uint8_t *p1 = s1, *p2 = s2; |
|||
|
|||
for (i = 0; i < n; i++) { |
|||
if (p1[i] != p2[i]) { |
|||
return p1[i] > p2[i] ? 1 : -1; |
|||
} |
|||
} |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
static inline size_t strlen(const char *str) |
|||
{ |
|||
size_t i; |
|||
for (i = 0; *str; i++) { |
|||
str++; |
|||
} |
|||
return i; |
|||
} |
|||
|
|||
static inline char *strcat(char *dest, const char *src) |
|||
{ |
|||
int i; |
|||
char *dest_end = dest + strlen(dest); |
|||
|
|||
for (i = 0; i <= strlen(src); i++) { |
|||
dest_end[i] = src[i]; |
|||
} |
|||
return dest; |
|||
} |
|||
|
|||
static inline int isdigit(int c) |
|||
{ |
|||
return (c >= '0') && (c <= '9'); |
|||
} |
|||
|
|||
uint64_t atoui(const char *str); |
|||
char *uitoa(uint64_t num, char *str, size_t len); |
|||
|
|||
#endif |
|||
Loading…
Reference in new issue