summaryrefslogtreecommitdiff
path: root/src/libs/utils.h
blob: 140f1fd5b1d44f90c5cd49f6c7655325bfd86b6b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#ifndef __UTILS__
#define __UTILS__

#include "types.h"

// General operations
#define STR32(ADDR,VALUE) *((volatile unsigned int*) (ADDR))=(VALUE)
#define LDR32(ADDR) (*((volatile unsigned int*) (ADDR)))

// Registers operations
#define REG_WRITE(ADDR,VALUE) STR32(ADDR,VALUE)
#define REG_WRITE_XOR(ADDR,VALUE) STR32(ADDR+0x1000,VALUE)
#define REG_WRITE_BITMAP_SET(ADDR,VALUE) STR32(ADDR+0x2000,VALUE)
#define REG_WRITE_BITMAP_CLEAR(ADDR,VALUE) STR32(ADDR+0x3000,VALUE)
#define REG_READ(ADDR) LDR32(ADDR)

// Memory operations
void memcpy(u8 *dst, u8 *src, u32 size); // TODO: Improve perf with 32bits memory transactions
void memset(u8 *start, u8 value, u32 size); // TODO: Improve perf with 32bits memory transactions

// Computations
int modulo(int dividend, int divisor); // Assumes that both argument are positve (TODO improve this)

// Strings (not these functions do not follow libc standards and are buggy)
int strlen(char * cp);
int wordlen(char *s);
u8 strcmp(char *str1, char*str2);
u8 strncmp(char *str1, char*str2, int n);

#endif