Compare commits

..

4 Commits

Author SHA1 Message Date
c211d8cde2 Fix: lab3 on-board problems 2025-04-01 23:38:06 +08:00
2af52f761c Fix: lab3 bug 2025-04-01 18:34:59 +08:00
09c2de666c Fix: enable interrupt later 2025-04-01 17:54:24 +08:00
6998a144e5 Feat: update README 2025-04-01 17:25:34 +08:00
9 changed files with 67 additions and 24 deletions

View File

@@ -1 +1 @@
[![Review Assignment Due Date](https://classroom.github.com/assets/deadline-readme-button-22041afd0340ce965d47ae6ef1cefeee28c7c493a6346c4f15d667ab976d596c.svg)](https://classroom.github.com/a/lAsr-c9M)
# osc2025/ytshih

View File

@@ -19,7 +19,7 @@ static inline char *_logger_string(char *dest, const char *src)
}
static inline char *_logger_hex(char *dest, uint64_t x)
{
for (int n, c = 28; c >= 0; c -= 4) {
for (int n, c = 60; c >= 0; c -= 4) {
n = (x >> c) & 0xf;
n += (n > 9) ? 0x37 : 0x30;
*dest++ = (char)n;

View File

@@ -2,7 +2,7 @@
// save general registers to stack
.macro save_all
sub sp, sp, 36 * 8
sub sp, sp, 34 * 8
stp x0, x1, [sp, 16 * 0]
stp x2, x3, [sp, 16 * 1]
stp x4, x5, [sp, 16 * 2]
@@ -18,17 +18,22 @@
stp x24, x25, [sp, 16 * 12]
stp x26, x27, [sp, 16 * 13]
stp x28, x29, [sp, 16 * 14]
stp x30, lr, [sp, 16 * 15]
mrs x0, spsr_el1
mrs x1, elr_el1
mrs x2, esr_el1
stp x0, x1, [sp, 16 * 16]
str x2, [sp, 16 * 17]
stp x0, x1, [sp, 16 * 15]
stp x2, lr, [sp, 16 * 16]
.endm
// load general registers from stack
.macro load_all
ldp x0, x1, [sp, 16 * 15]
ldp x2, lr, [sp, 16 * 16]
msr spsr_el1, x0
msr elr_el1, x1
msr esr_el1, x2
ldp x0, x1, [sp, 16 * 0]
ldp x2, x3, [sp, 16 * 1]
ldp x4, x5, [sp, 16 * 2]
@@ -44,14 +49,8 @@
ldp x24, x25, [sp, 16 * 12]
ldp x26, x27, [sp, 16 * 13]
ldp x28, x29, [sp, 16 * 14]
ldp x30, lr, [sp, 16 * 15]
mrs x0, spsr_el1
mrs x1, elr_el1
mrs x2, esr_el1
ldp x0, x1, [sp, 16 * 16]
ldr x2, [sp, 16 * 17]
add sp, sp, 36 * 8
add sp, sp, 34 * 8
.endm
_null_handler:

View File

@@ -105,7 +105,8 @@ void irq_handler(void)
void wfe(void)
{
if (!global_interrupt_pool) {
asm volatile("wfe");
// asm volatile("wfe");
asm volatile("nop");
return;
}

View File

@@ -24,11 +24,11 @@ int ringbuffer_push(ringbuffer_t *buf, uint8_t val)
return ERR_OUT_OF_BOUND;
*buf->write++ = val;
++buf->size;
if (buf->write == buf->data + buf->cap)
buf->write = buf->data;
++buf->size;
return NO_ERROR;
}
@@ -38,10 +38,18 @@ uint8_t ringbuffer_bump(ringbuffer_t *buf)
exit(ERR_INVALID_OP);
uint8_t ret = *buf->read++;
--buf->size;
if (buf->read == buf->data + buf->cap)
buf->read = buf->data;
--buf->size;
return ret;
}
uint8_t ringbuffer_peek(ringbuffer_t *buf)
{
if (buf->size == 0)
exit(ERR_INVALID_OP);
return *buf->read;
}

View File

@@ -159,20 +159,41 @@ void _reboot(void)
_reset(1 << 16);
}
char *_shell_buf = (char *)0x0;
int _shell_sz = 0;
static inline
int _shell_operations(char ch)
{
switch (ch) {
case 0x7f:
if (_shell_sz > 0) {
--_shell_sz;
uart_puts("\b \b");
}
return true;
default:
}
return false;
}
int shell(file_node_t *initrd_root)
{
uart_puts("# ");
char *buf = kmalloc(INPUT_BUFLEN * sizeof(char)), ch;
int sz = 0;
char ch;
_shell_buf = kmalloc(INPUT_BUFLEN * sizeof(char));
_shell_sz = 0;
while ((ch = uart_getc()) != '\n') {
buf[sz++] = ch;
if (_shell_operations(ch))
continue;
_shell_buf[_shell_sz++] = ch;
uart_putb((const uint8_t *)&ch, 1);
}
uart_puts(ENDL);
buf[sz] = ' ';
_shell_buf[_shell_sz] = ' ';
vector_t *args = make_vector(0);
for (char *saveptr = 0x0, *tok = strtok_r(buf, " ", &saveptr);
for (char *saveptr = 0x0, *tok = strtok_r(_shell_buf, " ", &saveptr);
tok; tok = strtok_r((char *)0x0, " ", &saveptr)) {
VEC_PUSH(args, tok);
LOG(tok);

View File

@@ -61,6 +61,16 @@ void _set_timer_interrrupt()
}
}
static inline
void _traverse(timer_t *t)
{
if (!t) return;
DEBUG_EXCEP(t->data.firing_tick);
t->data.func(t->data.param);
_traverse(t->_l);
_traverse(t->_r);
}
void add_task(task_t task)
{
DEBUG_EXCEP("add task");
@@ -74,6 +84,8 @@ void add_task(task_t task)
};
global_timer = _merge(global_timer, newtimer);
_traverse(global_timer);
_set_timer_interrrupt();
}

View File

@@ -162,6 +162,7 @@ size_t uart_getb_async(uint8_t *bytes, size_t len)
for (; recvlen < len; ++bytes, ++recvlen) {
while (!uart_readbuf->size)
wfe(); // wait for interrupt
*bytes = ringbuffer_bump(uart_readbuf);
}

View File

@@ -14,7 +14,6 @@
void init(void *dtb, file_node_t **initrd_root)
{
init_exception();
init_interrupt();
// UART
uart_init();
@@ -34,6 +33,8 @@ void init(void *dtb, file_node_t **initrd_root)
// Memory (Buddy system)
mman_init();
init_interrupt();
}
static inline
@@ -61,8 +62,8 @@ void main(void *dtb)
file_node_t *initrd_root = 0x0;
init(dtb, &initrd_root);
LOG("system booting in");
_print_time(0x0);
// LOG("system booting in");
// _print_time(0x0);
uint64_t el;
R_SYSREG(el, CurrentEL);