Changeset f6f22cdb in mainline
- Timestamp:
- 2013-12-27T18:45:56Z (11 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 32e8cd1
- Parents:
- e47ed05
- Location:
- boot/arch/sparc32
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
boot/arch/sparc32/Makefile.inc
re47ed05 rf6f22cdb 40 40 41 41 BITS = 32 42 ENDIANESS = LE42 ENDIANESS = BE 43 43 44 44 SOURCES = \ -
boot/arch/sparc32/_link.ld.in
re47ed05 rf6f22cdb 26 26 } 27 27 bdata_end = .; 28 28 29 29 /DISCARD/ : { 30 30 *(.gnu.*); -
boot/arch/sparc32/include/ambapp.h
re47ed05 rf6f22cdb 37 37 #define BOOT_sparc32_AMBAPP_H 38 38 39 #define AMBAPP_MAX_DEVICES6440 #define AMBAPP_AHBMASTER_AREA0xfffff00041 #define AMBAPP_AHBSLAVE_AREA0xfffff80042 #define AMBAPP_CONF_AREA0xff00039 #define AMBAPP_MAX_DEVICES 64 40 #define AMBAPP_AHBMASTER_AREA 0xfffff000 41 #define AMBAPP_AHBSLAVE_AREA 0xfffff800 42 #define AMBAPP_CONF_AREA 0xff000 43 43 44 44 typedef enum { 45 GAISLER 46 ESA 45 GAISLER = 1, 46 ESA = 4 47 47 } amba_vendor_id_t; 48 48 49 49 typedef enum { 50 GAISLER_LEON3 51 GAISLER_LEON3DSU 52 GAISLER_ETHAHB 53 GAISLER_APBMST 54 GAISLER_AHBUART 55 GAISLER_SRCTRL 56 GAISLER_SDCTRL 57 GAISLER_APBUART = 0x00C,58 GAISLER_IRQMP = 0x00D,59 GAISLER_AHBRAM = 0x00E,60 GAISLER_GPTIMER 61 GAISLER_PCITRG 62 GAISLER_PCISBRG 63 GAISLER_PCIFBRG 64 GAISLER_PCITRACE 65 GAISLER_PCIDMA 66 GAISLER_AHBTRACE 67 GAISLER_ETHDSU 68 GAISLER_PIOPORT = 0x01A,69 GAISLER_AHBJTAG 70 GAISLER_SPW 71 GAISLER_ATACTRL 72 GAISLER_VGA 73 GAISLER_KBD 74 GAISLER_ETHMAC = 0x01D,75 GAISLER_DDRSPA 76 GAISLER_EHCI 77 GAISLER_UHCI 78 GAISLER_SPW2 79 GAISLER_DDR2SPA = 0x02E,80 GAISLER_AHBSTAT 81 GAISLER_FTMCTRL 82 ESA_MCTRL = 0x00F,50 GAISLER_LEON3 = 0x003, 51 GAISLER_LEON3DSU = 0x004, 52 GAISLER_ETHAHB = 0x005, 53 GAISLER_APBMST = 0x006, 54 GAISLER_AHBUART = 0x007, 55 GAISLER_SRCTRL = 0x008, 56 GAISLER_SDCTRL = 0x009, 57 GAISLER_APBUART = 0x00c, 58 GAISLER_IRQMP = 0x00d, 59 GAISLER_AHBRAM = 0x00e, 60 GAISLER_GPTIMER = 0x011, 61 GAISLER_PCITRG = 0x012, 62 GAISLER_PCISBRG = 0x013, 63 GAISLER_PCIFBRG = 0x014, 64 GAISLER_PCITRACE = 0x015, 65 GAISLER_PCIDMA = 0x016, 66 GAISLER_AHBTRACE = 0x017, 67 GAISLER_ETHDSU = 0x018, 68 GAISLER_PIOPORT = 0x01a, 69 GAISLER_AHBJTAG = 0x01c, 70 GAISLER_SPW = 0x01f, 71 GAISLER_ATACTRL = 0x024, 72 GAISLER_VGA = 0x061, 73 GAISLER_KBD = 0x060, 74 GAISLER_ETHMAC = 0x01d, 75 GAISLER_DDRSPA = 0x025, 76 GAISLER_EHCI = 0x026, 77 GAISLER_UHCI = 0x027, 78 GAISLER_SPW2 = 0x029, 79 GAISLER_DDR2SPA = 0x02e, 80 GAISLER_AHBSTAT = 0x052, 81 GAISLER_FTMCTRL = 0x054, 82 ESA_MCTRL = 0x00f, 83 83 } amba_device_id_t; 84 84 … … 109 109 110 110 typedef struct { 111 unsigned int addr : 12;112 unsigned int reserved : 2;113 unsigned int prefetchable : 1;114 unsigned int cacheable : 1;115 unsigned int mask : 12;116 unsigned int type : 4;111 unsigned int addr : 12; 112 unsigned int reserved : 2; 113 unsigned int prefetchable : 1; 114 unsigned int cacheable : 1; 115 unsigned int mask : 12; 116 unsigned int type : 4; 117 117 } __attribute__((packed)) ambapp_bar_t; 118 118 119 119 typedef struct { 120 unsigned int vendor_id : 8;121 unsigned int device_id : 24;122 unsigned int reserved : 2;123 unsigned int version : 5;124 unsigned int irq : 5;120 unsigned int vendor_id : 8; 121 unsigned int device_id : 24; 122 unsigned int reserved : 2; 123 unsigned int version : 5; 124 unsigned int irq : 5; 125 125 uint32_t user_defined[3]; 126 126 ambapp_bar_t bar[4]; … … 128 128 129 129 typedef struct { 130 unsigned int ram_read_ws : 1;131 unsigned int ram_write_ws : 1;132 unsigned int ram_width : 2;133 unsigned int rmw : 1;134 unsigned int rbrdy : 1;130 unsigned int ram_read_ws : 1; 131 unsigned int ram_write_ws : 1; 132 unsigned int ram_width : 2; 133 unsigned int rmw : 1; 134 unsigned int rbrdy : 1; 135 135 unsigned int : 1; 136 unsigned int bank_size : 4;137 unsigned int si : 1;138 unsigned int se : 1;136 unsigned int bank_size : 4; 137 unsigned int si : 1; 138 unsigned int se : 1; 139 139 unsigned int : 1; 140 unsigned int ms : 1;140 unsigned int ms : 1; 141 141 unsigned int : 1; 142 unsigned int d64 : 1;143 unsigned int sdram_cmd : 2;144 unsigned int sdram_colsz : 2;145 unsigned int sdram_banksz : 3;146 unsigned int tcas : 1;147 unsigned int trfc : 3;148 unsigned int trp : 1;149 unsigned int sdrf : 1;142 unsigned int d64 : 1; 143 unsigned int sdram_cmd : 2; 144 unsigned int sdram_colsz : 2; 145 unsigned int sdram_banksz : 3; 146 unsigned int tcas : 1; 147 unsigned int trfc : 3; 148 unsigned int trp : 1; 149 unsigned int sdrf : 1; 150 150 } __attribute__((packed)) mctrl_mcfg2_t; 151 151 152 amba_device_t amba_devices[AMBAPP_MAX_DEVICES];153 int amba_devices_found;154 bool amba_fake;155 uintptr_t amba_uart_base;152 extern amba_device_t amba_devices[AMBAPP_MAX_DEVICES]; 153 extern int amba_devices_found; 154 extern bool amba_fake; 155 extern uintptr_t amba_uart_base; 156 156 157 void ambapp_scan(void);158 bool ambapp_fake(void);159 void ambapp_qemu_fake_scan(void);160 void ambapp_print_devices(void);161 amba_device_t *ambapp_lookup_first(amba_vendor_id_t, amba_device_id_t);157 extern void ambapp_scan(void); 158 extern bool ambapp_fake(void); 159 extern void ambapp_qemu_fake_scan(void); 160 extern void ambapp_print_devices(void); 161 extern amba_device_t *ambapp_lookup_first(amba_vendor_id_t, amba_device_id_t); 162 162 163 163 #endif -
boot/arch/sparc32/include/arch.h
re47ed05 rf6f22cdb 30 30 #define BOOT_sparc32_ARCH_H 31 31 32 #define PTL0_ENTRIES25633 #define PTL0_SHIFT2434 #define PTL0_SIZE(1 << 24)35 #define PTL0_ENTRY_SIZE432 #define PTL0_ENTRIES 256 33 #define PTL0_SHIFT 24 34 #define PTL0_SIZE (1 << 24) 35 #define PTL0_ENTRY_SIZE 4 36 36 37 37 /* ASI assignments: */ 38 #define ASI_CACHEMISS0x0139 #define ASI_CACHECTRL0x0240 #define ASI_MMUREGS0x1941 #define ASI_MMUBYPASS0x1c38 #define ASI_CACHEMISS 0x01 39 #define ASI_CACHECTRL 0x02 40 #define ASI_MMUREGS 0x19 41 #define ASI_MMUBYPASS 0x1c 42 42 43 43 /* 44 * Address where the boot stage image starts (beginning of usable physical45 * memory).44 * Address where the boot stage image starts 45 * (beginning of usable physical memory). 46 46 */ 47 #define BOOT_BASE 0x4000000048 #define BOOT_OFFSET (BOOT_BASE + 0xa00000)49 47 50 #define PA_OFFSET 0x40000000 48 #define BOOT_BASE 0x40000000 49 #define BOOT_OFFSET (BOOT_BASE + 0xa00000) 50 51 #define PA_OFFSET 0x40000000 51 52 52 53 #ifndef __ASM__ … … 56 57 #endif 57 58 58 59 59 #endif 60 60 -
boot/arch/sparc32/include/asm.h
re47ed05 rf6f22cdb 32 32 #include <typedefs.h> 33 33 34 static inline uint32_t asi_u32_read(int asi, uintptr_t va) 34 extern uintptr_t boot_ctx_table; 35 36 static inline uint32_t asi_u32_read(unsigned int asi, uintptr_t va) 35 37 { 36 38 uint32_t v; 37 39 38 40 asm volatile ( 39 41 "lda [%[va]] %[asi], %[v]\n" 40 42 : [v] "=r" (v) 41 43 : [va] "r" (va), 42 [asi] "i" ( (unsigned int)asi)44 [asi] "i" (asi) 43 45 ); 44 46 … … 46 48 } 47 49 48 static inline void asi_u32_write( int asi, uintptr_t va, uint32_t v)50 static inline void asi_u32_write(unsigned int asi, uintptr_t va, uint32_t v) 49 51 { 50 52 asm volatile ( … … 52 54 :: [v] "r" (v), 53 55 [va] "r" (va), 54 [asi] "i" ( (unsigned int)asi)56 [asi] "i" (asi) 55 57 : "memory" 56 58 ); 57 59 } 58 60 59 extern void jump_to_kernel(void * entry, bootinfo_t *bootinfo);61 extern void jump_to_kernel(void *, bootinfo_t *); 60 62 61 63 #endif -
boot/arch/sparc32/include/main.h
re47ed05 rf6f22cdb 35 35 36 36 #ifndef BOOT_sparc32_MAIN_H 37 #define BOOT_sparc 2_MAIN_H37 #define BOOT_sparc32_MAIN_H 38 38 39 39 /** Address where characters to be printed are expected. */ 40 #define APBUART_SCONS_THR0x8000010041 #define APBUART_SCONS_THR_MMU0xb000010040 #define APBUART_SCONS_THR 0x80000100 41 #define APBUART_SCONS_THR_MMU 0xb0000100 42 42 43 43 extern void bootstrap(void); -
boot/arch/sparc32/include/mm.h
re47ed05 rf6f22cdb 39 39 */ 40 40 41 #ifndef BOOT_sparc32_ _MM_H42 #define BOOT_sparc32_ _MM_H41 #ifndef BOOT_sparc32_MM_H 42 #define BOOT_sparc32_MM_H 43 43 44 44 #include <typedefs.h> 45 45 46 #define PAGE_SIZE(1 << 12)46 #define PAGE_SIZE (1 << 12) 47 47 48 48 typedef struct { … … 54 54 55 55 typedef struct { 56 unsigned int ppn : 24;57 unsigned int cacheable : 1;58 unsigned int modified : 1;59 unsigned int referenced : 1;60 unsigned int acc : 3;61 unsigned int et : 2;56 unsigned int ppn : 24; 57 unsigned int cacheable : 1; 58 unsigned int modified : 1; 59 unsigned int referenced : 1; 60 unsigned int acc : 3; 61 unsigned int et : 2; 62 62 } __attribute__((packed)) pte_t; 63 63 64 64 extern pte_t boot_pt[PTL0_ENTRIES]; 65 65 66 void mmu_init(void);66 extern void mmu_init(void); 67 67 68 #define PTE_ET_DESCRIPTOR169 #define PTE_ET_ENTRY270 #define PTE_ACC_RWX371 #define MMU_CONTROL_EN(1 << 0)68 #define PTE_ET_DESCRIPTOR 1 69 #define PTE_ET_ENTRY 2 70 #define PTE_ACC_RWX 3 71 #define MMU_CONTROL_EN (1 << 0) 72 72 73 73 #endif -
boot/arch/sparc32/src/ambapp.c
re47ed05 rf6f22cdb 50 50 #include <errno.h> 51 51 52 static void ambapp_scan_area(uintptr_t, int);52 static void ambapp_scan_area(uintptr_t, unsigned int); 53 53 54 54 void ambapp_scan() 55 55 { 56 56 amba_fake = false; 57 57 58 58 /* Scan for AHB masters & slaves */ 59 59 ambapp_scan_area(AMBAPP_AHBMASTER_AREA, 64); 60 60 ambapp_scan_area(AMBAPP_AHBSLAVE_AREA, 63); 61 61 62 62 /* Scan for APB slaves on APBMST */ 63 63 amba_device_t *apbmst = ambapp_lookup_first(GAISLER, GAISLER_APBMST); 64 64 if (apbmst != NULL) 65 65 ambapp_scan_area(apbmst->bars[0].start, 16); 66 66 67 67 /* If we found nothing, fake device entries */ 68 68 if (amba_devices_found == 0) … … 70 70 } 71 71 72 static void ambapp_scan_area(uintptr_t master_bar, int max_entries)72 static void ambapp_scan_area(uintptr_t master_bar, unsigned int max_entries) 73 73 { 74 74 ambapp_entry_t *entry = (ambapp_entry_t *) (master_bar | AMBAPP_CONF_AREA); 75 76 for ( int i = 0; i < max_entries; i++) {75 76 for (unsigned int i = 0; i < max_entries; i++) { 77 77 if (amba_devices_found == AMBAPP_MAX_DEVICES) 78 78 return; 79 79 80 80 if (entry->vendor_id == 0xff) 81 81 continue; 82 82 83 83 amba_device_t *device = &amba_devices[amba_devices_found]; 84 device->vendor_id = (amba_vendor_id_t) entry->vendor_id;85 device->device_id = (amba_device_id_t)entry->device_id;84 device->vendor_id = (amba_vendor_id_t) entry->vendor_id; 85 device->device_id = (amba_device_id_t) entry->device_id; 86 86 device->version = entry->version; 87 87 device->irq = entry->irq; 88 89 for ( int bar = 0; bar < 4; bar++) {88 89 for (unsigned int bar = 0; bar < 4; bar++) { 90 90 device->bars[bar].start = entry->bar[bar].addr << 20; 91 91 device->bars[bar].size = entry->bar[bar].mask; 92 device->bars[bar].prefetchable = (bool) entry->bar[bar].prefetchable;93 device->bars[bar].cacheable = (bool) entry->bar[bar].cacheable;92 device->bars[bar].prefetchable = (bool) entry->bar[bar].prefetchable; 93 device->bars[bar].cacheable = (bool) entry->bar[bar].cacheable; 94 94 } 95 95 96 96 amba_devices_found++; 97 97 } … … 107 107 amba_devices[0].bars[0].start = 0x80000100; 108 108 amba_devices[0].bars[0].size = 0x100; 109 109 110 110 /* IRQMP */ 111 111 amba_devices[1].vendor_id = GAISLER; … … 115 115 amba_devices[1].bars[0].start = 0x80000200; 116 116 amba_devices[1].bars[0].size = 0x100; 117 117 118 118 /* GPTIMER */ 119 119 amba_devices[2].vendor_id = GAISLER; … … 123 123 amba_devices[2].bars[0].start = 0x80000300; 124 124 amba_devices[2].bars[0].size = 0x100; 125 125 126 126 amba_fake = true; 127 127 amba_devices_found = 3; … … 136 136 { 137 137 printf("ABMA devices:\n"); 138 139 for ( int i = 0; i < amba_devices_found; i++) {138 139 for (unsigned int i = 0; i < amba_devices_found; i++) { 140 140 amba_device_t *dev = &amba_devices[i]; 141 printf("<%1x:%03x> at 0x%08x ", dev->vendor_id, dev->device_id, dev->bars[0].start); 141 142 printf("<%1x:%03x> at 0x%08x ", dev->vendor_id, dev->device_id, 143 dev->bars[0].start); 144 142 145 if (dev->irq == -1) 143 146 printf("\n"); … … 147 150 } 148 151 149 amba_device_t *ambapp_lookup_first(amba_vendor_id_t vendor, amba_device_id_t device) 152 amba_device_t *ambapp_lookup_first(amba_vendor_id_t vendor, 153 amba_device_id_t device) 150 154 { 151 for ( int i = 0; i < amba_devices_found; i++) {152 if ( amba_devices[i].vendor_id == vendor&&153 amba_devices[i].device_id == device)155 for (unsigned int i = 0; i < amba_devices_found; i++) { 156 if ((amba_devices[i].vendor_id == vendor) && 157 (amba_devices[i].device_id == device)) 154 158 return &amba_devices[i]; 155 159 } 156 160 157 161 return NULL; 158 162 } -
boot/arch/sparc32/src/main.c
re47ed05 rf6f22cdb 52 52 53 53 #define TOP2ADDR(top) (((void *) PA2KA(BOOT_OFFSET)) + (top)) 54 54 55 static bootinfo_t bootinfo; 55 56 … … 58 59 /* Initialize AMBA P&P device list */ 59 60 ambapp_scan(); 60 61 /* Look upfor UART */61 62 /* Look for UART */ 62 63 amba_device_t *uart = ambapp_lookup_first(GAISLER, GAISLER_APBUART); 63 64 amba_uart_base = uart->bars[0].start; 64 65 bootinfo.uart_base = amba_uart_base; 65 66 bootinfo.uart_irq = uart->irq; 66 67 /* Look upfor IRQMP */67 68 /* Look for IRQMP */ 68 69 amba_device_t *irqmp = ambapp_lookup_first(GAISLER, GAISLER_IRQMP); 69 70 bootinfo.intc_base = irqmp->bars[0].start; 70 71 /* Look upfor timer */71 72 /* Look for timer */ 72 73 amba_device_t *timer = ambapp_lookup_first(GAISLER, GAISLER_GPTIMER); 73 74 bootinfo.timer_base = timer->bars[0].start; 74 75 bootinfo.timer_irq = timer->irq; 75 76 76 /* Lookp up for memory controller and obtain memory size */ 77 if (ambapp_fake()) { 78 bootinfo.memsize = 64 * 1024 * 1024; // 64MB 79 } else { 77 /* Look for memory controller and obtain memory size */ 78 if (!ambapp_fake()) { 80 79 amba_device_t *mctrl = ambapp_lookup_first(ESA, ESA_MCTRL); 81 volatile mctrl_mcfg2_t *mcfg2 = (volatile mctrl_mcfg2_t *)(mctrl->bars[0].start + 0x4); 80 volatile mctrl_mcfg2_t *mcfg2 = (volatile mctrl_mcfg2_t *) 81 (mctrl->bars[0].start + 0x4); 82 82 bootinfo.memsize = (1 << (13 + mcfg2->bank_size)); 83 } 83 } else 84 bootinfo.memsize = 64 * 1024 * 1024; 84 85 85 86 /* Standard output is now initialized */ 86 87 version_print(); 87 88 88 89 for (size_t i = 0; i < COMPONENTS; i++) { 89 90 printf(" %p|%p: %s image (%u/%u bytes)\n", components[i].start, … … 91 92 components[i].size); 92 93 } 93 94 94 95 ambapp_print_devices(); 95 96 printf("Memory size: % dMB\n", bootinfo.memsize >> 20);97 96 97 printf("Memory size: %u MB\n", bootinfo.memsize >> 20); 98 98 99 mmu_init(); 99 100 100 101 void *dest[COMPONENTS]; 101 102 size_t top = 0; … … 116 117 117 118 dest[i] = TOP2ADDR(top); 118 119 119 120 top += components[i].inflated; 120 121 cnt++; … … 128 129 printf("\n%s: Image too large to fit (%p >= %p), halting.\n", 129 130 components[i].name, tail, dest[i - 1]); 130 for (;;);131 halt(); 131 132 } 132 133 … … 137 138 if (err != EOK) { 138 139 printf("\n%s: Inflating error %d\n", components[i - 1].name, err); 139 for (;;);140 halt(); 140 141 } 141 142 } 142 143 143 144 printf("Booting the kernel ... \n"); 144 145 jump_to_kernel((void *) PA2KA(BOOT_OFFSET), &bootinfo); -
boot/arch/sparc32/src/mm.c
re47ed05 rf6f22cdb 50 50 #include <inflate.h> 51 51 52 #define OFF2SEC(_addr)((_addr) >> PTL0_SHIFT)53 #define SEC2OFF(_sec)((_sec) << PTL0_SHIFT)52 #define OFF2SEC(_addr) ((_addr) >> PTL0_SHIFT) 53 #define SEC2OFF(_sec) ((_sec) << PTL0_SHIFT) 54 54 55 55 static section_mapping_t mappings[] = { … … 60 60 }; 61 61 62 extern uintptr_t boot_ctx_table; 63 64 static void mmu_enable() 62 static void mmu_enable(void) 65 63 { 66 boot_ctx_table = ((uintptr_t) &boot_pt[0] >> 4) | PTE_ET_DESCRIPTOR;67 64 boot_ctx_table = ((uintptr_t) &boot_pt[0] >> 4) | PTE_ET_DESCRIPTOR; 65 68 66 /* Set Context Table Pointer register */ 69 asi_u32_write(ASI_MMUREGS, 0x100, ((uint32_t) &boot_ctx_table) >> 4);70 67 asi_u32_write(ASI_MMUREGS, 0x100, ((uint32_t) &boot_ctx_table) >> 4); 68 71 69 /* Select context 0 */ 72 70 asi_u32_write(ASI_MMUREGS, 0x200, 0); 73 71 74 72 /* Enable MMU */ 75 73 uint32_t cr = asi_u32_read(ASI_MMUREGS, 0x000); … … 85 83 } 86 84 87 void mmu_init( )85 void mmu_init(void) 88 86 { 89 87 mmu_disable(); 90 91 for ( int i = 0; mappings[i].size != 0; i++) {92 int ptr = 0;93 for (uint32_t sec = OFF2SEC(mappings[i].va); 94 95 88 89 for (unsigned int i = 0; mappings[i].size != 0; i++) { 90 unsigned int ptr = 0; 91 for (uint32_t sec = OFF2SEC(mappings[i].va); 92 sec < OFF2SEC(mappings[i].va + mappings[i].size); 93 sec++) { 96 94 boot_pt[sec].ppn = ((mappings[i].pa + SEC2OFF(ptr++)) >> 12) & 0xffffff; 97 95 boot_pt[sec].cacheable = mappings[i].cacheable; … … 100 98 } 101 99 } 102 100 103 101 mmu_enable(); 104 102 } -
boot/arch/sparc32/src/putchar.c
re47ed05 rf6f22cdb 47 47 /** Send a byte to the LEON3 serial console. 48 48 * 49 * @param byte Byte to send. 49 * @param byte Byte to send. 50 * 50 51 */ 51 52 static void scons_sendb(uint8_t byte) … … 56 57 /** Display a character 57 58 * 58 * @param ch Character to display 59 * @param ch Character to display 60 * 59 61 */ 60 62 void putchar(const wchar_t ch) … … 62 64 if (ch == '\n') 63 65 scons_sendb('\r'); 64 66 65 67 if (ascii_check(ch)) 66 68 scons_sendb((uint8_t) ch);
Note:
See TracChangeset
for help on using the changeset viewer.