parent
42f31a0c17
commit
c524941890
@ -0,0 +1,2 @@
|
|||||||
|
build/
|
||||||
|
.DS_Store
|
@ -0,0 +1,14 @@
|
|||||||
|
// See LICENSE for license details.
|
||||||
|
|
||||||
|
#ifndef __LIBS_AARCH64_H__
|
||||||
|
#define __LIBS_AARCH64_H__
|
||||||
|
|
||||||
|
#define do_div(n, base) \
|
||||||
|
({ \
|
||||||
|
int __res; \
|
||||||
|
__res = ((unsigned long)n) % (unsigned)base; \
|
||||||
|
n = ((unsigned long)n) / (unsigned)base; \
|
||||||
|
__res; \
|
||||||
|
})
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,75 @@
|
|||||||
|
#ifndef __LIBS_ATOMIC_H__
|
||||||
|
#define __LIBS_ATOMIC_H__
|
||||||
|
|
||||||
|
// TODO: implement atomic operations for aarch64
|
||||||
|
|
||||||
|
/* Atomic operations that C can't guarantee us. Useful for resource counting etc.. */
|
||||||
|
|
||||||
|
static inline void set_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
||||||
|
static inline void clear_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
||||||
|
static inline void change_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
||||||
|
static inline bool test_and_set_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
||||||
|
static inline bool test_and_clear_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
||||||
|
static inline bool test_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
||||||
|
|
||||||
|
/* *
|
||||||
|
* set_bit - Atomically set a bit in memory
|
||||||
|
* @nr: the bit to set
|
||||||
|
* @addr: the address to start counting from
|
||||||
|
*
|
||||||
|
* Note that @nr may be almost arbitrarily large; this function is not
|
||||||
|
* restricted to acting on a single-word quantity.
|
||||||
|
* */
|
||||||
|
static inline void set_bit(int nr, volatile void *addr) {
|
||||||
|
/* unimplemented */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* *
|
||||||
|
* clear_bit - Atomically clears a bit in memory
|
||||||
|
* @nr: the bit to clear
|
||||||
|
* @addr: the address to start counting from
|
||||||
|
* */
|
||||||
|
static inline void clear_bit(int nr, volatile void *addr) {
|
||||||
|
/* unimplemented */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* *
|
||||||
|
* change_bit - Atomically toggle a bit in memory
|
||||||
|
* @nr: the bit to change
|
||||||
|
* @addr: the address to start counting from
|
||||||
|
* */
|
||||||
|
static inline void change_bit(int nr, volatile void *addr) {
|
||||||
|
/* unimplemented */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* *
|
||||||
|
* test_bit - Determine whether a bit is set
|
||||||
|
* @nr: the bit to test
|
||||||
|
* @addr: the address to count from
|
||||||
|
* */
|
||||||
|
static inline bool test_bit(int nr, volatile void *addr) {
|
||||||
|
/* unimplemented */
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* *
|
||||||
|
* test_and_set_bit - Atomically set a bit and return its old value
|
||||||
|
* @nr: the bit to set
|
||||||
|
* @addr: the address to count from
|
||||||
|
* */
|
||||||
|
static inline bool test_and_set_bit(int nr, volatile void *addr) {
|
||||||
|
/* unimplemented */
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* *
|
||||||
|
* test_and_clear_bit - Atomically clear a bit and return its old value
|
||||||
|
* @nr: the bit to clear
|
||||||
|
* @addr: the address to count from
|
||||||
|
* */
|
||||||
|
static inline bool test_and_clear_bit(int nr, volatile void *addr) {
|
||||||
|
/* unimplemented */
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* !__LIBS_ATOMIC_H__ */
|
@ -0,0 +1,79 @@
|
|||||||
|
#ifndef __LIBS_DEFS_H__
|
||||||
|
#define __LIBS_DEFS_H__
|
||||||
|
|
||||||
|
#ifndef NULL
|
||||||
|
#define NULL ((void *)0)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define __always_inline inline __attribute__((always_inline))
|
||||||
|
#define __noinline __attribute__((noinline))
|
||||||
|
#define __noreturn __attribute__((noreturn))
|
||||||
|
|
||||||
|
#define CHAR_BIT 8
|
||||||
|
|
||||||
|
/* Represents true-or-false values */
|
||||||
|
typedef long long bool;
|
||||||
|
|
||||||
|
/* Explicitly-sized versions of integer types */
|
||||||
|
typedef char int8_t;
|
||||||
|
typedef unsigned char uint8_t;
|
||||||
|
typedef short int16_t;
|
||||||
|
typedef unsigned short uint16_t;
|
||||||
|
typedef int int32_t;
|
||||||
|
typedef unsigned int uint32_t;
|
||||||
|
typedef long long int64_t;
|
||||||
|
typedef unsigned long long uint64_t;
|
||||||
|
|
||||||
|
/* *
|
||||||
|
* Pointers and addresses are 32 bits long.
|
||||||
|
* We use pointer types to represent addresses,
|
||||||
|
* uintptr_t to represent the numerical values of addresses.
|
||||||
|
* */
|
||||||
|
typedef int64_t intptr_t;
|
||||||
|
typedef uint64_t uintptr_t;
|
||||||
|
|
||||||
|
/* size_t is used for memory object sizes */
|
||||||
|
typedef uintptr_t size_t;
|
||||||
|
|
||||||
|
/* off_t is used for file offsets and lengths */
|
||||||
|
typedef intptr_t off_t;
|
||||||
|
|
||||||
|
/* used for page numbers */
|
||||||
|
typedef size_t ppn_t;
|
||||||
|
|
||||||
|
/* *
|
||||||
|
* Rounding operations (efficient when n is a power of 2)
|
||||||
|
* Round down to the nearest multiple of n
|
||||||
|
* */
|
||||||
|
#define ROUNDDOWN(a, n) ({ \
|
||||||
|
size_t __a = (size_t)(a); \
|
||||||
|
(typeof(a))(__a - __a % (n)); \
|
||||||
|
})
|
||||||
|
|
||||||
|
/* Round up to the nearest multiple of n */
|
||||||
|
#define ROUNDUP(a, n) ({ \
|
||||||
|
size_t __n = (size_t)(n); \
|
||||||
|
(typeof(a))(ROUNDDOWN((size_t)(a) + __n - 1, __n)); \
|
||||||
|
})
|
||||||
|
|
||||||
|
/* Round up the result of dividing of n */
|
||||||
|
#define ROUNDUP_DIV(a, n) ({ \
|
||||||
|
uint64_t __n = (uint64_t)(n); \
|
||||||
|
(typeof(a))(((a) + __n - 1) / __n); \
|
||||||
|
})
|
||||||
|
|
||||||
|
/* Return the offset of 'member' relative to the beginning of a struct type */
|
||||||
|
#define offsetof(type, member) \
|
||||||
|
((size_t)(&((type *)0)->member))
|
||||||
|
|
||||||
|
/* *
|
||||||
|
* to_struct - get the struct from a ptr
|
||||||
|
* @ptr: a struct pointer of member
|
||||||
|
* @type: the type of the struct this is embedded in
|
||||||
|
* @member: the name of the member within the struct
|
||||||
|
* */
|
||||||
|
#define to_struct(ptr, type, member) \
|
||||||
|
((type *)((char *)(ptr) - offsetof(type, member)))
|
||||||
|
|
||||||
|
#endif /* !__LIBS_DEFS_H__ */
|
||||||
|
|
@ -0,0 +1,8 @@
|
|||||||
|
.text
|
||||||
|
.globl _start
|
||||||
|
_start:
|
||||||
|
# call user-program function
|
||||||
|
ldr x0, [sp]
|
||||||
|
add x1, sp, #8
|
||||||
|
bl umain
|
||||||
|
1: b 1b
|
Loading…
Reference in new issue