Skip to content

Commit 7086710

Browse files
committed
various changes, moving repo to another pc
1 parent b87e962 commit 7086710

File tree

9 files changed

+111
-10
lines changed

9 files changed

+111
-10
lines changed

arch/vc4/arch.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,32 @@
11
#include <sys/types.h>
22
#include <stdint.h>
33
#include <lk/debug.h>
4+
#include <lk/console_cmd.h>
5+
#include <lk/reg.h>
6+
#include <platform/bcm28xx.h>
7+
8+
static int cmd_boot_other_core(int argc, const cmd_args *argv);
9+
10+
static char core2_stack[4096];
11+
uint32_t core2_stack_top = 0;
12+
13+
STATIC_COMMAND_START
14+
STATIC_COMMAND("boot_other_core", "boot the 2nd vpu core", &cmd_boot_other_core)
15+
STATIC_COMMAND_END(arch);
416

517
void arch_early_init(void) {
18+
uint32_t r28, sp, sr;
19+
__asm__ volatile ("mov %0, r28" : "=r"(r28));
20+
__asm__ volatile ("mov %0, sp" : "=r"(sp));
21+
__asm__ volatile ("mov %0, sr" : "=r"(sr));
22+
dprintf(INFO, "arch_early_init\nr28: 0x%x\nsp: 0x%x\nsr: 0x%x\n", r28, sp, sr);
623
}
724

825
void arch_init(void) {
26+
uint32_t r28, sp;
27+
__asm__ volatile ("mov %0, r28" : "=r"(r28));
28+
__asm__ volatile ("mov %0, sp" : "=r"(sp));
29+
dprintf(INFO, "arch_init\nr28: 0x%x\nsp: 0x%x\n", r28, sp);
930
}
1031

