提交 bcd3e285 编写于 作者: Y Yanyan Jiang

format refactors

上级 fb27cbbc
......@@ -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 {
......
......@@ -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
......
......@@ -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;
......
......@@ -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;
......
......@@ -97,7 +97,7 @@ int _map(_AddressSpace *as, void *va, void *pa, int prot) {
else {
pp->is_mapped = false;
}
return 0;
}
......
......@@ -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;
......
......@@ -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 {
......
......@@ -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++) {
......
......@@ -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));
}
......
......@@ -58,7 +58,6 @@ void _halt(int code) {
}
outw(0x604, 0x2000); // offer of qemu :)
while (1) hlt();
}
_Area __am_heap_init() {
......
......@@ -15,7 +15,6 @@
#ifndef __ASSEMBLER__
#include <am.h>
#include <klib.h>
#define ROUNDUP(a, sz) ((((uintptr_t)a)+(sz)-1) & ~((sz)-1))
#define ROUNDDOWN(a, sz) ((((uintptr_t)a)) & ~((sz)-1))
......
/*
* Static runtime library for a system software on AbstractMachine
*/
#ifndef __KLIB_H__
#define __KLIB_H__
#include <am.h>
#include <stdarg.h>
//#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 <am.h>
#include <stdarg.h>
//#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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册