-
Notifications
You must be signed in to change notification settings - Fork 0
vprintf, kprintfの修正 #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
no2ca
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
putchar/kputcharがどこで設定されているか分かりやすくて良いと思いました👍
|
@74rina int vprintf(const char *fmt, va_list vargs) {
return _vprintf(putchar, fmt, vargs);
}
int _vprintf(putc_fn_t putc, const char *fmt, va_list vargs) {
...
} |
|
void __common_putc(char c);
int vprintf(putc_fn_t putc, const char *fmt, va_list vargs) {
...
__common_putc(...);
return count;
}
void kputchar(char ch) {...}
void __common_putc(char ch) __attribute__((alias("kputchar")));
void putchar(char ch) {...}
void __common_putc(char ch) __attribute__((alias("putchar")));とする手もあり、どっちがきれいかは諸説あり |
Latte72R
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kernel/kernel.c
Outdated
| void kputchar(char ch) { sbi_call(ch, 0, 0, 0, 0, 0, 0, 1); } | ||
| void __common_putc(char ch) __attribute__((alias("kputchar"))); | ||
|
|
||
| void putchar(char ch) { kputchar(ch); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここの putchar は必要ないです.
common/common.c
Outdated
| #include "common.h" | ||
|
|
||
| int vprintf(const char *fmt, va_list vargs) { | ||
| void __common_putc(char c); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
関数の宣言はデフォルトで extern なので必要はないけど,extern void __common_putc(char c); のほうが分かりやすいかも.
common/common.c
Outdated
| int vprintf(const char *fmt, va_list vargs) { | ||
| void __common_putc(char c); | ||
|
|
||
| int vprintf(putc_fn_t __common_putc, const char *fmt, va_list vargs) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
putc_fn_t __common_putc を受け取る必要はないです.
common/common.h
Outdated
|
|
||
| int printf(const char *fmt, ...); | ||
| int vprintf(const char *fmt, va_list ap); | ||
| int vprintf(putc_fn_t putc, const char *fmt, va_list vargs); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
putc_fn_t __common_putc は必要ないです.(上に同じく)
common/common_types.h
Outdated
| typedef uint32_t paddr_t; | ||
| typedef uint32_t vaddr_t; | ||
| typedef uint8_t bool; | ||
| typedef void (*putc_fn_t)(char); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
putc_fn_t __common_putc を廃止するので,これも必要ないです.
kernel/kernel.c
Outdated
| va_list vargs; | ||
| va_start(vargs, fmt); | ||
| int ret = kvprintf(fmt, vargs); | ||
| int ret = vprintf(kputchar, fmt, vargs); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここも変更してください.
user/usys.c
Outdated
| void sys_concat_first_file(void) { syscall(SYS_CAT_FIRST_FILE, 0, 0, 0); } | ||
|
|
||
|
|
||
| int vprintf(void (*putc)(char), const char *fmt, va_list vargs); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
common.h で宣言しているため不要です.
| return count; | ||
| } | ||
|
|
||
| int printf(const char *fmt, ...) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
この printf を消す必要はありません.
user/usys.c
Outdated
|
|
||
|
|
||
| int vprintf(void (*putc)(char), const char *fmt, va_list vargs); | ||
| int printf(const char *fmt, ...) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
printf は common.h に置いてください.
| int create_file(const char *name, const uint8_t *data, uint32_t size); | ||
| void sys_list_root_dir(void); | ||
| void sys_concat_first_file(void); | ||
| int printf(const char *fmt, ...); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
printf は common.h に置いてください.
commonのvprintfで、特権に依存するputcharを直接呼ばないように変更しました(引数のputcで、kputchar(カーネル)またはputchar(ユーザー)を指定する形です)。
ユーザーのprintf → vprintf( putchar{ syscall } )
カーネルのkprintf → vprintf( kputchar{ sbi_call } )
という構成にしました。
正しい実装か分からず、レビューお願いいたします😭