Changeset 1f12fab in mainline
- Timestamp:
- 2013-10-07T20:00:34Z (11 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a73ebf0
- Parents:
- 80d9d83
- Files:
-
- 1 added
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/arch/sparc32/include/arch/arch.h
r80d9d83 r1f12fab 41 41 #include <typedefs.h> 42 42 43 #define NWINDOWS 8 44 43 45 /* ASI assignments: */ 44 46 #define ASI_CACHEMISS 0x01 … … 63 65 } bootinfo_t; 64 66 65 void arch_pre_main(bootinfo_t *bootinfo); 67 extern uintptr_t kernel_sp; 68 extern uintptr_t uspace_wbuf; 69 70 extern void arch_pre_main(void *unused, bootinfo_t *bootinfo); 66 71 67 72 #endif -
kernel/arch/sparc32/include/arch/elf.h
r80d9d83 r1f12fab 27 27 */ 28 28 29 /** @addtogroup abs32le29 /** @addtogroup sparc32 30 30 * @{ 31 31 */ … … 33 33 */ 34 34 35 #ifndef KERN_ abs32le_ELF_H_36 #define KERN_ abs32le_ELF_H_35 #ifndef KERN_sparc32_ELF_H_ 36 #define KERN_sparc32_ELF_H_ 37 37 38 #define ELF_MACHINE EM_ NO39 #define ELF_DATA_ENCODING ELFDATA2 LSB38 #define ELF_MACHINE EM_SPARC 39 #define ELF_DATA_ENCODING ELFDATA2MSB 40 40 #define ELF_CLASS ELFCLASS32 41 41 -
kernel/arch/sparc32/include/arch/istate.h
r80d9d83 r1f12fab 27 27 */ 28 28 29 /** @addtogroup abs32leinterrupt29 /** @addtogroup sparc32interrupt 30 30 * @{ 31 31 */ … … 33 33 */ 34 34 35 #ifndef KERN_ abs32le_ISTATE_H_36 #define KERN_ abs32le_ISTATE_H_35 #ifndef KERN_sparc32_ISTATE_H_ 36 #define KERN_sparc32_ISTATE_H_ 37 37 38 38 #include <trace.h> … … 54 54 */ 55 55 typedef struct istate { 56 uintptr_t ip; 57 uintptr_t fp; 56 uintptr_t pstate; 57 uintptr_t pc; 58 uintptr_t npc; 58 59 uint32_t stack[]; 59 60 } istate_t; … … 64 65 /* On real hardware this checks whether the interrupted 65 66 context originated from user space. */ 66 67 return !(istate-> ip& UINT32_C(0x80000000));67 68 return !(istate->pc & UINT32_C(0x80000000)); 68 69 } 69 70 … … 74 75 /* On real hardware this sets the instruction pointer. */ 75 76 76 istate-> ip= retaddr;77 istate->pc = retaddr; 77 78 } 78 79 … … 82 83 /* On real hardware this returns the instruction pointer. */ 83 84 84 return istate-> ip;85 return istate->pc; 85 86 } 86 87 … … 90 91 /* On real hardware this returns the frame pointer. */ 91 92 92 return istate->fp;93 return 0;//istate->fp; 93 94 } 94 95 -
kernel/arch/sparc32/include/arch/mm/tlb.h
r80d9d83 r1f12fab 1 1 /* 2 * Copyright (c) 201 0 Martin Decky2 * Copyright (c) 2013 Jakub Klama 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 /** @addtogroup abs32lemm29 /** @addtogroup sparc32mm 30 30 * @{ 31 31 */ … … 33 33 */ 34 34 35 #ifndef KERN_abs32le_TLB_H_ 36 #define KERN_abs32le_TLB_H_ 35 #ifndef KERN_sparc32_TLB_H_ 36 #define KERN_sparc32_TLB_H_ 37 38 #define MMU_CONTROL 0x000 39 #define MMU_CONTEXT_TABLE 0x100 40 #define MMU_CONTEXT 0x200 41 #define MMU_FAULT_STATUS 0x300 42 #define MMU_FAULT_ADDRESS 0x400 37 43 38 44 #endif -
kernel/arch/sparc32/include/arch/proc/thread.h
r80d9d83 r1f12fab 1 1 /* 2 * Copyright (c) 201 0 Martin Decky2 * Copyright (c) 2013 Jakub Klama 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 /** @addtogroup abs32leproc29 /** @addtogroup sparc32proc 30 30 * @{ 31 31 */ … … 33 33 */ 34 34 35 #ifndef KERN_ abs32le_THREAD_H_36 #define KERN_ abs32le_THREAD_H_35 #ifndef KERN_sparc32_THREAD_H_ 36 #define KERN_sparc32_THREAD_H_ 37 37 38 38 #include <typedefs.h> 39 39 40 40 typedef struct { 41 /** Buffer for register windows with userspace content. */ 42 uint8_t *uspace_window_buffer; 41 43 } thread_arch_t; 42 43 #define thr_constructor_arch(thr)44 #define thr_destructor_arch(thr)45 44 46 45 #endif -
kernel/arch/sparc32/src/exception.c
r80d9d83 r1f12fab 48 48 void instruction_access_exception(int n, istate_t *istate) 49 49 { 50 fault_if_from_uspace(istate, "%s.", __func__); 51 panic_badtrap(istate, n, "%s.", __func__); 50 page_fault(n, istate); 51 // fault_if_from_uspace(istate, "%s.", __func__); 52 // panic_badtrap(istate, n, "%s.", __func__); 52 53 } 53 54 … … 104 105 void data_access_exception(int n, istate_t *istate) 105 106 { 106 fault_if_from_uspace(istate, "%s.", __func__); 107 panic_badtrap(istate, n, "%s.", __func__); 107 page_fault(n, istate); 108 // fault_if_from_uspace(istate, "%s.", __func__); 109 // panic_badtrap(istate, n, "%s.", __func__); 108 110 } 109 111 … … 111 113 void data_access_error(int n, istate_t *istate) 112 114 { 113 fault_if_from_uspace(istate, "%s.", __func__); 114 panic_badtrap(istate, n, "%s.", __func__); 115 page_fault(n, istate); 116 // fault_if_from_uspace(istate, "%s.", __func__); 117 // panic_badtrap(istate, n, "%s.", __func__); 115 118 } 116 119 … … 118 121 void data_store_error(int n, istate_t *istate) 119 122 { 120 fault_if_from_uspace(istate, "%s.", __func__); 121 panic_badtrap(istate, n, "%s.", __func__); 123 page_fault(n, istate); 124 // fault_if_from_uspace(istate, "%s.", __func__); 125 // panic_badtrap(istate, n, "%s.", __func__); 122 126 } 123 127 /** Handle data_access_error. (0x2c) */ -
kernel/arch/sparc32/src/mm/frame.c
r80d9d83 r1f12fab 60 60 BOOT_PT_START_FRAME + BOOT_PT_SIZE_FRAMES, 61 61 ZONE_AVAILABLE | ZONE_LOWMEM); 62 63 printf("low_zone: %d frames\n", SIZE2FRAMES(size)); 62 64 } else { 63 65 pfn_t conf = zone_external_conf_alloc(SIZE2FRAMES(size)); … … 65 67 zone_create(ADDR2PFN(base), SIZE2FRAMES(size), conf, 66 68 ZONE_AVAILABLE | ZONE_HIGHMEM); 69 70 printf("high zone: %d frames\n", SIZE2FRAMES(size)); 67 71 } 68 72 73 printf("free: %d\n", frame_total_free_get()); 69 74 } 70 75 … … 81 86 /* blacklist boot page table */ 82 87 frame_mark_unavailable(BOOT_PT_START_FRAME, BOOT_PT_SIZE_FRAMES); 88 printf("free: %d\n", frame_total_free_get()); 83 89 //machine_frame_init(); 84 90 } -
kernel/arch/sparc32/src/mm/page.c
r80d9d83 r1f12fab 34 34 35 35 #include <arch/mm/page.h> 36 #include <arch/mm/page_fault.h> 37 #include <arch/mm/tlb.h> 36 38 #include <genarch/mm/page_pt.h> 37 39 #include <arch/mm/frame.h> … … 75 77 76 78 /* Switch MMU to new context table */ 77 asi_u32_write(ASI_MMUREGS, 0x100, KA2PA(as_context_table) >> 4);79 asi_u32_write(ASI_MMUREGS, MMU_CONTEXT_TABLE, KA2PA(as_context_table) >> 4); 78 80 79 81 //boot_page_table_free(); … … 82 84 void page_fault(unsigned int n __attribute__((unused)), istate_t *istate) 83 85 { 86 uint32_t fault_status = asi_u32_read(ASI_MMUREGS, MMU_FAULT_STATUS); 87 uintptr_t fault_address = asi_u32_read(ASI_MMUREGS, MMU_FAULT_ADDRESS); 88 mmu_fault_status_t *fault = (mmu_fault_status_t *)&fault_status; 89 mmu_fault_type_t type = (mmu_fault_type_t)fault->ft; 90 91 printf("page fault on address 0x%08x, status 0x%08x\n", fault_address, fault_status); 92 93 if (type == FAULT_TYPE_LOAD_USER_DATA) 94 as_page_fault(fault_address, PF_ACCESS_READ, istate); 95 96 if (type == FAULT_TYPE_EXECUTE_USER) 97 as_page_fault(fault_address, PF_ACCESS_EXEC, istate); 98 99 if (type == FAULT_TYPE_STORE_USER_DATA || type == FAULT_TYPE_STORE_USER_INSTRUCTION) 100 as_page_fault(fault_address, PF_ACCESS_WRITE, istate); 84 101 } 85 102 -
kernel/arch/sparc32/src/proc/scheduler.c
r80d9d83 r1f12fab 1 1 /* 2 * Copyright (c) 201 0 Martin Decky2 * Copyright (c) 2013 Jakub Klama 3 3 * All rights reserved. 4 4 * … … 34 34 35 35 #include <proc/scheduler.h> 36 #include <proc/thread.h> 37 #include <arch.h> 38 #include <arch/arch.h> 36 39 37 40 void before_task_runs_arch(void) … … 41 44 void before_thread_runs_arch(void) 42 45 { 46 kernel_sp = (uintptr_t) THREAD->kstack + STACK_SIZE; 47 uspace_wbuf = (uintptr_t) THREAD->arch.uspace_window_buffer; 43 48 } 44 49 -
kernel/arch/sparc32/src/proc/thread.c
r80d9d83 r1f12fab 33 33 */ 34 34 35 #include <arch/regwin.h> 35 36 #include <proc/thread.h> 37 38 void thr_constructor_arch(thread_t *t) 39 { 40 t->arch.uspace_window_buffer = NULL; 41 } 42 43 void thr_destructor_arch(thread_t *t) 44 { 45 if (t->arch.uspace_window_buffer) { 46 uintptr_t uw_buf = (uintptr_t) t->arch.uspace_window_buffer; 47 /* 48 * Mind the possible alignment of the userspace window buffer 49 * belonging to a killed thread. 50 */ 51 free((uint8_t *) ALIGN_DOWN(uw_buf, UWB_ALIGNMENT)); 52 } 53 } 36 54 37 55 void thread_create_arch(thread_t *t) 38 56 { 57 if ((t->uspace) && (!t->arch.uspace_window_buffer)) 58 { 59 /* 60 * The thread needs userspace window buffer and the object 61 * returned from the slab allocator doesn't have any. 62 */ 63 t->arch.uspace_window_buffer = malloc(UWB_ASIZE, 0); 64 } else { 65 uintptr_t uw_buf = (uintptr_t) t->arch.uspace_window_buffer; 66 67 /* 68 * Mind the possible alignment of the userspace window buffer 69 * belonging to a killed thread. 70 */ 71 t->arch.uspace_window_buffer = (uint8_t *) ALIGN_DOWN(uw_buf, 72 UWB_ASIZE); 73 } 39 74 } 40 75 -
kernel/arch/sparc32/src/sparc32.c
r80d9d83 r1f12fab 56 56 char memcpy_to_uspace_failover_address; 57 57 58 void arch_pre_main( bootinfo_t *bootinfo)58 void arch_pre_main(void *unused, bootinfo_t *bootinfo) 59 59 { 60 60 init.cnt = min3(bootinfo->cnt, TASKMAP_MAX_RECORDS, CONFIG_INIT_TASKS); -
kernel/arch/sparc32/src/start.S
r80d9d83 r1f12fab 31 31 .global kernel_image_start 32 32 .global early_putchar 33 .global kernel_sp 34 .global uspace_wbuf 33 35 34 36 kernel_image_start: … … 68 70 nop 69 71 72 kernel_sp: 73 .space 4 74 75 uspace_wbuf: 76 .space 4 77 70 78 .align 16 71 79 .space 4096 -
kernel/arch/sparc32/src/trap_table.S
r80d9d83 r1f12fab 33 33 .global trap_table 34 34 .global reset_trap 35 .global preemptible_trap 35 36 .global window_overflow_trap 36 37 .global window_underflow_trap … … 116 117 rett %l2 117 118 118 #define TRAP(_vector, _handler) \ 119 preemptible_trap: 120 /* Enable traps */ 121 mov %psr, %l0 122 or %l0, (1 << 5), %l0 123 mov %l0, %psr 124 125 /* Check whether previous mode was usermode */ 126 and %l0, (1 << 6), %l0 127 cmp %l0, 0 128 bne 1f 129 nop 130 131 /* Set up stack */ 132 set kernel_sp, %l4 133 ld [%l4], %sp 134 mov %sp, %fp 135 1: sub %sp, 112, %sp 136 137 /* Save trap data on stack */ 138 st %l1, [%fp - 4] 139 st %l2, [%fp - 8] 140 st %l0, [%fp - 12] 141 142 /* Jump to actual subroutine */ 143 mov 1, %o0 144 jmp %g1 145 sub %fp, 12, %o1 146 147 /* Return from handler */ 148 ld [%fp - 4], %l1 149 ld [%fp - 8], %l2 150 jmp %l1 151 rett %l2 152 153 #define STRAP(_vector, _handler) \ 119 154 .org trap_table + _vector * TRAP_ENTRY_SIZE; \ 120 155 mov %psr, %l0 ; \ 121 156 sethi %hi(_handler), %l4 ; \ 122 jmp %l4 + %lo(_handler); \ 123 mov _vector, %l3 ; 157 jmp %lo(_handler) + %l4 ; \ 158 nop 159 160 #define TRAP(_vector, _handler) \ 161 .org trap_table + _vector * TRAP_ENTRY_SIZE; \ 162 sethi %hi(_handler), %g1 ; \ 163 b preemptible_trap ; \ 164 or %g1, %lo(_handler), %g1 ; 124 165 125 166 #define INTERRUPT(_vector, _priority) \ … … 141 182 TRAP(0x3, privileged_instruction) 142 183 TRAP(0x4, fp_disabled) 143 TRAP(0x5, window_overflow_trap)144 TRAP(0x6, window_underflow_trap)184 STRAP(0x5, window_overflow_trap) 185 STRAP(0x6, window_underflow_trap) 145 186 TRAP(0x7, mem_address_not_aligned) 146 187 TRAP(0x8, fp_exception) -
kernel/arch/sparc32/src/userspace.c
r80d9d83 r1f12fab 36 36 #include <typedefs.h> 37 37 #include <arch.h> 38 #include <arch/asm.h> 38 39 #include <abi/proc/uarg.h> 39 40 #include <mm/as.h> … … 41 42 void userspace(uspace_arg_t *kernel_uarg) 42 43 { 44 printf("userspace(): entry=%p, stack=%p, stacksize=%d\n", kernel_uarg->uspace_entry, kernel_uarg->uspace_stack, kernel_uarg->uspace_stack_size); 43 45 /* On real hardware this switches the CPU to user 44 46 space mode and jumps to kernel_uarg->uspace_entry. */ 45 47 48 uint32_t psr = psr_read(); 49 50 psr &= ~(1 << 7); 51 psr &= ~(1 << 6); 52 53 asm volatile ( 54 "mov %[stack], %%sp\n" 55 "mov %[psr], %%psr\n" 56 "nop\n" 57 "jmp %[entry]\n" 58 "nop\n" :: [entry] "r" (kernel_uarg->uspace_entry), 59 [psr] "r" (psr), 60 [stack] "r" (kernel_uarg->uspace_stack + kernel_uarg->uspace_stack_size)); 61 46 62 while (true); 47 63 } -
uspace/lib/c/arch/sparc32/src/entry.s
r80d9d83 r1f12fab 44 44 save %sp, -176, %sp 45 45 # XXX flushw 46 add %g0, -0x7ff, %fp 46 # add %g0, -0x7ff, %fp 47 set 0x80000000, %fp 47 48 48 49 # Pass pcb_ptr as the first argument to __main()
Note:
See TracChangeset
for help on using the changeset viewer.