1132
void arch_idle(void) {
@@ -16,3 +37,16 @@ void arch_chain_load(void *entry, ulong arg0, ulong arg1, ulong arg2, ulong arg3
1637
PANIC_UNIMPLEMENTED;
1738
}
1839

40+
void core2_start();
41+
42+
static int cmd_boot_other_core(int argc, const cmd_args *argv) {
43+
core2_stack_top = (core2_stack + sizeof(core2_stack)) - 4;
44+
*REG32(A2W_PLLC_CORE1) = A2W_PASSWORD | 6; // 3ghz/6 == 500mhz
45+
*REG32(IC1_WAKEUP) = &core2_start;
46+
return 0;
47+
}
48+
49+
void core2_entry() {
50+
dprintf(INFO, "core2 says hello\n");
51+
for (;;);
52+
}

arch/vc4/intc.c

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ struct handlerArgPair irq_handlers[64];
2121
// if the highest bit on this addr is set, the cpu will switch into supervisor mode
2222
irqType __attribute__ ((aligned (512))) vectorTable[144]; // might only need to be 128 entries
2323

24+
uint8_t irq_stack0[4096];
25+
2426
static const char* g_ExceptionNames[] = {
2527
"Zero",
2628
"Misaligned",
@@ -50,6 +52,10 @@ void set_interrupt(int intno, bool enable, int core) {
5052

5153

5254
void intc_init(void) {
55+
uint32_t r28, sp;
56+
__asm__ volatile ("mov %0, r28" : "=r"(r28));
57+
__asm__ volatile ("mov %0, sp" : "=r"(sp));
58+
dprintf(INFO, "intc_init\nr28: 0x%x\nsp: 0x%x\n", r28, sp);
5359
// TODO
5460
for (int i=0; i<64; i++) {
5561
irq_handlers[0].h = 0; // is this needed? maybe .bss already took care of it?
@@ -77,18 +83,23 @@ void intc_init(void) {
7783
}
7884
// swi opcode handler
7985
for (int i=32; i<=63; i++) {
80-
vectorTable[i] = fleh_irq;
86+
vectorTable[i] = (uint32_t)fleh_irq | 1;
8187
}
8288
// external interrupts
8389
for (int i=64; i<=127; i++) {
84-
vectorTable[i] = fleh_irq;
90+
vectorTable[i] = (uint32_t)fleh_irq | 1;
8591
}
8692

93+
uint32_t irq_sp = (irq_stack0 + sizeof(irq_stack0)) - 4;
94+
dprintf(INFO, "r28 = 0x%x\nirq_stack0: %p\nsizeof(irq_stack0): %d\n", irq_sp, irq_stack0, sizeof(irq_stack0));
95+
96+
__asm__ volatile ("mov r28, 0xdeadbeef": :"r"(irq_sp));
97+
8798
*REG32(IC0_VADDR) = vectorTable;
8899
*REG32(IC1_VADDR) = vectorTable;
89100

90101
if (*REG32(IC0_VADDR) != vectorTable) {
91-
printf("vector table now at 0x%08lx 0x%08lx\n", *REG32(IC0_VADDR), (uint32_t)vectorTable);
102+
printf("vector table now at 0x%08x 0x%08x\n", *REG32(IC0_VADDR), (uint32_t)vectorTable);
92103
panic("vector table failed to install");
93104
}
94105
}
@@ -182,11 +193,25 @@ void sleh_fatal(vc4_saved_state_t* pcb, uint32_t n) {
182193
while(true) __asm__ volatile ("nop");
183194
}
184195

196+
// upon entry to this function(before its prologue runs), sp and r0 point to a `struct vc4_saved_state_t`
197+
// r0 (which lands in pcb) contains a copy of that sp from before the prologue
198+
// some common values and offsets:
199+
// r0 + 0: r23
200+
// ...
201+
// r0 + 92: r0
202+
// r0 + 96: lr
203+
// r0 + 100: sr
204+
// r0 + 104: pc
185205
void sleh_irq(vc4_saved_state_t* pcb, uint32_t tp) {
186206
uint32_t status = *REG32(IC0_S);
187207
uint32_t source = status & 0xFF;
188-
uint32_t cs;
189-
int ret;
208+
enum handler_return ret = INT_NO_RESCHEDULE;
209+
210+
uint32_t r28, sp, sr;
211+
__asm__ volatile ("mov %0, r28" : "=r"(r28));
212+
__asm__ volatile ("mov %0, sp" : "=r"(sp));
213+
__asm__ volatile ("mov %0, sr" : "=r"(sr));
214+
//dprintf(INFO, "sleh_irq\nr28: 0x%x\nsp: 0x%x\nsr: 0x%x\n", r28, sp, sr);
190215

191216
//dprintf(INFO, "VPU Received interrupt from source %d\n", source);
192217

@@ -195,7 +220,11 @@ void sleh_irq(vc4_saved_state_t* pcb, uint32_t tp) {
195220
case 121: // uart
196221
assert(irq_handlers[source - 64].h);
197222
ret = irq_handlers[source - 64].h(irq_handlers[source - 64].arg);
198-
if (ret == INT_RESCHEDULE) thread_preempt();
223+
if (ret == INT_RESCHEDULE) {
224+
//dprintf(INFO, "pre-emptying\n");
225+
thread_preempt();
226+
//dprintf(INFO, "done preempt\n");
227+
}
199228
break;
200229
case INTERRUPT_ARM:
201230
// fired when the arm cpu writes to the arm->vpu mailbox

arch/vc4/interrupt.S

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ fleh_irq:
4848
SaveRegsAll
4949
mov r0, sp
5050
mov r1, r29
51-
di
5251
bl sleh_irq
5352
return_from_exception:
5453
ldm r16-r23, (sp++)

arch/vc4/start.S

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,14 @@ _start:
99
bl lk_main
1010
loop:
1111
b loop
12+
13+
.global core2_start
14+
core2_start:
15+
mov r0, core2_stack_top
16+
ld sp, (r0)
17+
mov r0, 0
18+
mov r1, 'A'
19+
bl uart_putc
20+
bl core2_entry
21+
loop2:
22+
b loop2

arch/vc4/thread.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
void vc4_context_switch(uint32_t *oldsp, uint32_t newsp);
55

66
void arch_context_switch(thread_t *oldthread, thread_t *newthread) {
7+
uint32_t r28, sp;
8+
__asm__ volatile ("mov %0, r28" : "=r"(r28));
9+
__asm__ volatile ("mov %0, sp" : "=r"(sp));
10+
//dprintf(INFO, "arch_context_switch\nr28: 0x%x\nsp: 0x%x\n", r28, sp);
11+
//dprintf(INFO, "switching (%s) -> %p(%s)\n", oldthread->name, newthread->arch.sp, newthread->name);
712
vc4_context_switch(&oldthread->arch.sp, newthread->arch.sp);
813
}
914

@@ -17,16 +22,23 @@ static inline void push(thread_t *t, uint32_t val) {
1722
static void initial_thread_func(void) __NO_RETURN;
1823
static void initial_thread_func(void) {
1924
thread_t *ct = get_current_thread();
25+
uint32_t own_sp;
26+
27+
__asm__ volatile ("mov %0, sp": "=r"(own_sp));
28+
dprintf(INFO, "thread %p(%s) starting with sp near 0x%x\n", ct, ct->name, own_sp);
2029

2130
int ret = ct->entry(ct->arg);
2231

2332
thread_exit(ret);
2433
}
2534

2635
void arch_thread_initialize(thread_t *t) {
36+
printf("thread %p(%s) has a stack of %p+0x%x\n", t, t->name, t->stack, t->stack_size);
2737
t->arch.sp = (t->stack + t->stack_size) - 4;
2838
push(t, &initial_thread_func);
29-
push(t, 0); // the initial frame-pointer
39+
for (int i=6; i<=23; i++) {
40+
push(t, 0); // r${i}
41+
}
3042
}
3143

3244
void arch_dump_thread(thread_t *t) {

arch/vc4/thread_asm.S

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
// r0 is address to save the sp to
44
// r1 is the new sp to load
55
vc4_context_switch:
6-
stm r6,lr,(--sp)
6+
stm lr, (--sp)
7+
stm r6-r15, (--sp)
8+
stm r16-r23, (--sp)
79
st sp, (r0)
810
mov sp, r1
9-
ldm r6,pc,(sp++)
11+
ldm r16-r23, (sp++)
12+
ldm r6-r15, (sp++)
13+
ldm pc,(sp++)

kernel/thread.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,8 @@ void thread_resched(void) {
461461
thread_t *current_thread = get_current_thread();
462462
uint cpu = arch_curr_cpu_num();
463463

464+
//dprintf(INFO, "thread_resched called on thread %p(%s) on core %d\n", current_thread, current_thread->name, cpu);
465+
464466
DEBUG_ASSERT(arch_ints_disabled());
465467
DEBUG_ASSERT(spin_lock_held(&thread_lock));
466468
DEBUG_ASSERT(current_thread->state != THREAD_RUNNING);
@@ -601,6 +603,8 @@ void thread_yield(void) {
601603

602604
THREAD_STATS_INC(yields);
603605

606+
dprintf(INFO, "thread_yield\n");
607+
604608
/* we are yielding the cpu, so stick ourselves into the tail of the run queue and reschedule */
605609
current_thread->state = THREAD_READY;
606610
current_thread->remaining_quantum = 0;

platform/bcm28xx/platform.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,10 @@ void platform_early_init(void) {
208208
}
209209

210210
void platform_init(void) {
211+
uint32_t r28, sp;
212+
__asm__ volatile ("mov %0, r28" : "=r"(r28));
213+
__asm__ volatile ("mov %0, sp" : "=r"(sp));
214+
dprintf(INFO, "platform_init\nr28: 0x%x\nsp: 0x%x\n", r28, sp);
211215
uart_init();
212216
#if BCM2837
213217
init_framebuffer();

todo.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
use TARGET_HAS_DEBUG_LED on rpi
2+
3+
fix \r\n issues
4+
an IRQ between \r and \n can lead to text getting overwritten

0 commit comments

Comments
 (0)