chore: clang format

This commit is contained in:
xinyangli 2024-07-22 17:45:49 +08:00
parent f5ea31f676
commit b317827c3c
Signed by: xin
SSH key fingerprint: SHA256:qZ/tzd8lYRtUFSrfBDBMcUqV4GHKxqeqRA3huItgvbk
16 changed files with 216 additions and 181 deletions

View file

@ -1,4 +1,4 @@
AbstractMachine is a minimal, modularized, and machine-independent
AbstractMachine is a minimal, modularized, and machine-independent
abstraction layer of the computer hardware:
* physical memory and direct execution (The "Turing Machine");
@ -9,5 +9,5 @@ abstraction layer of the computer hardware:
CONTACTS
Bug reports and suggestions go to Yanyan Jiang (jyy@nju.edu.cn) and Zihao
Bug reports and suggestions go to Yanyan Jiang (jyy@nju.edu.cn) and Zihao
Yu (yuzihao@ict.ac.cn).

View file

@ -1,5 +1,5 @@
#include <stdatomic.h>
#include "platform.h"
#include <stdatomic.h>
int __am_mpe_init = 0;
extern bool __am_has_ioe;
@ -16,7 +16,8 @@ bool mpe_init(void (*entry)()) {
char ch;
assert(read(sync_pipe[0], &ch, 1) == 1);
assert(ch == '+');
close(sync_pipe[0]); close(sync_pipe[1]);
close(sync_pipe[0]);
close(sync_pipe[1]);
thiscpu->cpuid = i;
__am_init_timer_irq();
@ -31,8 +32,9 @@ bool mpe_init(void (*entry)()) {
for (int i = 1; i < cpu_count(); i++) {
assert(write(sync_pipe[1], "+", 1) == 1);
}
close(sync_pipe[0]); close(sync_pipe[1]);
close(sync_pipe[0]);
close(sync_pipe[1]);
entry();
panic("MP entry should not return\n");
}
@ -42,9 +44,7 @@ int cpu_count() {
return __am_ncpu;
}
int cpu_current() {
return thiscpu->cpuid;
}
int cpu_current() { return thiscpu->cpuid; }
int atomic_xchg(int *addr, int newval) {
return atomic_exchange((int *)addr, newval);

View file

@ -55,25 +55,25 @@ __am_iret:
popl %edi
popl %ebp
iret
.kernel_iret:
popl %eax
popl %ebx
popl %ecx
popl %edx
addl $4, %esp
/* stack frame:
28 ss
24 esp (not popped by iret when returning to ring0)
20 eflags ---> move to new-esp
16 cs
12 eip
8 ebp
4 edi
8 ebp
4 edi
0 esi <--- %esp
*/
movl %esp, %ebp
movl 24(%ebp), %edi // %edi is new-esp

View file

@ -1,5 +1,5 @@
#include <klib.h>
#include <klib-macros.h>
#include <klib.h>
#include <stdint.h>
#if !defined(__ISA_NATIVE__) || defined(__NATIVE_USE_KLIB__)
@ -7,14 +7,15 @@
size_t strlen(const char *s) {
const char *p = s;
size_t len = 0;
while(*(p++) != '\0') len++;
while (*(p++) != '\0')
len++;
return len;
}
char *strcpy(char *dst, const char *src) {
char *p_dst = dst;
const char *p_src = src;
for(; *p_src != '\0'; p_src++, p_dst++) {
for (; *p_src != '\0'; p_src++, p_dst++) {
*p_dst = *p_src;
}
*p_dst = '\0';
@ -23,10 +24,10 @@ char *strcpy(char *dst, const char *src) {
char *strncpy(char *dst, const char *src, size_t n) {
int i = 0;
for(; i < n && src[i] != '\0'; i++) {
for (; i < n && src[i] != '\0'; i++) {
dst[i] = src[i];
}
for(; i < n; i++) {
for (; i < n; i++) {
dst[i] = '\0';
}
return dst;
@ -35,8 +36,9 @@ char *strncpy(char *dst, const char *src, size_t n) {
char *strcat(char *dst, const char *src) {
char *p_dst = dst;
const char *p_src = src;
while(*p_dst != '\0') p_dst++;
for(; *p_src != '\0'; p_src++, p_dst++) {
while (*p_dst != '\0')
p_dst++;
for (; *p_src != '\0'; p_src++, p_dst++) {
*p_dst = *p_src;
}
*p_dst = '\0';
@ -45,54 +47,56 @@ char *strcat(char *dst, const char *src) {
int strcmp(const char *s1, const char *s2) {
const char *p_s1 = s1, *p_s2 = s2;
for(; *p_s1 == *p_s2; p_s1++, p_s2++) {
if(*p_s1 == '\0' || *p_s2 == '\0') {
for (; *p_s1 == *p_s2; p_s1++, p_s2++) {
if (*p_s1 == '\0' || *p_s2 == '\0') {
break;
}
}
}
return *p_s1 - *p_s2;
}
int strncmp(const char *s1, const char *s2, size_t n) {
const char *p_s1 = s1, *p_s2 = s2;
int i = 0;
for(i = 0; i < n - 1; i++) {
if(s1[i] == '\0' || s2[i] == '\0')
for (i = 0; i < n - 1; i++) {
if (s1[i] == '\0' || s2[i] == '\0')
break;
}
}
return s1[i] - s2[i];
}
void *memset(void *s, int c, size_t n) {
uint8_t *p = s;
for(int i = 0; i < n; i++) {
for (int i = 0; i < n; i++) {
p[i] = c;
}
return s;
}
void *memmove(void *dst, const void *src, size_t n) {
if (src + n > dst && src < dst) {
if (src + n > dst && src < dst) {
size_t len = dst - src;
void *p_dst = (void *)src + n;
const void *p_src = src + n - len;
while(p_dst >= dst) {
while (p_dst >= dst) {
memcpy(p_dst, p_src, len);
p_src -= len;
p_dst -= len;
}
if(n % len) memcpy(dst, src, n % len);
if (n % len)
memcpy(dst, src, n % len);
} else if (dst < src && dst + n > src) {
size_t len = src - dst;
void *p_dst = dst;
const void *p_src = src;
while(p_src < src + n) {
while (p_src < src + n) {
memcpy(p_dst, p_src, len);
p_src += len;
p_dst += len;
}
if(n % len) memcpy(p_dst, p_src, n % len);
} else {
if (n % len)
memcpy(p_dst, p_src, n % len);
} else {
memcpy(dst, src, n);
}
@ -100,7 +104,7 @@ void *memmove(void *dst, const void *src, size_t n) {
}
void *memcpy(void *out, const void *in, size_t n) {
for (size_t i = 0 ; i < n ; i++) {
for (size_t i = 0; i < n; i++) {
*(uint8_t *)(out + i) = *(uint8_t *)(in + i);
}
return out;
@ -109,9 +113,10 @@ void *memcpy(void *out, const void *in, size_t n) {
int memcmp(const void *s1, const void *s2, size_t n) {
const uint8_t *p1 = s1, *p2 = s2;
for (int i = 0; i < n; i++) {
if(*p1 != *p2)
if (*p1 != *p2)
return p1 - p2;
p1++; p2++;
p1++;
p2++;
}
return 0;
}