Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: fallen/milkymist-mmu
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 5cf6408
Choose a base ref
...
head repository: fallen/milkymist-mmu
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 8e87083
Choose a head ref
  • 2 commits
  • 4 files changed
  • 1 contributor

Commits on May 28, 2012

  1. Copy the full SHA
    4ab33ba View commit details

Commits on May 30, 2012

  1. Copy the full SHA
    8e87083 View commit details
Showing with 67 additions and 35 deletions.
  1. +9 −17 software/bios/main.c
  2. +4 −2 software/bios/mmu_test_gen.c
  3. +22 −7 software/libbase/console.c
  4. +32 −9 software/libbase/uart.c
26 changes: 9 additions & 17 deletions software/bios/main.c
Original file line number Diff line number Diff line change
@@ -648,7 +648,7 @@ static void readstr(char *s, int size)
}
break;
case '\e':
vga_set_console(!vga_get_console());
// vga_set_console(!vga_get_console());
break;
case 0x07:
break;
@@ -685,7 +685,6 @@ static void ethreset()
int main(int i, char **c)
{
char buffer[64];
unsigned short int k;

/* lock gdbstub ROM */
CSR_DBG_CTRL = DBG_CTRL_GDB_ROM_LOCK;
@@ -696,30 +695,23 @@ int main(int i, char **c)
CSR_GPIO_OUT = GPIO_LED1;
rescue = !((unsigned int)main > FLASH_OFFSET_REGULAR_BIOS);

irq_setmask(0);
irq_enable(1);
uart_init();
uart_force_sync(1);
irq_setmask(0);
irq_enable(0);

putsnonl(banner);
crcbios();
brd_init();

if(rescue)
printf("I: Booting in rescue mode\n");

boot_sequence();

uart_force_sync(1);
irq_enable(0);

for (k = 0 ; k < 65000 ; ++k)
asm volatile("nop");

dtlb_load_test();

uart_set_polling_mode(1);
while(1) {
if (++k == 0)
printf(".");
asm volatile("nop");
putsnonl("\e[1mBIOS>\e[0m ");
readstr(buffer, 64);
do_command(buffer);
}

return 0;
6 changes: 4 additions & 2 deletions software/bios/mmu_test_gen.c
Original file line number Diff line number Diff line change
@@ -47,6 +47,8 @@ int main(void) {
"unsigned int count;\n"
"asm volatile(\"mv %0, sp\" : \"=r\"(stack) :: );\n"
"mmu_dtlb_map(0x44002000, 0x44001000);\n"
"mmu_dtlb_map(stack, stack);\n"
"mmu_dtlb_map(stack-0x1000, stack-0x1000);\n"
"printf(\"stack == 0x%08X\\n\", stack);"
"a = 0;\n"
"b = 1;\n"
@@ -75,12 +77,12 @@ int main(void) {

puts("disable_dtlb();");
puts("printf(\"addr == 0x%08X\\n\", addr);");
puts("printf(\"[MMU OFF] *(0x%08X) == 0x%08X\\n\", addr, *(unsigned int *)addr);");
puts("printf(\"[MMU OFF] *(0x%08X) == 0x%08X\\n\", addr, *(volatile unsigned int *)addr);");
puts("enable_dtlb();");
puts("asm volatile(\"lw %0, (%1+0)\" : \"=&r\"(data) : \"r\"(addr) : );");
puts("disable_dtlb();");
puts("printf(\"[MMU ON] *(0x%08X) == 0x%08X\\n\", addr, data);");
puts("printf(\"[MMU OFF] *(0x%08X) == 0x%08X\\n\", addr-0x1000, *(unsigned int *)(addr - 0x1000));");
puts("printf(\"[MMU OFF] *(0x%08X) == 0x%08X\\n\", addr-0x1000, *(volatile unsigned int *)(addr - 0x1000));");
printf("printf(\"Test n° %02d : \");\n", test_num);
puts( "if (value == value_verif) {\n"
"\tputs(\"PASS\");\n"
29 changes: 22 additions & 7 deletions software/libbase/console.c
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@
static console_write_hook write_hook;
static console_read_hook read_hook;
static console_read_nonblock_hook read_nonblock_hook;
static char uart_polling_mode = 0;

void console_set_write_hook(console_write_hook h)
{
@@ -40,20 +41,34 @@ void console_set_read_hook(console_read_hook r, console_read_nonblock_hook rn)
static void writechar(char c)
{
uart_write(c);
if(write_hook != NULL)
write_hook(c);
}

char readchar(void)
{
while(1) {
if(uart_read_nonblock())
return uart_read();
if((read_nonblock_hook != NULL) && read_nonblock_hook())
return read_hook();
if ( uart_polling_mode )
{
while (!uart_rx_event());
uart_rx_event_ack();
return uart_getchar();
} else {
uart_write('-');
while(1) {
if(uart_read_nonblock())
return uart_read();
if((read_nonblock_hook != NULL) && read_nonblock_hook())
return read_hook();
}
}
}

void uart_set_polling_mode(char m) {
uart_polling_mode = m;
if (m)
uart_activate_irq(1);
else
uart_activate_irq(0);
}

int readchar_nonblock(void)
{
return (uart_read_nonblock()
41 changes: 32 additions & 9 deletions software/libbase/uart.c
Original file line number Diff line number Diff line change
@@ -44,20 +44,26 @@ static volatile int tx_cts;

static int force_sync;

char uart_rx_event(void)
{
unsigned int stat = CSR_UART_STAT;
return stat & UART_STAT_RX_EVT;
}

void uart_rx_event_ack(void)
{
CSR_UART_STAT = UART_STAT_RX_EVT;
}

char uart_getchar(void)
{
return CSR_UART_RXTX;
}

void uart_isr(void)
{
unsigned int stat = CSR_UART_STAT;

mmu_dtlb_map(uart_isr, uart_isr);
mmu_dtlb_map(rx_buf, rx_buf);
mmu_dtlb_map(tx_buf, tx_buf);
mmu_dtlb_map(&tx_produce, &tx_produce);
mmu_dtlb_map(&tx_consume, &tx_consume);
mmu_dtlb_map(&rx_produce, &rx_produce);
mmu_dtlb_map(&tx_cts, &tx_cts);
mmu_dtlb_map(irq_ack, irq_ack);

if(stat & UART_STAT_RX_EVT) {
rx_buf[rx_produce] = CSR_UART_RXTX;
rx_produce = (rx_produce + 1) & UART_RINGBUFFER_MASK_RX;
@@ -113,6 +119,23 @@ void uart_write(char c)
irq_setmask(oldmask);
}

void uart_activate_irq(char a)
{
unsigned int mask;
if (a)
{
CSR_UART_CTRL &= ~(UART_CTRL_TX_INT) & ~(UART_CTRL_RX_INT);
mask = irq_getmask();
mask |= IRQ_UART;
irq_setmask(mask);
} else {
CSR_UART_CTRL = UART_CTRL_TX_INT | UART_CTRL_RX_INT;
mask = irq_getmask();
mask &= ~IRQ_UART;
irq_setmask(mask);
}
}

void uart_init(void)
{
unsigned int mask;