From bcd3e2853f8bba00a31819fa36b1392f956bf774 Mon Sep 17 00:00:00 2001 From: Yanyan Jiang Date: Sun, 2 Feb 2020 07:00:03 +0000 Subject: [PATCH] format refactors --- am/am.h | 2 +- am/amdev.h | 2 +- am/src/mips32/nemu/cte.c | 2 +- am/src/native/devices/input.c | 2 +- am/src/native/vme.c | 2 +- am/src/navy/dev/input.c | 2 +- am/src/x86/qemu/boot/main.c | 4 +- am/src/x86/qemu/cte.c | 8 +- am/src/x86/qemu/ioe.c | 8 +- am/src/x86/qemu/trm.c | 1 - am/src/x86/qemu/x86-qemu.h | 1 - libs/klib/include/klib.h | 198 +++++++++++++++++----------------- 12 files changed, 115 insertions(+), 117 deletions(-) diff --git a/am/am.h b/am/am.h index 4c80913e..bbff2f62 100644 --- a/am/am.h +++ b/am/am.h @@ -36,7 +36,7 @@ enum { // Memory area for [@start, @end) typedef struct _Area { void *start, *end; -} _Area; +} _Area; // An event of type @event, caused by @cause of pointer @ref typedef struct _Event { diff --git a/am/amdev.h b/am/amdev.h index f07e7f97..2a79b71b 100644 --- a/am/amdev.h +++ b/am/amdev.h @@ -9,7 +9,7 @@ extern "C" { // =========================== AM Devices ============================ -#define _DEV_PERFCNT 0x0000ac01 // AM Virtual Performance Counter +#define _DEV_PERFCNT 0x0000ac01 // AM Virtual Performance Counter #define _DEV_INPUT 0x0000ac02 // AM Virtual Input Device #define _DEV_TIMER 0x0000ac03 // AM Virtual Timer #define _DEV_VIDEO 0x0000ac04 // AM Virtual Video Controller diff --git a/am/src/mips32/nemu/cte.c b/am/src/mips32/nemu/cte.c index 6bd762cc..4757acb3 100644 --- a/am/src/mips32/nemu/cte.c +++ b/am/src/mips32/nemu/cte.c @@ -20,7 +20,7 @@ _Context* __am_irq_handle(_Context *c) { case 0: ev.event = _EVENT_IRQ_TIMER; break; case 2: case 3: __am_tlb_refill(); return next; - case 8: + case 8: syscall_instr = *(uint32_t *)(c->epc); ev.event = ((syscall_instr >> 6) == 1) ? _EVENT_YIELD : _EVENT_SYSCALL; c->epc += 4; diff --git a/am/src/native/devices/input.c b/am/src/native/devices/input.c index dcdc1135..fa82aa99 100644 --- a/am/src/native/devices/input.c +++ b/am/src/native/devices/input.c @@ -20,7 +20,7 @@ static int event_thread(void *args) { SDL_WaitEvent(&event); switch (event.type) { case SDL_QUIT: _exit(0); break; - case SDL_KEYDOWN: + case SDL_KEYDOWN: case SDL_KEYUP: { SDL_Keysym k = event.key.keysym; diff --git a/am/src/native/vme.c b/am/src/native/vme.c index 0782fca2..9fc2941e 100644 --- a/am/src/native/vme.c +++ b/am/src/native/vme.c @@ -97,7 +97,7 @@ int _map(_AddressSpace *as, void *va, void *pa, int prot) { else { pp->is_mapped = false; } - + return 0; } diff --git a/am/src/navy/dev/input.c b/am/src/navy/dev/input.c index 6628edf3..85092a7a 100644 --- a/am/src/navy/dev/input.c +++ b/am/src/navy/dev/input.c @@ -22,7 +22,7 @@ int __am_event_thread(void) { if (event.type == NDL_EVENT_TIMER) { __am_set_systime(event.data); } - + if (event.type == NDL_EVENT_KEYUP || event.type == NDL_EVENT_KEYDOWN) { int keydown = event.type == NDL_EVENT_KEYDOWN; int scancode = event.data; diff --git a/am/src/x86/qemu/boot/main.c b/am/src/x86/qemu/boot/main.c index 638c4115..3e0aa6f9 100644 --- a/am/src/x86/qemu/boot/main.c +++ b/am/src/x86/qemu/boot/main.c @@ -67,12 +67,12 @@ void load_kernel(void) { struct elf32_hdr *elf32 = (void *)0x8000; struct elf64_hdr *elf64 = (void *)0x8000; int is_ap = boot_record()->is_ap; - + if (!is_ap) { // load argument (string) to memory copy_from_disk((void *)MAINARG_ADDR, 1024, -1024); // load elf header to memory - copy_from_disk(elf32, 4096, 0); + copy_from_disk(elf32, 4096, 0); if (elf32->e_machine == EM_X86_64) { load_elf64(elf64); } else { diff --git a/am/src/x86/qemu/cte.c b/am/src/x86/qemu/cte.c index 790760bf..3d6d8b71 100644 --- a/am/src/x86/qemu/cte.c +++ b/am/src/x86/qemu/cte.c @@ -23,7 +23,7 @@ static void __am_irq_handle_internal(struct trap_frame *tf) { .cause = 0, .ref = 0, .msg = "(no message)", }; - + #if __x86_64 saved_ctx = tf->saved_context; saved_ctx.rip = tf->rip; @@ -46,7 +46,7 @@ static void __am_irq_handle_internal(struct trap_frame *tf) { } #endif - #define IRQ T_IRQ0 + + #define IRQ T_IRQ0 + #define MSG(m) ev.msg = m; if (IRQ 0 <= tf->irq && tf->irq < IRQ 32) { @@ -157,7 +157,7 @@ _Context *_kcontext(_Area stack, void (*entry)(void *), void *arg) { ctx->rip = (uintptr_t)entry; ctx->rflags = FL_IF; ctx->rdi = (uintptr_t)arg; - void *stk[] = { panic_on_return }; + void *stk[] = { panic_on_return }; #else #define sp esp ctx->esp = (uintptr_t)stack.end; @@ -165,7 +165,7 @@ _Context *_kcontext(_Area stack, void (*entry)(void *), void *arg) { ctx->cs = KSEL(SEG_KCODE); ctx->eip = (uint32_t)entry; ctx->eflags = FL_IF; - void *stk[] = { panic_on_return, arg }; + void *stk[] = { panic_on_return, arg }; #endif ctx->sp -= sizeof(stk); for (int i = 0; i < LENGTH(stk); i++) { diff --git a/am/src/x86/qemu/ioe.c b/am/src/x86/qemu/ioe.c index 3e3dfa7e..f3e4472e 100644 --- a/am/src/x86/qemu/ioe.c +++ b/am/src/x86/qemu/ioe.c @@ -21,7 +21,7 @@ static int scan_code[] = { 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 43, 58, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 28, 42, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, - 29, 91, 56, 57, 56, 29, + 29, 91, 56, 57, 56, 29, 72, 80, 75, 77 }; @@ -328,7 +328,7 @@ void __am_percpu_initlapic(void) { lapicw(SVR, ENABLE | (T_IRQ0 + IRQ_SPURIOUS)); lapicw(TDCR, X1); lapicw(TIMER, PERIODIC | (T_IRQ0 + IRQ_TIMER)); - lapicw(TICR, 10000000); + lapicw(TICR, 10000000); lapicw(LINT0, MASKED); lapicw(LINT1, MASKED); if (((__am_lapic[VER]>>16) & 0xFF) >= 4) @@ -360,8 +360,8 @@ void __am_lapic_bootap(uint32_t apicid, void *addr) { lapicw(ICRHI, apicid<<24); lapicw(ICRLO, INIT | LEVEL | ASSERT); lapicw(ICRLO, INIT | LEVEL); - - for (i = 0; i < 2; i++){ + + for (i = 0; i < 2; i++){ lapicw(ICRHI, apicid<<24); lapicw(ICRLO, STARTUP | ((uintptr_t)addr>>12)); } diff --git a/am/src/x86/qemu/trm.c b/am/src/x86/qemu/trm.c index 01217aaa..dc803bb4 100644 --- a/am/src/x86/qemu/trm.c +++ b/am/src/x86/qemu/trm.c @@ -58,7 +58,6 @@ void _halt(int code) { } outw(0x604, 0x2000); // offer of qemu :) while (1) hlt(); - } _Area __am_heap_init() { diff --git a/am/src/x86/qemu/x86-qemu.h b/am/src/x86/qemu/x86-qemu.h index 0dd82de9..830ca7de 100644 --- a/am/src/x86/qemu/x86-qemu.h +++ b/am/src/x86/qemu/x86-qemu.h @@ -15,7 +15,6 @@ #ifndef __ASSEMBLER__ #include -#include #define ROUNDUP(a, sz) ((((uintptr_t)a)+(sz)-1) & ~((sz)-1)) #define ROUNDDOWN(a, sz) ((((uintptr_t)a)) & ~((sz)-1)) diff --git a/libs/klib/include/klib.h b/libs/klib/include/klib.h index e9afcd38..f703221e 100644 --- a/libs/klib/include/klib.h +++ b/libs/klib/include/klib.h @@ -1,99 +1,99 @@ -/* - * Static runtime library for a system software on AbstractMachine - */ - -#ifndef __KLIB_H__ -#define __KLIB_H__ - -#include -#include - -//#define __NATIVE_USE_KLIB__ - -#ifdef __NATIVE_USE_KLIB__ -#define strlen my_strlen -#define strcpy my_strcpy -#define strncpy my_strncpy -#define strcat my_strcat -#define strcmp my_strcmp -#define strncmp my_strncmp -#define memset my_memset -#define memcpy my_memcpy -#define memcmp my_memcmp -#define printf my_printf -#define vsprintf my_vsprintf -#define sprintf my_sprintf -#define snprintf my_snprintf -#define malloc my_malloc -#define free my_free -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -// am devices - -uint32_t uptime(); -void get_timeofday(void *rtc); -int read_key(); -void draw_rect(uint32_t *pixels, int x, int y, int w, int h); -void draw_sync(); -int screen_width(); -int screen_height(); - -// string.h -void* memset(void* v, int c, size_t n); -void* memcpy(void* dst, const void* src, size_t n); -void* memmove(void* dst, const void* src, size_t n); -int memcmp(const void* s1, const void* s2, size_t n); -size_t strlen(const char* s); -char* strcat(char* dst, const char* src); -char* strcpy(char* dst, const char* src); -char* strncpy(char* dst, const char* src, size_t n); -int strcmp(const char* s1, const char* s2); -int strncmp(const char* s1, const char* s2, size_t n); -char* strtok(char* s,const char* delim); -char *strstr(const char *, const char *); -char *strchr(const char *s, int c); -char *strrchr(const char *s, int c); - -// stdlib.h -int atoi(const char* nptr); -int abs(int x); -unsigned long time(); -void srand(unsigned int seed); -int rand(); -void *malloc(size_t size); -void free(void *ptr); - -// stdio.h -int printf(const char* fmt, ...); -int sprintf(char* out, const char* format, ...); -int snprintf(char* s, size_t n, const char* format, ...); -int vsprintf(char *str, const char *format, va_list ap); -int vsnprintf(char *str, size_t size, const char *format, va_list ap); -int sscanf(const char *str, const char *format, ...); - -void qsort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *)); - -#define printk printf - -// assert.h -#ifdef NDEBUG - #define assert(ignore) ((void)0) -#else - #define assert(cond) \ - do { \ - if (!(cond)) { \ - printk("Assertion fail at %s:%d\n", __FILE__, __LINE__); \ - _halt(1); \ - } \ - } while (0) -#endif - -#ifdef __cplusplus -} -#endif - -#endif +/* + * Static runtime library for a system software on AbstractMachine + */ + +#ifndef __KLIB_H__ +#define __KLIB_H__ + +#include +#include + +//#define __NATIVE_USE_KLIB__ + +#ifdef __NATIVE_USE_KLIB__ +#define strlen my_strlen +#define strcpy my_strcpy +#define strncpy my_strncpy +#define strcat my_strcat +#define strcmp my_strcmp +#define strncmp my_strncmp +#define memset my_memset +#define memcpy my_memcpy +#define memcmp my_memcmp +#define printf my_printf +#define vsprintf my_vsprintf +#define sprintf my_sprintf +#define snprintf my_snprintf +#define malloc my_malloc +#define free my_free +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +// am devices + +uint32_t uptime(); +void get_timeofday(void *rtc); +int read_key(); +void draw_rect(uint32_t *pixels, int x, int y, int w, int h); +void draw_sync(); +int screen_width(); +int screen_height(); + +// string.h +void *memset(void* v, int c, size_t n); +void *memcpy(void* dst, const void* src, size_t n); +void *memmove(void* dst, const void* src, size_t n); +int memcmp(const void* s1, const void* s2, size_t n); +size_t strlen(const char* s); +char *strcat(char* dst, const char* src); +char *strcpy(char* dst, const char* src); +char *strncpy(char* dst, const char* src, size_t n); +int strcmp(const char* s1, const char* s2); +int strncmp(const char* s1, const char* s2, size_t n); +char *strtok(char* s,const char* delim); +char *strstr(const char *, const char *); +char *strchr(const char *s, int c); +char *strrchr(const char *s, int c); + +// stdlib.h +int atoi(const char* nptr); +int abs(int x); +unsigned long time(); +void srand(unsigned int seed); +int rand(); +void *malloc(size_t size); +void free(void *ptr); + +// stdio.h +int printf(const char* fmt, ...); +int sprintf(char* out, const char* format, ...); +int snprintf(char* s, size_t n, const char* format, ...); +int vsprintf(char *str, const char *format, va_list ap); +int vsnprintf(char *str, size_t size, const char *format, va_list ap); +int sscanf(const char *str, const char *format, ...); + +void qsort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *)); + +#define printk printf + +// assert.h +#ifdef NDEBUG + #define assert(ignore) ((void)0) +#else + #define assert(cond) \ + do { \ + if (!(cond)) { \ + printk("Assertion fail at %s:%d\n", __FILE__, __LINE__); \ + _halt(1); \ + } \ + } while (0) +#endif + +#ifdef __cplusplus +} +#endif + +#endif