Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/dtbsupport #24

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion device/uart/kvprintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ syscall kvprintf(const char *format, va_list ap)
* it prevents kprintf()'s from stepping on each other toes if you happen to
* call kprintf() from an interrupt handler. */
im = disable();
retval = _doprnt(format, ap, (int (*)(int, int))kputc, (int)&devtab[SERIAL0]);
retval = _doprnt(format, ap, (int (*)(int, uintptr_t))kputc, (uintptr_t)&devtab[SERIAL0]);
restore(im);
return retval;
}
26 changes: 26 additions & 0 deletions include/dtb.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* @file dhcpc.h
*
* Devicetree parser interface
*/
/* Embedded Xinu, Copyright (C) 2018. All rights reserved. */

#ifndef _DTB_H_
#define _DTB_H_


/* parse dtb tree:
Arguments: pointer to the in-memory flat device tree
pointer to callback that will handle parsed properties
pointer to callback that will handle reserved memory blocks
*/
int parse_dtb(void *dtbptr,
void (*prop_handler)(char *node_name,
char *property_name,
unsigned char *val,
uint32_t len),
void (*rsv_handler)(uint64_t address,
uint64_t size));
uint64_t dtb_read_uint64(uint32_t* dataptr);

#endif
22 changes: 22 additions & 0 deletions include/endianness.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,39 @@ bswap32(uint32_t n)
return (n << 24) | ((n & 0xff00) << 8) | ((n & 0xff0000) >> 8) | (n >> 24);
}

static inline uint64_t
bswap64(uint64_t n)
{
return((n & 0xff00000000000000) >> 56)
| ((n & 0x00ff000000000000) >> 40)
| ((n & 0x0000ff0000000000) >> 24)
| ((n & 0x000000ff00000000) >> 8)
| ((n & 0x00000000ff000000) << 8)
| ((n & 0x0000000000ff0000) << 24)
| ((n & 0x000000000000ff00) << 40)
| ((n & 0x00000000000000ff) << 56);
}


#if BYTE_ORDER == BIG_ENDIAN

/* Big-endian CPU */

/* big endian to big endian: no-op */
# define cpu_to_be16(n) n
# define cpu_to_be32(n) n
# define cpu_to_be64(n) n
# define be16_to_cpu(n) n
# define be32_to_cpu(n) n
# define be64_to_cpu(n) n

/* big endian to little endian and vice versa */
# define cpu_to_le16(n) bswap16(n)
# define cpu_to_le32(n) bswap32(n)
# define cpu_to_le64(n) bswap64(n)
# define le16_to_cpu(n) bswap16(n)
# define le32_to_cpu(n) bswap32(n)
# define le64_to_cpu(n) bswap64(n)

#else /* BYTE_ORDER == BIG_ENDIAN */

Expand All @@ -46,14 +64,18 @@ bswap32(uint32_t n)
/* little endian to big endian and vice versa */
# define cpu_to_be16(n) bswap16(n)
# define cpu_to_be32(n) bswap32(n)
# define cpu_to_be64(n) bswap64(n)
# define be16_to_cpu(n) bswap16(n)
# define be32_to_cpu(n) bswap32(n)
# define be64_to_cpu(n) bswap64(n)

/* little endian to little endian: no-op */
# define cpu_to_le16(n) n
# define cpu_to_le32(n) n
# define cpu_to_le64(n) n
# define le16_to_cpu(n) n
# define le32_to_cpu(n) n
# define le64_to_cpu(n) n

#endif /* BYTE_ORDER != BIG_ENDIAN */

Expand Down
4 changes: 4 additions & 0 deletions include/limits.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@
#define INT_MIN (-INT_MAX-1) /**< minimum value of int */
#define UINT_MAX (2U*INT_MAX+1) /**< maximum value of unsigned int */

#ifdef __LP64__ /* 64 bit arch */
#define LONG_MAX 9223372036854775807L /**< maximum value of long */
#else /* 32 bit arch */
#define LONG_MAX 2147483647 /**< maximum value of long */
#endif
#define LONG_MIN (-LONG_MAX-1) /**< minimum value of long */
#define ULONG_MAX (2UL*LONG_MAX+1) /**< maximum value of unsigned long */

Expand Down
14 changes: 8 additions & 6 deletions include/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
#define _MEMORY_H_

#include <stddef.h>
#include <stdint.h>

#define MEMORY_DMBDEC (2*sizeof(uintptr_t)-1)
/* roundmb - round address up to size of memblock */
#define roundmb(x) (void *)( (7 + (ulong)(x)) & ~0x07 )
#define roundmb(x) (void *)( (MEMORY_DMBDEC + (ulong)(x)) & ~MEMORY_DMBDEC )
/* truncmb - truncate address down to size of memblock */
#define truncmb(x) (void *)( ((ulong)(x)) & ~0x07 )
#define truncmb(x) (void *)( ((ulong)(x)) & ~MEMORY_DMBDEC )

