Commit fc0e2087 authored by Collin L. Walling's avatar Collin L. Walling Committed by Thomas Huth
Browse files

s390-ccw: update libc



Moved:
  memcmp from bootmap.h to libc.h (renamed from _memcmp)
  strlen from sclp.c to libc.h (renamed from _strlen)

Added C standard functions:
  isdigit

Added non C-standard function:
  uitoa
  atoui

Signed-off-by: default avatarCollin L. Walling <walling@linux.vnet.ibm.com>
Acked-by: default avatarChristian Borntraeger <borntraeger@de.ibm.com>
Reviewed-by: default avatarJanosch Frank <frankja@linux.vnet.ibm.com>
Reviewed-by: default avatarThomas Huth <thuth@redhat.com>
Signed-off-by: default avatarThomas Huth <thuth@redhat.com>
parent ac4c5958
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -9,7 +9,7 @@ $(call set-vpath, $(SRC_PATH)/pc-bios/s390-ccw)

.PHONY : all clean build-all

OBJECTS = start.o main.o bootmap.o sclp.o virtio.o virtio-scsi.o virtio-blkdev.o
OBJECTS = start.o main.o bootmap.o sclp.o virtio.o virtio-scsi.o virtio-blkdev.o libc.o
QEMU_CFLAGS := $(filter -W%, $(QEMU_CFLAGS))
QEMU_CFLAGS += -ffreestanding -fno-delete-null-pointer-checks -msoft-float
QEMU_CFLAGS += -march=z900 -fPIE -fno-strict-aliasing
+2 −2
Original line number Diff line number Diff line
@@ -506,7 +506,7 @@ static bool is_iso_bc_entry_compatible(IsoBcSection *s)
                    "Failed to read image sector 0");

    /* Checking bytes 8 - 32 for S390 Linux magic */
    return !_memcmp(magic_sec + 8, linux_s390_magic, 24);
    return !memcmp(magic_sec + 8, linux_s390_magic, 24);
}

/* Location of the current sector of the directory */
@@ -635,7 +635,7 @@ static uint32_t find_iso_bc(void)
        if (vd->type == VOL_DESC_TYPE_BOOT) {
            IsoVdElTorito *et = &vd->vd.boot;

            if (!_memcmp(&et->el_torito[0], el_torito_magic, 32)) {
            if (!memcmp(&et->el_torito[0], el_torito_magic, 32)) {
                return bswap32(et->bc_offset);
            }
        }
+1 −15
Original line number Diff line number Diff line
@@ -328,20 +328,6 @@ static inline bool magic_match(const void *data, const void *magic)
    return *((uint32_t *)data) == *((uint32_t *)magic);
}

static inline int _memcmp(const void *s1, const void *s2, size_t n)
{
    int 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 uint32_t iso_733_to_u32(uint64_t x)
{
    return (uint32_t)x;
@@ -434,7 +420,7 @@ const uint8_t vol_desc_magic[] = "CD001";

static inline bool is_iso_vd_valid(IsoVolDesc *vd)
{
    return !_memcmp(&vd->ident[0], vol_desc_magic, 5) &&
    return !memcmp(&vd->ident[0], vol_desc_magic, 5) &&
           vd->version == 0x1 &&
           vd->type <= VOL_DESC_TYPE_PARTITION;
}
+88 −0
Original line number Diff line number Diff line
/*
 * 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(*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)
{
    size_t 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;
}
+35 −2
Original line number Diff line number Diff line
/*
 * 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
@@ -19,7 +21,7 @@ typedef unsigned long long uint64_t;

static inline void *memset(void *s, int c, size_t n)
{
    int i;
    size_t i;
    unsigned char *p = s;

    for (i = 0; i < n; i++) {
@@ -33,7 +35,7 @@ static inline void *memcpy(void *s1, const void *s2, size_t n)
{
    uint8_t *dest = s1;
    const uint8_t *src = s2;
    int i;
    size_t i;

    for (i = 0; i < n; i++) {
        dest[i] = src[i];
@@ -42,4 +44,35 @@ static inline void *memcpy(void *s1, const void *s2, size_t n)
    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 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