29 volatile unsigned char *uart1 = (
volatile unsigned char *) 0x4806A000;
30 volatile unsigned char *uart2 = (
volatile unsigned char *) 0x4806C000;
31 volatile unsigned char *uart3 = (
volatile unsigned char *) 0x49020000;
38 #define ATAG_CORE 0x54410001 39 #define ATAG_MEM 0x54410002 40 #define ATAG_VIDEOTEXT 0x54410003 41 #define ATAG_RAMDISK 0x54410004 42 #define ATAG_INITRD2 0x54410005 43 #define ATAG_SERIAL 0x54410006 44 #define ATAG_REVISION 0x54410007 45 #define ATAG_VIDEOLFB 0x54410008 46 #define ATAG_CMDLINE 0x54410009 71 unsigned short video_page;
72 unsigned char video_mode;
73 unsigned char video_cols;
74 unsigned short video_ega_bx;
75 unsigned char video_lines;
76 unsigned char video_isvga;
77 unsigned short video_points;
106 unsigned short lfb_width;
107 unsigned short lfb_height;
108 unsigned short lfb_depth;
109 unsigned short lfb_linelength;
112 unsigned char red_size;
113 unsigned char red_pos;
114 unsigned char green_size;
115 unsigned char green_pos;
116 unsigned char blue_size;
117 unsigned char blue_pos;
118 unsigned char rsvd_size;
119 unsigned char rsvd_pos;
144 #define MULTIBOOT_FLAG_MEM 0x001 145 #define MULTIBOOT_FLAG_DEVICE 0x002 146 #define MULTIBOOT_FLAG_CMDLINE 0x004 147 #define MULTIBOOT_FLAG_MODS 0x008 148 #define MULTIBOOT_FLAG_AOUT 0x010 149 #define MULTIBOOT_FLAG_ELF 0x020 150 #define MULTIBOOT_FLAG_MMAP 0x040 151 #define MULTIBOOT_FLAG_CONFIG 0x080 152 #define MULTIBOOT_FLAG_LOADER 0x100 153 #define MULTIBOOT_FLAG_APM 0x200 154 #define MULTIBOOT_FLAG_VBE 0x400 164 uint32_t boot_device;
177 uint32_t mmap_length;
180 uint32_t drives_length;
181 uint32_t drives_addr;
183 uint32_t config_table;
185 uint32_t boot_loader_name;
189 uint32_t vbe_control_info;
190 uint32_t vbe_mode_info;
192 uint32_t vbe_interface_seg;
193 uint32_t vbe_interface_off;
194 uint32_t vbe_interface_len;
201 #define DLL_REG 0x00 // R/W 202 #define RHR_REG 0x00 // R 203 #define THR_REG 0x00 // W 204 #define DLH_REG 0x04 // R/W 205 #define IER_REG 0x04 // R/W 206 #define IIR_REG 0x08 // R 207 #define FCR_REG 0x08 // W 208 #define EFR_REG 0x08 // RW 209 #define LCR_REG 0x0C // RW 210 #define MCR_REG 0x10 // RW 211 #define XON1_ADDR1_REG 0x10 // RW 212 #define LSR_REG 0x14 // R 213 #define XON2_ADDR2_REG 0x14 // RW 214 #define MSR_REG 0x18 // R 215 #define TCR_REG 0x18 // RW 216 #define XOFF1_REG 0x18 // RW 217 #define SPR_REG 0x1C // RW 218 #define TLR_REG 0x1C // RW 219 #define XOFF2_REG 0x1C // RW 220 #define MDR1_REG 0x20 // RW 221 #define MDR2_REG 0x24 // RW 223 #define USAR_REG 0x38 // R 225 #define SCR_REG 0x40 // RW 226 #define SSR_REG 0x44 // R 228 #define MVR_REG 0x50 // R 229 #define SYSC_REG 0x54 // RW 230 #define SYSS_REG 0x58 // R 231 #define WER_REG 0x5C // RW 234 extern "C" volatile unsigned char *uart_get(
int n)
247 extern "C" bool uart_softreset(
int n)
249 volatile unsigned char *uart = uart_get(n);
256 uart[SYSC_REG] |= 0x2;
259 while (!(uart[SYSS_REG] & 0x1))
266 extern "C" bool uart_fifodefaults(
int n)
268 volatile unsigned char *uart = uart_get(n);
275 unsigned char old_lcr_reg = uart[LCR_REG];
276 uart[LCR_REG] = 0xBF;
279 unsigned char efr_reg = uart[EFR_REG];
280 unsigned char old_enhanced_en = efr_reg & 0x8;
281 if (!(efr_reg & 0x8))
283 uart[EFR_REG] = efr_reg;
286 uart[LCR_REG] = 0x80;
289 unsigned char mcr_reg = uart[MCR_REG];
290 unsigned char old_tcl_tlr = mcr_reg & 0x20;
291 if (!(mcr_reg & 0x20))
293 uart[MCR_REG] = mcr_reg;
300 uart[LCR_REG] = 0xBF;
310 if (!old_enhanced_en)
311 uart[EFR_REG] = uart[EFR_REG] ^ 0x8;
314 uart[LCR_REG] = 0x80;
318 uart[MCR_REG] = uart[MCR_REG] ^ 0x20;
321 uart[LCR_REG] = old_lcr_reg;
329 extern "C" bool uart_protoconfig(
int n)
331 volatile unsigned char *uart = uart_get(n);
338 uart[MDR1_REG] = (uart[MDR1_REG] & ~0x7) | 0x7;
341 uart[LCR_REG] = 0xBF;
344 unsigned char efr_reg = uart[EFR_REG];
345 unsigned char old_enhanced_en = efr_reg & 0x8;
346 if (!(efr_reg & 0x8))
348 uart[EFR_REG] = efr_reg;
357 uart[LCR_REG] = 0xBF;
370 uart[LCR_REG] = 0xBF;
374 uart[EFR_REG] = uart[EFR_REG] ^ 0x8;
387 extern "C" bool uart_disableflowctl(
int n)
389 volatile unsigned char *uart = uart_get(n);
396 unsigned char old_lcr_reg = uart[LCR_REG];
397 uart[LCR_REG] = 0x80;
400 unsigned char mcr_reg = uart[MCR_REG];
401 unsigned char old_tcl_tlr = mcr_reg & 0x20;
402 if (!(mcr_reg & 0x20))
404 uart[MCR_REG] = mcr_reg;
407 uart[LCR_REG] = 0xBF;
410 unsigned char efr_reg = uart[EFR_REG];
411 unsigned char old_enhanced_en = efr_reg & 0x8;
412 if (!(efr_reg & 0x8))
414 uart[EFR_REG] = efr_reg;
424 uart[LCR_REG] = 0x80;
428 uart[MCR_REG] = uart[MCR_REG] ^ 0x20;
431 uart[LCR_REG] = old_lcr_reg;
436 extern "C" void uart_write(
int n,
char c)
438 volatile unsigned char *uart = uart_get(n);
443 while (!(uart[LSR_REG] & 0x20))
448 extern "C" char uart_read(
int n)
450 volatile unsigned char *uart = uart_get(n);
455 while (!(uart[LSR_REG] & 0x1))
457 return uart[RHR_REG];
460 extern "C" inline void writeStr(
int n,
const char *str)
467 extern "C" void writeHex(
int uart,
unsigned int n)
469 bool noZeroes =
true;
473 for (i = 28; i > 0; i -= 4)
475 tmp = (n >> i) & 0xF;
476 if (tmp == 0 && noZeroes)
482 uart_write(uart, tmp - 0xA +
'a');
487 uart_write(uart, tmp +
'0');
493 uart_write(uart, tmp - 0xA +
'a');
495 uart_write(uart, tmp +
'0');
503 : m_gpio1(0), m_gpio2(0), m_gpio3(0), m_gpio4(0), m_gpio5(0), m_gpio6(0)
512 m_gpio1 = (
volatile unsigned int *) 0x48310000;
513 initspecific(1, m_gpio1);
514 m_gpio2 = (
volatile unsigned int *) 0x49050000;
515 initspecific(2, m_gpio2);
516 m_gpio3 = (
volatile unsigned int *) 0x49052000;
517 initspecific(3, m_gpio3);
518 m_gpio4 = (
volatile unsigned int *) 0x49054000;
519 initspecific(4, m_gpio4);
520 m_gpio5 = (
volatile unsigned int *) 0x49056000;
521 initspecific(5, m_gpio5);
522 m_gpio6 = (
volatile unsigned int *) 0x49058000;
523 initspecific(6, m_gpio6);
526 void clearpin(
int pin)
530 volatile unsigned int *gpio = getGpioForPin(pin, &base);
533 writeStr(3,
"BeagleGpio::drivepin : No GPIO found for pin ");
535 writeStr(3,
"!\r\n");
540 gpio[0x24] = (1 << base);
543 void drivepin(
int pin)
547 volatile unsigned int *gpio = getGpioForPin(pin, &base);
550 writeStr(3,
"BeagleGpio::drivepin : No GPIO found for pin ");
552 writeStr(3,
"!\r\n");
559 gpio[0x25] = (1 << base);
562 bool pinstate(
int pin)
566 volatile unsigned int *gpio = getGpioForPin(pin, &base);
569 writeStr(3,
"BeagleGpio::pinstate : No GPIO found for pin ");
571 writeStr(3,
"!\r\n");
575 return (gpio[0x25] & (1 << base));
578 int capturepin(
int pin)
582 volatile unsigned int *gpio = getGpioForPin(pin, &base);
585 writeStr(3,
"BeagleGpio::capturepin :No GPIO found for pin ");
587 writeStr(3,
"!\r\n");
592 return (gpio[0xE] & (1 << base)) >> (base ? base - 1 : 0);
595 void enableoutput(
int pin)
599 volatile unsigned int *gpio = getGpioForPin(pin, &base);
602 writeStr(3,
"BeagleGpio::enableoutput :No GPIO found for pin ");
604 writeStr(3,
"!\r\n");
609 if (gpio[0xD] & (1 << base))
610 gpio[0xD] ^= (1 << base);
624 unsigned int rev = gpio[0];
627 writeStr(3,
": revision ");
628 writeHex(3, (rev & 0xF0) >> 4);
630 writeHex(3, rev & 0x0F);
631 writeStr(3,
" - initialising: ");
635 while (!(gpio[0x5] & 1))
646 writeStr(3,
"Done.\r\n");
653 volatile unsigned int *gpio = 0;
659 else if ((pin >= 34) && (pin < 64))
664 else if ((pin >= 64) && (pin < 96))
669 else if ((pin >= 96) && (pin < 128))
674 else if ((pin >= 128) && (pin < 160))
679 else if ((pin >= 160) && (pin < 192))
689 volatile unsigned int *m_gpio1;
690 volatile unsigned int *m_gpio2;
691 volatile unsigned int *m_gpio3;
692 volatile unsigned int *m_gpio4;
693 volatile unsigned int *m_gpio5;
694 volatile unsigned int *m_gpio6;
712 uint32_t ignore : 30;
722 uint32_t baseaddr : 22;
737 uint32_t sectiontype : 1;
760 uint32_t ignore : 30;
793 extern "C" void __start(uint32_t r0, uint32_t machineType,
struct atag *tagList)
795 void __start(uint32_t r0, uint32_t machineType,
struct atag *tagList)
799 bool b = uart_softreset(3);
803 b = uart_fifodefaults(3);
807 b = uart_protoconfig(3);
811 b = uart_disableflowctl(3);
816 writeStr(3,
"Pedigree for the BeagleBoard\r\n\r\n");
820 gpio.enableoutput(149);
821 gpio.enableoutput(150);
828 3,
"\r\nPlease press the USER button on the board to continue.\r\n");
830 while (!gpio.capturepin(7))
833 writeStr(3,
"USER button pressed, continuing...\r\n\r\n");
836 3,
"Press 1 to toggle the USR0 LED, and 2 to toggle the USR1 " 837 "LED.\r\nPress 0 to clear both LEDs. Hit ENTER to boot the " 841 char c = uart_read(3);
844 writeStr(3,
"Toggling USR0 LED\r\n");
845 if (gpio.pinstate(150))
852 writeStr(3,
"Toggling USR1 LED\r\n");
853 if (gpio.pinstate(149))
860 writeStr(3,
"Clearing both USR0 and USR1 LEDs\r\n");
864 else if ((c == 13) || (c == 10))
868 writeStr(3,
"\r\n\r\nPlease wait while the kernel is loaded...\r\n");
871 writeStr(3,
"Preparing file... ");
872 elf.
load((uint8_t *) file, 0);
873 writeStr(3,
"Done!\r\n");
875 writeStr(3,
"Loading file into memory (please wait) ");
877 writeStr(3,
" Done!\r\n");
883 writeStr(3,
"Creating bootstrap information structure... ");
884 ByteSet(bs, 0,
sizeof(*bs));
885 bs->shndx = elf.m_pHeader->shstrndx;
886 bs->num = elf.m_pHeader->shnum;
887 bs->size = elf.m_pHeader->shentsize;
888 bs->addr = (
unsigned int) elf.m_pSectionHeaders;
889 bs->flags |= MULTIBOOT_FLAG_ELF;
892 bs->mods_addr = reinterpret_cast<uint32_t>(elf.
m_pBuffer);
893 bs->mods_count = (
sizeof file) + 0x1000;
894 bs->flags |= MULTIBOOT_FLAG_MODS;
897 for (
int i = 0; i < elf.m_pHeader->shnum; i++)
899 elf.m_pSectionHeaders[i].addr =
900 elf.m_pSectionHeaders[i].offset + (uint32_t) elf.
m_pBuffer;
902 writeStr(3,
"Done!\r\n");
911 3,
"Now starting the Pedigree kernel (can take a while, please " Bootstrap structure passed to the kernel entry point.
void initspecific(int n, volatile unsigned int *gpio)
Initialises a specific GPIO to a given set of defaults.
uint8_t * m_pBuffer
Offset of the file in memory.
volatile unsigned int * getGpioForPin(int pin, int *bit)
bool load(uint8_t *pBuffer, unsigned int nBufferLength)