/**
* @ingroup memory_mgmt
Expand All @@ -38,7 +40,7 @@
struct memblock
{
struct memblock *next; /**< pointer to next memory block */
uint length; /**< size of memory block (with struct) */
uintptr_t length; /**< size of memory block (with struct) */
};

extern struct memblock memlist; /**< head of free memory list */
Expand All @@ -50,8 +52,8 @@ extern void *_etext; /**< linker provides end of text segment */
extern void *memheap; /**< bottom of heap */

/* Memory function prototypes */
void *memget(uint);
syscall memfree(void *, uint);
void *stkget(uint);
void *memget(uintptr_t);
syscall memfree(void *, uintptr_t);
void *stkget(uintptr_t);

#endif /* _MEMORY_H_ */
8 changes: 8 additions & 0 deletions include/stdint.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,12 @@ typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long long uint64_t;

#if __LP64__
typedef long int intptr_t;
typedef unsigned long int uintptr_t;
#else
typedef int intptr_t;
typedef unsigned int uintptr_t;
#endif

#endif /* _STDINT_H_ */
7 changes: 4 additions & 3 deletions include/stdio.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#ifndef _STDIO_H_
#define _STDIO_H_

#include <stdint.h>
#include <compiler.h>
#include <stdarg.h>
#include <thread.h> /* For thrtab and thrcurrent. */
Expand All @@ -31,8 +32,8 @@

/* Formatted input */
int _doscan(const char *fmt, va_list ap,
int (*getch) (int, int), int (*ungetch) (int, int),
int arg1, int arg2);
int (*getch) (int, uintptr_t), int (*ungetch) (int, uintptr_t),
int arg1, uintptr_t arg2);

int fscanf(int dev, const char *format, ...);

Expand All @@ -45,7 +46,7 @@ int sscanf(const char *str, const char *format, ...);

/* Formatted output */
int _doprnt(const char *format, va_list,
int (*putc_func)(int, int), int putc_arg);
int (*putc_func)(int, uintptr_t), uintptr_t putc_arg);

int fprintf(int dev, const char *format, ...) __printf_format(2, 3);
int printf(const char *format, ...) __printf_format(1, 2);
Expand Down
2 changes: 1 addition & 1 deletion lib/libxc/doprnt.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ enum integer_size {
* number of characters written on success, or @c EOF on failure
*/
int _doprnt(const char *fmt, va_list ap,
int (*putc_func) (int, int), int putc_arg)
int (*putc_func) (int, uintptr_t), uintptr_t putc_arg)
{
int chars_written = 0; /* Number of characters written so far */

Expand Down
24 changes: 12 additions & 12 deletions lib/libxc/doscan.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ enum integer_size {

static int scan_string(char *ptr, int type, uint maxlen,
const uchar *stopchar_tab,
int (*getch) (int, int), int (*ungetch) (int, int),
int arg1, int arg2, bool *eofptr);
int (*getch) (int, uintptr_t), int (*ungetch) (int, uintptr_t),
int arg1, uintptr_t arg2, bool *eofptr);

static int scan_number_or_string(void *ptr, uchar type, uint maxlen,
enum integer_size size,
const uchar *stopchar_tab,
int (*getch) (int, int),
int (*ungetch) (int, int),
int arg1, int arg2, bool *eofptr);
int (*getch) (int, uintptr_t),
int (*ungetch) (int, uintptr_t),
int arg1, uintptr_t arg2, bool *eofptr);

static const uchar *build_stopchar_tab(const uchar *ufmt, uchar *stopchar_tab);

