sw: bootrom: Improve performance and reduce size

This commit is contained in:
Markus Koch 2024-08-07 18:01:22 +02:00
parent 49ccbea9e9
commit e561c31691

View File

@ -22,6 +22,7 @@ __attribute__((noreturn)) void _start() {
uint8_t opcode; uint8_t opcode;
uint8_t *ptr; uint8_t *ptr;
uint32_t length; uint32_t length;
uint32_t sr;
/*while (1) { /*while (1) {
while (UART0_SR & UART0_SR_RX_DATA_EMPTY); while (UART0_SR & UART0_SR_RX_DATA_EMPTY);
@ -32,52 +33,37 @@ __attribute__((noreturn)) void _start() {
while (1) { while (1) {
while (UART0_SR & UART0_SR_RX_DATA_EMPTY); while (UART0_SR & UART0_SR_RX_DATA_EMPTY);
c = UART0_DR; c = (uint8_t)UART0_DR;
sr = (sr << 8) | c;
state++; state++;
switch (state) { switch (state) {
case 1: // Opcode case 1: // Opcode
opcode = c; opcode = c;
ptr = 0;
length = 0;
if (c == 0) // NOP if (c == 0) // NOP
state = 0; state = 0;
break; break;
case 2: // Address case 5: // Address
case 3: ptr = (uint8_t*)sr;
case 4:
case 5:
ptr = (uint8_t*)(((uint32_t)ptr << 8) | c);
if (state != 5)
break;
if (opcode == 3) { // Jump if (opcode == 3) { // Jump
//((void (*)()) ptr)(); //((void (*)()) ptr)();
asm("jalr %0" : : "r"(ptr)); // Not sure why, but the jump above causes GCC to save variables to the stack at the beginning of this function asm("jalr %0" : : "r"(ptr)); // Not sure why, but the jump above causes GCC to save variables to the stack at the beginning of this function
__builtin_unreachable(); __builtin_unreachable();
} }
break; break;
case 6: // Length case 9: // Data
case 7: length = sr;
case 8:
case 9:
length = (length << 8) | c;
if (state != 9)
break;
if (opcode == 2) { // Read if (opcode == 2) { // Read
for (; length > 0; length--) { for (; length > 0; length--) {
while (UART0_SR & UART0_SR_TX_FULL); while (UART0_SR & UART0_SR_TX_FULL);
UART0_DR = *(ptr); UART0_DR = *(ptr++);
ptr++; }
} else { // Write
for (; length > 0; length--) {
while (UART0_SR & UART0_SR_RX_DATA_EMPTY);
*(ptr++) = UART0_DR;
} }
state = 0;
}
break;
case 10: // Write byte by byte
*(ptr++) = c;
if (--length == 0) {
state = 0;
} else {
state--; // Stay in this state
} }
state = 0;
break; break;
default: default:
break; break;