lab2 增加 lab1 变更

This commit is contained in:
KAAAsS 2021-05-12 22:56:57 +08:00
parent 1c15a8b9d9
commit fd018168a9
Signed by: KAAAsS
GPG Key ID: D56625F3E671882F
3 changed files with 39 additions and 1 deletions

2
lab2/.gitignore vendored
View File

@ -14,3 +14,5 @@ build
*.out
*.pyc
chcore.out
.idea

View File

@ -119,7 +119,25 @@ static int printk_write_num(char **out, long long i, int base, int sign,
// store the digitals in the buffer `print_buf`:
// 1. the last postion of this buffer must be '\0'
// 2. the format is only decided by `base` and `letbase` here
int len = 0;
s = print_buf + 1;
while (u > 0) {
t = u % base;
u /= base;
if (t <= 9)
s[len++] = t + '0';
else
s[len++] = t - 10 + (letbase ? 'a': 'A');
}
s[len] = '\0';
// swap print_buf
char ch;
for (int i = 0; i < len / 2; i++) {
ch = s[i];
s[i] = s[len - 1 - i];
s[len - 1 - i] = ch;
}
if (neg) {
if (width && (flags & PAD_ZERO)) {
simple_outputchar(out, '-');

View File

@ -15,6 +15,9 @@
#include <common/printk.h>
#include <common/types.h>
#include <common/machine.h>
extern char kernel_stack[PLAT_CPU_NUM][KERNEL_STACK_SIZE];
static inline __attribute__ ((always_inline))
u64 read_fp()
@ -30,6 +33,21 @@ int stack_backtrace()
printk("Stack backtrace:\n");
// Your code here.
u64 *fp, *preFp;
fp = read_fp();
// until stack end
while (true) {
preFp = *fp;
// entry frame
if (preFp == 0)
break;
printk("LR %lx FP %lx Args", *(preFp + 1), preFp);
for (int i = 0; i < 5; i++) {
printk(" %lx", *(fp + 2 + i));
}
printk("\n");
fp = preFp;
}
return 0;
}