Expand Down Expand Up @@ -81,8 +81,8 @@ static const uchar *build_stopchar_tab(const uchar *ufmt, uchar *stopchar_tab);
* returned.
*/
int _doscan(const char *fmt, va_list ap,
int (*getch) (int, int), int (*ungetch) (int, int),
int arg1, int arg2)
int (*getch) (int, uintptr_t), int (*ungetch) (int, uintptr_t),
int arg1, uintptr_t arg2)
{
int nmatch;
uint maxlen;
Expand Down Expand Up @@ -235,8 +235,8 @@ int _doscan(const char *fmt, va_list ap,
}

static int scan_string(char *ptr, int type, uint maxlen, const uchar *stopchar_tab,
int (*getch) (int, int), int (*ungetch) (int, int),
int arg1, int arg2, bool *eofptr)
int (*getch) (int, uintptr_t), int (*ungetch) (int, uintptr_t),
int arg1, uintptr_t arg2, bool *eofptr)
{
uint len;
int c;
Expand Down Expand Up @@ -290,9 +290,9 @@ static int scan_string(char *ptr, int type, uint maxlen, const uchar *stopchar_t
static int scan_number_or_string(void *ptr, uchar type, uint maxlen,
enum integer_size size,
const uchar *stopchar_tab,
int (*getch) (int, int),
int (*ungetch) (int, int),
int arg1, int arg2, bool *eofptr)
int (*getch) (int, uintptr_t),
int (*ungetch) (int,uintptr_t),
int arg1, uintptr_t arg2, bool *eofptr)
{
int c = EOF;
ulong n;
Expand Down
2 changes: 1 addition & 1 deletion lib/libxc/fprintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ int fprintf(int dev, const char *format, ...)
int ret;

va_start(ap, format);
ret = _doprnt(format, ap, fputc, dev);
ret = _doprnt(format, ap, (int (*)(int, uintptr_t)) fputc, (uintptr_t) dev);
va_end(ap);
return ret;
}
10 changes: 5 additions & 5 deletions lib/libxc/fscanf.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#include <stdarg.h>
#include <stdio.h>

static int getch(int, int);
static int ungetch(int, int);
static int getch(int, uintptr_t);
static int ungetch(int, uintptr_t);

struct ch_buf
{
Expand Down Expand Up @@ -44,14 +44,14 @@ int fscanf(int dev, const char *format, ...)

buf.ch_avail = FALSE;
va_start(ap, format);
ret = _doscan(format, ap, getch, ungetch, dev, (int)&buf);
ret = _doscan(format, ap, getch, ungetch, dev, (uintptr_t)&buf);
va_end(ap);
return ret;
}

/* Get a character from the device, storing it in the character buffer in case
* an unget is requested. */
static int getch(int dev, int _ch_buf)
static int getch(int dev, uintptr_t _ch_buf)
{
struct ch_buf *buf = (struct ch_buf *)_ch_buf;
int c;
Expand All @@ -72,7 +72,7 @@ static int getch(int dev, int _ch_buf)
}

/* Put back a character. */
static int ungetch(int dev, int _chbuf)
static int ungetch(int dev, uintptr_t _chbuf)
{
struct ch_buf *buf = (struct ch_buf *)_chbuf;

Expand Down
2 changes: 1 addition & 1 deletion lib/libxc/malloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void *malloc(size_t size)

/* acquire memory from kernel */
pmem = (struct memblock *)memget(size);
if (SYSERR == (uint)pmem)
if (SYSERR == (intptr_t)pmem)
{
return NULL;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/libxc/printf.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ int printf(const char *format, ...)
int ret;

va_start(ap, format);
ret = _doprnt(format, ap, fputc, stdout);
ret = _doprnt(format, ap, (int (*)(int, uintptr_t)) fputc, (uintptr_t)stdout);
va_end(ap);

return ret;
Expand Down
6 changes: 3 additions & 3 deletions lib/libxc/sprintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <stdarg.h>
#include <stdio.h>

static int sprntf(int, int);
static int sprntf(int, uintptr_t);

/**
* @ingroup libxc
Expand All @@ -33,7 +33,7 @@ int sprintf(char *str, const char *format, ...)

s = str;
va_start(ap, format);
_doprnt(format, ap, sprntf, (int)&s);
_doprnt(format, ap, sprntf, (uintptr_t) &s);
va_end(ap);
*s = '\0';

Expand All @@ -43,7 +43,7 @@ int sprintf(char *str, const char *format, ...)
/*
* Routine called by _doprnt() to output each character.
*/
static int sprntf(int c, int _sptr)
static int sprntf(int c, uintptr_t _sptr)
{
char **sptr = (char **)_sptr;
char *s = *sptr;
Expand Down
10 changes: 5 additions & 5 deletions lib/libxc/sscanf.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#include <stddef.h>
#include <stdio.h>

static int sgetch(int, int);
static int sungetch(int, int);
static int sgetch(int, uintptr_t);
static int sungetch(int, uintptr_t);

/**
* @ingroup libxc
Expand All @@ -36,7 +36,7 @@ int sscanf(const char *str, const char *format, ...)
int ret;

va_start(ap, format);
ret = _doscan(format, ap, sgetch, sungetch, 0, (int)&str);
ret = _doscan(format, ap, sgetch, sungetch, 0, (uintptr_t) &str);
va_end(ap);

return ret;
Expand All @@ -45,7 +45,7 @@ int sscanf(const char *str, const char *format, ...)
/* The first argument to the below functions is ignored, as we only need one
* argument to specify the current position in the string. */

static int sgetch(int _ignored, int _str_p)
static int sgetch(int _ignored, uintptr_t _str_p)
{
const char **str_p = (const char **)_str_p;
const char *str = *str_p;
Expand All @@ -63,7 +63,7 @@ static int sgetch(int _ignored, int _str_p)
return c;
}

static int sungetch(int _ignored, int _str_p)
static int sungetch(int _ignored, uintptr_t _str_p)
{
const char **str_p = (const char**)_str_p;
const char *str = *str_p;
Expand Down
2 changes: 1 addition & 1 deletion mailbox/mailboxAlloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ syscall mailboxAlloc(uint count)
mbxptr->msgs = memget(sizeof(int) * count);

/* check if memory was allocated correctly */
if (SYSERR == (int)mbxptr->msgs)
if (SYSERR == (intptr_t)mbxptr->msgs)
{
break;
}
Expand Down
Loading