diff --git a/kernel/arch/earm/omap_serial.c b/kernel/arch/earm/omap_serial.c index 4f82ac9c6..4f628b7a9 100644 --- a/kernel/arch/earm/omap_serial.c +++ b/kernel/arch/earm/omap_serial.c @@ -1,22 +1,59 @@ +#include #include #include +#include #include #include "omap_serial.h" +struct omap_serial { + vir_bytes base; +}; + +static struct omap_serial omap_serial = { + .base = 0, +}; + +/* + * In kernel serial for the omap. The serial driver like most other + * drivers needs to be started early and even before the MMU is turned on. + * We start by directly accessing the hardware memory address. Later on + * a when the MMU is turned on we still use a 1:1 mapping for these addresses. + * + * Pretty soon we are going to remap these addresses at later stage. And this + * requires us to use a dynamic base address. The idea is to receive a callback + * from VM with the new address to use. + * + * We also anticipate on the beaglebone port an try to keep the differences between + * the drivers to a minimum by initializing a struct here and not using (to much) + * constants in the code. + * + * The serial driver also gets used in the "pre_init" stage before the kernel is loaded + * in high memory so keep in mind there are two copies of this code in the kernel. + */ +void omap3_ser_init(){ +#ifdef DM37XX + omap_serial.base = OMAP3_DEBUG_UART_BASE; + //map(OMAP3_DEBUG_UART_BASE,&callback); +#endif + assert(omap_serial.base); +} + void omap3_ser_putc(char c) { + assert(omap_serial.base); + int i; /* Wait until FIFO's empty */ for (i = 0; i < 100000; i++) - if (mmio_read(OMAP3_DEBUG_UART_LSR) & OMAP3_LSR_THRE) + if (mmio_read(omap_serial.base + OMAP3_LSR) & OMAP3_LSR_THRE) break; /* Write character */ - mmio_write(OMAP3_DEBUG_UART_THR, c); + mmio_write(omap_serial.base + OMAP3_THR, c); /* And wait again until FIFO's empty to prevent TTY from overwriting */ for (i = 0; i < 100000; i++) - if (mmio_read(OMAP3_DEBUG_UART_LSR) & (OMAP3_LSR_THRE | OMAP3_LSR_TEMT)) + if (mmio_read(omap_serial.base + OMAP3_LSR) & (OMAP3_LSR_THRE | OMAP3_LSR_TEMT)) break; } diff --git a/kernel/arch/earm/omap_serial.h b/kernel/arch/earm/omap_serial.h index 3cb8a344e..9d3b4bb74 100644 --- a/kernel/arch/earm/omap_serial.h +++ b/kernel/arch/earm/omap_serial.h @@ -16,12 +16,9 @@ /* Supplementary status register fields */ #define OMAP3_SSR_TX_FIFO_FULL (1 << 0) /* Transmit FIFO full */ -#define OMAP3_DEBUG_UART_THR (OMAP3_DEBUG_UART_BASE + OMAP3_THR) -#define OMAP3_DEBUG_UART_LSR (OMAP3_DEBUG_UART_BASE + OMAP3_LSR) -#define OMAP3_DEBUG_UART_SSR (OMAP3_DEBUG_UART_BASE + OMAP3_SSR) - #ifndef __ASSEMBLY__ +void omap3_ser_init(); void omap3_ser_putc(char c); #endif /* __ASSEMBLY__ */ diff --git a/kernel/arch/earm/pre_init.c b/kernel/arch/earm/pre_init.c index 45464e4ea..0d62bac7a 100644 --- a/kernel/arch/earm/pre_init.c +++ b/kernel/arch/earm/pre_init.c @@ -130,7 +130,7 @@ void setup_mbi(multiboot_info_t *mbi) /* Final 'module' is actually a string holding the boot cmdline */ mbi->cmdline = MB_PARAM_MOD; - mbi->mmap_addr = (void*)&mb_memmap; + mbi->mmap_addr =(u32_t)&mb_memmap; mbi->mmap_length = sizeof(mb_memmap); mb_memmap.size = sizeof(multiboot_memory_map_t); @@ -267,6 +267,7 @@ kinfo_t *pre_init(u32_t magic, u32_t ebx) /* Clear BSS */ memset(&_edata, 0, (u32_t)&_end - (u32_t)&_edata); + omap3_ser_init(); /* Get our own copy boot params pointed to by ebx. * Here we find out whether we should do serial output. */ @@ -286,7 +287,13 @@ kinfo_t *pre_init(u32_t magic, u32_t ebx) return &kinfo; } +/* pre_init gets executed at the memory location where the kernel was loaded by the boot loader. + * at that stage we only have a minium set of functionality present (all symbols gets renamed to + * ensure this). The following methods are used in that context. Once we jump to kmain they are no + * longer used and the "real" implementations are visible + */ int send_sig(endpoint_t proc_nr, int sig_nr) { return 0; } void minix_shutdown(timer_t *t) { arch_shutdown(RBT_PANIC); } void busy_delay_ms(int x) { } int raise(int n) { panic("raise(%d)\n", n); } + diff --git a/kernel/main.c b/kernel/main.c index 288ba24e7..cf80c954e 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -127,6 +127,10 @@ void kmain(kinfo_t *local_cbi) memcpy(&kinfo, local_cbi, sizeof(kinfo)); memcpy(&kmess, kinfo.kmess, sizeof(kmess)); +#ifdef __arm__ + /* We want to initialize serial before we do any output */ + omap3_ser_init(); +#endif /* We can talk now */ printf("MINIX booting\n");