Changeset cefb126 in mainline for kernel/arch
- Timestamp:
- 2010-07-02T14:19:30Z (16 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 89c57b6
- Parents:
- fe7abd0 (diff), e3ee9b9 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- kernel/arch
- Files:
-
- 1 added
- 4 deleted
- 103 edited
-
abs32le/include/atomic.h (modified) (5 diffs)
-
abs32le/include/interrupt.h (modified) (5 diffs)
-
abs32le/include/mm/page.h (modified) (1 diff)
-
abs32le/include/types.h (modified) (1 diff)
-
abs32le/src/abs32le.c (modified) (2 diffs)
-
amd64/Makefile.inc (modified) (2 diffs)
-
amd64/_link.ld.in (modified) (4 diffs)
-
amd64/include/arch.h (modified) (1 diff)
-
amd64/include/boot/boot.h (modified) (2 diffs)
-
amd64/include/context.h (modified) (1 diff)
-
amd64/include/elf.h (modified) (2 diffs)
-
amd64/include/faddr.h (modified) (2 diffs)
-
amd64/include/interrupt.h (modified) (1 diff)
-
amd64/include/mm/as.h (modified) (2 diffs)
-
amd64/include/mm/page.h (modified) (5 diffs)
-
amd64/include/mm/ptl.h (modified) (2 diffs)
-
amd64/include/mm/tlb.h (modified) (1 diff)
-
amd64/include/pm.h (modified) (1 diff)
-
amd64/include/proc/thread.h (modified) (1 diff)
-
amd64/include/types.h (modified) (1 diff)
-
amd64/src/amd64.c (modified) (3 diffs)
-
amd64/src/asm.S (added)
-
amd64/src/asm_utils.S (deleted)
-
amd64/src/boot/boot.S (modified) (19 diffs)
-
amd64/src/boot/vesa_ret.inc (modified) (2 diffs)
-
amd64/src/context.S (modified) (2 diffs)
-
amd64/src/cpu/cpu.c (modified) (2 diffs)
-
amd64/src/debug/stacktrace.c (modified) (3 diffs)
-
amd64/src/debugger.c (modified) (4 diffs)
-
amd64/src/delay.S (modified) (1 diff)
-
amd64/src/fpu_context.c (modified) (1 diff)
-
amd64/src/interrupt.c (modified) (6 diffs)
-
amd64/src/mm/page.c (modified) (4 diffs)
-
amd64/src/proc/scheduler.c (modified) (2 diffs)
-
amd64/src/proc/task.c (modified) (1 diff)
-
amd64/src/proc/thread.c (modified) (1 diff)
-
amd64/src/smp/ap.S (modified) (4 diffs)
-
arm32/Makefile.inc (modified) (1 diff)
-
arm32/include/exception.h (modified) (2 diffs)
-
arm32/include/mach/integratorcp/integratorcp.h (modified) (2 diffs)
-
arm32/include/mach/testarm/testarm.h (modified) (2 diffs)
-
arm32/include/machine_func.h (modified) (3 diffs)
-
arm32/src/arm32.c (modified) (2 diffs)
-
arm32/src/asm.S (modified) (3 diffs)
-
arm32/src/exc_handler.S (modified) (2 diffs)
-
arm32/src/exception.c (modified) (3 diffs)
-
arm32/src/interrupt.c (modified) (1 diff)
-
arm32/src/mach/integratorcp/integratorcp.c (modified) (1 diff)
-
arm32/src/mach/testarm/testarm.c (modified) (1 diff)
-
arm32/src/machine_func.c (modified) (8 diffs)
-
arm32/src/mm/frame.c (modified) (1 diff)
-
arm32/src/mm/page.c (modified) (1 diff)
-
arm32/src/mm/page_fault.c (modified) (2 diffs)
-
ia32/Makefile.inc (modified) (1 diff)
-
ia32/include/bios/bios.h (modified) (2 diffs)
-
ia32/include/drivers/i8259.h (modified) (1 diff)
-
ia32/include/fpu_context.h (modified) (2 diffs)
-
ia32/include/interrupt.h (modified) (3 diffs)
-
ia32/include/mm/asid.h (modified) (2 diffs)
-
ia32/include/smp/apic.h (modified) (2 diffs)
-
ia32/include/smp/mps.h (modified) (6 diffs)
-
ia32/include/smp/smp.h (modified) (2 diffs)
-
ia32/src/asm.S (modified) (9 diffs)
-
ia32/src/bios/bios.c (modified) (1 diff)
-
ia32/src/boot/boot.S (modified) (15 diffs)
-
ia32/src/boot/vesa_prot.inc (modified) (7 diffs)
-
ia32/src/boot/vesa_real.inc (modified) (19 diffs)
-
ia32/src/boot/vesa_ret.inc (modified) (1 diff)
-
ia32/src/ia32.c (modified) (1 diff)
-
ia32/src/interrupt.c (modified) (7 diffs)
-
ia32/src/mm/as.c (modified) (1 diff)
-
ia32/src/mm/frame.c (modified) (7 diffs)
-
ia32/src/mm/page.c (modified) (1 diff)
-
ia32/src/mm/tlb.c (modified) (1 diff)
-
ia32/src/smp/apic.c (modified) (4 diffs)
-
ia32/src/smp/mps.c (modified) (7 diffs)
-
ia32/src/smp/smp.c (modified) (8 diffs)
-
ia64/src/asm.S (modified) (8 diffs)
-
ia64/src/interrupt.c (modified) (4 diffs)
-
ia64/src/mm/tlb.c (modified) (7 diffs)
-
mips32/Makefile.inc (modified) (1 diff)
-
mips32/src/asm.S (modified) (8 diffs)
-
mips32/src/debugger.c (modified) (2 diffs)
-
mips32/src/exception.c (modified) (4 diffs)
-
mips32/src/mm/frame.c (modified) (1 diff)
-
mips32/src/mm/tlb.c (modified) (4 diffs)
-
mips32/src/panic.S (deleted)
-
ppc32/Makefile.inc (modified) (1 diff)
-
ppc32/include/interrupt.h (modified) (1 diff)
-
ppc32/include/mm/tlb.h (modified) (1 diff)
-
ppc32/include/types.h (modified) (1 diff)
-
ppc32/src/asm.S (modified) (7 diffs)
-
ppc32/src/debug/panic.s (deleted)
-
ppc32/src/interrupt.c (modified) (2 diffs)
-
ppc32/src/mm/frame.c (modified) (2 diffs)
-
ppc32/src/mm/tlb.c (modified) (4 diffs)
-
sparc64/Makefile.inc (modified) (1 diff)
-
sparc64/include/drivers/tick.h (modified) (2 diffs)
-
sparc64/include/types.h (modified) (1 diff)
-
sparc64/src/asm.S (modified) (7 diffs)
-
sparc64/src/drivers/tick.c (modified) (2 diffs)
-
sparc64/src/mm/sun4u/frame.c (modified) (2 diffs)
-
sparc64/src/mm/sun4u/tlb.c (modified) (7 diffs)
-
sparc64/src/mm/sun4v/frame.c (modified) (1 diff)
-
sparc64/src/mm/sun4v/tlb.c (modified) (6 diffs)
-
sparc64/src/panic.S (deleted)
-
sparc64/src/trap/exception.c (modified) (20 diffs)
-
sparc64/src/trap/sun4v/interrupt.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
kernel/arch/abs32le/include/atomic.h
rfe7abd0 rcefb126 39 39 #include <arch/barrier.h> 40 40 #include <preemption.h> 41 #include <verify.h> 41 42 42 static inline void atomic_inc(atomic_t *val) { 43 ATOMIC static inline void atomic_inc(atomic_t *val) 44 WRITES(&val->count) 45 REQUIRES_EXTENT_MUTABLE(val) 46 REQUIRES(val->count < ATOMIC_COUNT_MAX) 47 { 43 48 /* On real hardware the increment has to be done 44 49 as an atomic action. */ … … 47 52 } 48 53 49 static inline void atomic_dec(atomic_t *val) { 54 ATOMIC static inline void atomic_dec(atomic_t *val) 55 WRITES(&val->count) 56 REQUIRES_EXTENT_MUTABLE(val) 57 REQUIRES(val->count > ATOMIC_COUNT_MIN) 58 { 50 59 /* On real hardware the decrement has to be done 51 60 as an atomic action. */ 52 61 53 val->count ++;62 val->count--; 54 63 } 55 64 56 static inline atomic_count_t atomic_postinc(atomic_t *val) 65 ATOMIC static inline atomic_count_t atomic_postinc(atomic_t *val) 66 WRITES(&val->count) 67 REQUIRES_EXTENT_MUTABLE(val) 68 REQUIRES(val->count < ATOMIC_COUNT_MAX) 57 69 { 58 70 /* On real hardware both the storing of the previous … … 66 78 } 67 79 68 static inline atomic_count_t atomic_postdec(atomic_t *val) 80 ATOMIC static inline atomic_count_t atomic_postdec(atomic_t *val) 81 WRITES(&val->count) 82 REQUIRES_EXTENT_MUTABLE(val) 83 REQUIRES(val->count > ATOMIC_COUNT_MIN) 69 84 { 70 85 /* On real hardware both the storing of the previous … … 81 96 #define atomic_predec(val) (atomic_postdec(val) - 1) 82 97 83 static inline atomic_count_t test_and_set(atomic_t *val) 98 ATOMIC static inline atomic_count_t test_and_set(atomic_t *val) 99 WRITES(&val->count) 100 REQUIRES_EXTENT_MUTABLE(val) 84 101 { 102 /* On real hardware the retrieving of the original 103 value and storing 1 have to be done as a single 104 atomic action. */ 105 85 106 atomic_count_t prev = val->count; 86 107 val->count = 1; … … 89 110 90 111 static inline void atomic_lock_arch(atomic_t *val) 112 WRITES(&val->count) 113 REQUIRES_EXTENT_MUTABLE(val) 91 114 { 92 115 do { -
kernel/arch/abs32le/include/interrupt.h
rfe7abd0 rcefb126 37 37 38 38 #include <typedefs.h> 39 #include <verify.h> 39 40 40 41 #define IVT_ITEMS 0 … … 54 55 55 56 static inline int istate_from_uspace(istate_t *istate) 57 REQUIRES_EXTENT_MUTABLE(istate) 56 58 { 57 59 /* On real hardware this checks whether the interrupted … … 62 64 63 65 static inline void istate_set_retaddr(istate_t *istate, uintptr_t retaddr) 66 WRITES(&istate->ip) 64 67 { 65 68 /* On real hardware this sets the instruction pointer. */ … … 69 72 70 73 static inline unative_t istate_get_pc(istate_t *istate) 74 REQUIRES_EXTENT_MUTABLE(istate) 71 75 { 72 76 /* On real hardware this returns the instruction pointer. */ … … 76 80 77 81 static inline unative_t istate_get_fp(istate_t *istate) 82 REQUIRES_EXTENT_MUTABLE(istate) 78 83 { 79 84 /* On real hardware this returns the frame pointer. */ -
kernel/arch/abs32le/include/mm/page.h
rfe7abd0 rcefb126 140 140 141 141 static inline unsigned int get_pt_flags(pte_t *pt, size_t i) 142 REQUIRES_ARRAY_MUTABLE(pt, PTL0_ENTRIES_ARCH) 142 143 { 143 144 pte_t *p = &pt[i]; 144 145 145 return ((!p->page_cache_disable) << PAGE_CACHEABLE_SHIFT | 146 (!p->present) << PAGE_PRESENT_SHIFT | 147 p->uaccessible << PAGE_USER_SHIFT | 148 1 << PAGE_READ_SHIFT | 149 p->writeable << PAGE_WRITE_SHIFT | 150 1 << PAGE_EXEC_SHIFT | 151 p->global << PAGE_GLOBAL_SHIFT); 146 return ( 147 ((unsigned int) (!p->page_cache_disable) << PAGE_CACHEABLE_SHIFT) | 148 ((unsigned int) (!p->present) << PAGE_PRESENT_SHIFT) | 149 ((unsigned int) p->uaccessible << PAGE_USER_SHIFT) | 150 (1 << PAGE_READ_SHIFT) | 151 ((unsigned int) p->writeable << PAGE_WRITE_SHIFT) | 152 (1 << PAGE_EXEC_SHIFT) | 153 ((unsigned int) p->global << PAGE_GLOBAL_SHIFT) 154 ); 152 155 } 153 156 154 157 static inline void set_pt_flags(pte_t *pt, size_t i, int flags) 158 WRITES(ARRAY_RANGE(pt, PTL0_ENTRIES_ARCH)) 159 REQUIRES_ARRAY_MUTABLE(pt, PTL0_ENTRIES_ARCH) 155 160 { 156 161 pte_t *p = &pt[i]; -
kernel/arch/abs32le/include/types.h
rfe7abd0 rcefb126 35 35 #ifndef KERN_abs32le_TYPES_H_ 36 36 #define KERN_abs32le_TYPES_H_ 37 38 #define ATOMIC_COUNT_MIN UINT32_MIN 39 #define ATOMIC_COUNT_MAX UINT32_MAX 37 40 38 41 typedef uint32_t size_t; -
kernel/arch/abs32le/src/abs32le.c
rfe7abd0 rcefb126 114 114 } 115 115 116 void panic_printf(const char *fmt, ...)116 void istate_decode(istate_t *istate) 117 117 { 118 va_list args; 119 120 va_start(args, fmt); 121 vprintf(fmt, args); 122 va_end(args); 123 124 halt(); 118 (void) istate; 125 119 } 126 120 … … 157 151 } 158 152 153 void early_putchar(wchar_t ch) 154 { 155 } 156 159 157 /** @} 160 158 */ -
kernel/arch/amd64/Makefile.inc
rfe7abd0 rcefb126 33 33 34 34 FPU_NO_CFLAGS = -mno-sse -mno-sse2 35 CMN1 = -m64 -mcmodel= kernel-mno-red-zone -fno-unwind-tables -fno-omit-frame-pointer35 CMN1 = -m64 -mcmodel=large -mno-red-zone -fno-unwind-tables -fno-omit-frame-pointer 36 36 GCC_CFLAGS += $(CMN1) 37 37 ICC_CFLAGS += $(CMN1) … … 71 71 arch/$(KARCH)/src/mm/page.c \ 72 72 arch/$(KARCH)/src/mm/tlb.c \ 73 arch/$(KARCH)/src/asm _utils.S \73 arch/$(KARCH)/src/asm.S \ 74 74 arch/$(KARCH)/src/cpu/cpu.c \ 75 75 arch/$(KARCH)/src/proc/scheduler.c \ -
kernel/arch/amd64/_link.ld.in
rfe7abd0 rcefb126 1 1 /** AMD64 linker script 2 * 2 * 3 3 * umapped section: 4 * kernel text5 * kernel data4 * kernel text 5 * kernel data 6 6 * mapped section: 7 * kernel text8 * kernel data7 * kernel text 8 * kernel data 9 9 */ 10 10 … … 17 17 *(K_TEXT_START); 18 18 unmapped_ktext_end = .; 19 19 20 20 unmapped_kdata_start = .; 21 21 *(K_DATA_START); … … 23 23 unmapped_kdata_end = .; 24 24 } 25 25 26 26 .mapped (PA2KA(BOOT_OFFSET)+SIZEOF(.unmapped)) : AT (SIZEOF(.unmapped)) { 27 27 ktext_start = .; 28 28 *(.text); 29 29 ktext_end = .; 30 30 31 31 kdata_start = .; 32 *(.data); /* initialized data */33 *(.rodata*); /* string literals */32 *(.data); /* initialized data */ 33 *(.rodata*); /* string literals */ 34 34 hardcoded_load_address = .; 35 35 QUAD(PA2KA(BOOT_OFFSET)); … … 42 42 hardcoded_unmapped_kdata_size = .; 43 43 QUAD(unmapped_kdata_end - unmapped_kdata_start); 44 *(COMMON); /* global variables */45 44 *(COMMON); /* global variables */ 45 46 46 . = ALIGN(8); 47 47 symbol_table = .; 48 *(symtab.*); /* Symbol table, must be LAST symbol!*/49 50 *(.bss); /* uninitialized static variables */51 48 *(symtab.*); /* Symbol table, must be LAST symbol!*/ 49 50 *(.bss); /* uninitialized static variables */ 51 52 52 kdata_end = .; 53 53 } 54 54 55 55 /DISCARD/ : { 56 56 *(*); 57 57 } 58 58 59 #ifdef CONFIG_SMP 59 #ifdef CONFIG_SMP 60 60 _hardcoded_unmapped_size = (unmapped_ktext_end - unmapped_ktext_start) + (unmapped_kdata_end - unmapped_kdata_start); 61 61 ap_boot = unmapped_ap_boot - BOOT_OFFSET + AP_BOOT_OFFSET; 62 62 ap_gdtr = unmapped_ap_gdtr - BOOT_OFFSET + AP_BOOT_OFFSET; 63 63 protected_ap_gdtr = PA2KA(ap_gdtr); 64 65 64 #endif /* CONFIG_SMP */ 66 65 67 66 } -
kernel/arch/amd64/include/arch.h
rfe7abd0 rcefb126 27 27 */ 28 28 29 /** @addtogroup amd64 29 /** @addtogroup amd64 30 30 * @{ 31 31 */ -
kernel/arch/amd64/include/boot/boot.h
rfe7abd0 rcefb126 27 27 */ 28 28 29 /** @addtogroup amd64 29 /** @addtogroup amd64 30 30 * @{ 31 31 */ … … 36 36 #define KERN_amd64_BOOT_H_ 37 37 38 #define BOOT_OFFSET 0x10800039 #define AP_BOOT_OFFSET 0x800040 #define BOOT_STACK_SIZE 0x40038 #define BOOT_OFFSET 0x108000 39 #define AP_BOOT_OFFSET 0x008000 40 #define BOOT_STACK_SIZE 0x000400 41 41 42 #define MULTIBOOT_HEADER_MAGIC 0x1BADB00243 #define MULTIBOOT_HEADER_FLAGS 0x0001000342 #define MULTIBOOT_HEADER_MAGIC 0x1BADB002 43 #define MULTIBOOT_HEADER_FLAGS 0x00010003 44 44 45 45 #ifndef __ASM__ -
kernel/arch/amd64/include/context.h
rfe7abd0 rcefb126 59 59 */ 60 60 typedef struct { 61 uintptr_t sp;62 uintptr_t pc;63 64 uint64_t rbx;65 uint64_t rbp;66 67 uint64_t r12;68 uint64_t r13;69 uint64_t r14;70 uint64_t r15;71 72 ipl_t ipl;61 uintptr_t sp; 62 uintptr_t pc; 63 64 uint64_t rbx; 65 uint64_t rbp; 66 67 uint64_t r12; 68 uint64_t r13; 69 uint64_t r14; 70 uint64_t r15; 71 72 ipl_t ipl; 73 73 } __attribute__ ((packed)) context_t; 74 74 -
kernel/arch/amd64/include/elf.h
rfe7abd0 rcefb126 27 27 */ 28 28 29 /** @addtogroup amd64 29 /** @addtogroup amd64 30 30 * @{ 31 31 */ … … 36 36 #define KERN_amd64_ELF_H_ 37 37 38 #define ELF_MACHINEEM_X86_6439 #define ELF_DATA_ENCODING ELFDATA2LSB40 #define ELF_CLASS ELFCLASS6438 #define ELF_MACHINE EM_X86_64 39 #define ELF_DATA_ENCODING ELFDATA2LSB 40 #define ELF_CLASS ELFCLASS64 41 41 42 42 #endif -
kernel/arch/amd64/include/faddr.h
rfe7abd0 rcefb126 27 27 */ 28 28 29 /** @addtogroup amd64 29 /** @addtogroup amd64 30 30 * @{ 31 31 */ … … 38 38 #include <typedefs.h> 39 39 40 #define FADDR(fptr) ((uintptr_t) (fptr))40 #define FADDR(fptr) ((uintptr_t) (fptr)) 41 41 42 42 #endif -
kernel/arch/amd64/include/interrupt.h
rfe7abd0 rcefb126 112 112 extern void (* eoi_function)(void); 113 113 114 extern void decode_istate(int n, istate_t *istate);115 114 extern void interrupt_init(void); 116 115 extern void trap_virtual_enable_irqs(uint16_t irqmask); 117 116 extern void trap_virtual_disable_irqs(uint16_t irqmask); 118 119 /* AMD64 - specific page handler */120 extern void ident_page_fault(unsigned int, istate_t *);121 117 122 118 #endif -
kernel/arch/amd64/include/mm/as.h
rfe7abd0 rcefb126 27 27 */ 28 28 29 /** @addtogroup amd64mm 29 /** @addtogroup amd64mm 30 30 * @{ 31 31 */ … … 36 36 #define KERN_amd64_AS_H_ 37 37 38 #define KERNEL_ADDRESS_SPACE_SHADOWED_ARCH 038 #define KERNEL_ADDRESS_SPACE_SHADOWED_ARCH 0 39 39 40 #define KERNEL_ADDRESS_SPACE_START_ARCH (unsigned long) 0xffff800000000000 41 #define KERNEL_ADDRESS_SPACE_END_ARCH (unsigned long) 0xffffffff80000000 42 #define USER_ADDRESS_SPACE_START_ARCH (unsigned long) 0x0000000000000000 43 #define USER_ADDRESS_SPACE_END_ARCH (unsigned long) 0x00007fffffffffff 40 #define KERNEL_ADDRESS_SPACE_START_ARCH (unsigned long) 0xffff800000000000 41 #define KERNEL_ADDRESS_SPACE_END_ARCH (unsigned long) 0xffffffffffffffff 44 42 45 #define USTACK_ADDRESS_ARCH (USER_ADDRESS_SPACE_END_ARCH-(PAGE_SIZE-1)) 43 #define USER_ADDRESS_SPACE_START_ARCH (unsigned long) 0x0000000000000000 44 #define USER_ADDRESS_SPACE_END_ARCH (unsigned long) 0x00007fffffffffff 46 45 47 #define as_constructor_arch(as, flags) (as != as) 48 #define as_destructor_arch(as) (as != as) 49 #define as_create_arch(as, flags) (as != as) 46 #define USTACK_ADDRESS_ARCH (USER_ADDRESS_SPACE_END_ARCH - (PAGE_SIZE - 1)) 47 48 #define as_constructor_arch(as, flags) (as != as) 49 #define as_destructor_arch(as) (as != as) 50 #define as_create_arch(as, flags) (as != as) 51 50 52 #define as_install_arch(as) 51 53 #define as_deinstall_arch(as) -
kernel/arch/amd64/include/mm/page.h
rfe7abd0 rcefb126 35 35 /** Paging on AMD64 36 36 * 37 * The space is divided in positive numbers - userspace and 38 * negative numbers - kernel space. The 'negative' space starting 39 * with 0xffff800000000000 and ending with 0xffffffff80000000 40 * (-2GB) is identically mapped physical memory. The area 41 * (0xffffffff80000000 ... 0xffffffffffffffff is again identically 42 * mapped first 2GB. 43 * 44 * ATTENTION - PA2KA(KA2PA(x)) != x if 'x' is in kernel 37 * The space is divided in positive numbers (uspace) and 38 * negative numbers (kernel). The 'negative' space starting 39 * with 0xffff800000000000 and ending with 0xffffffffffffffff 40 * is identically mapped physical memory. 41 * 45 42 */ 46 43 … … 50 47 #include <arch/mm/frame.h> 51 48 52 #define PAGE_WIDTH FRAME_WIDTH53 #define PAGE_SIZE FRAME_SIZE49 #define PAGE_WIDTH FRAME_WIDTH 50 #define PAGE_SIZE FRAME_SIZE 54 51 55 52 #ifdef KERNEL 56 53 57 54 #ifndef __ASM__ 58 # include <mm/mm.h> 59 # include <typedefs.h> 60 # include <arch/interrupt.h> 61 62 static inline uintptr_t ka2pa(uintptr_t x) 63 { 64 if (x > 0xffffffff80000000) 65 return x - 0xffffffff80000000; 66 else 67 return x - 0xffff800000000000; 68 } 69 70 # define KA2PA(x) ka2pa((uintptr_t) x) 71 # define PA2KA_CODE(x) (((uintptr_t) (x)) + 0xffffffff80000000) 72 # define PA2KA(x) (((uintptr_t) (x)) + 0xffff800000000000) 73 #else 74 # define KA2PA(x) ((x) - 0xffffffff80000000) 75 # define PA2KA(x) ((x) + 0xffffffff80000000) 76 #endif 55 56 #define KA2PA(x) (((uintptr_t) (x)) - 0xffff800000000000) 57 #define PA2KA(x) (((uintptr_t) (x)) + 0xffff800000000000) 58 59 #else /* __ASM__ */ 60 61 #define KA2PA(x) ((x) - 0xffff800000000000) 62 #define PA2KA(x) ((x) + 0xffff800000000000) 63 64 #endif /* __ASM__ */ 77 65 78 66 /* Number of entries in each level. */ 79 #define PTL0_ENTRIES_ARCH 51280 #define PTL1_ENTRIES_ARCH 51281 #define PTL2_ENTRIES_ARCH 51282 #define PTL3_ENTRIES_ARCH 51267 #define PTL0_ENTRIES_ARCH 512 68 #define PTL1_ENTRIES_ARCH 512 69 #define PTL2_ENTRIES_ARCH 512 70 #define PTL3_ENTRIES_ARCH 512 83 71 84 72 /* Page table sizes for each level. */ 85 #define PTL0_SIZE_ARCH ONE_FRAME86 #define PTL1_SIZE_ARCH ONE_FRAME87 #define PTL2_SIZE_ARCH ONE_FRAME88 #define PTL3_SIZE_ARCH ONE_FRAME73 #define PTL0_SIZE_ARCH ONE_FRAME 74 #define PTL1_SIZE_ARCH ONE_FRAME 75 #define PTL2_SIZE_ARCH ONE_FRAME 76 #define PTL3_SIZE_ARCH ONE_FRAME 89 77 90 78 /* Macros calculating indices into page tables in each level. */ 91 #define PTL0_INDEX_ARCH(vaddr) (((vaddr) >> 39) & 0x1ff)92 #define PTL1_INDEX_ARCH(vaddr) (((vaddr) >> 30) & 0x1ff)93 #define PTL2_INDEX_ARCH(vaddr) (((vaddr) >> 21) & 0x1ff)94 #define PTL3_INDEX_ARCH(vaddr) (((vaddr) >> 12) & 0x1ff)79 #define PTL0_INDEX_ARCH(vaddr) (((vaddr) >> 39) & 0x1ff) 80 #define PTL1_INDEX_ARCH(vaddr) (((vaddr) >> 30) & 0x1ff) 81 #define PTL2_INDEX_ARCH(vaddr) (((vaddr) >> 21) & 0x1ff) 82 #define PTL3_INDEX_ARCH(vaddr) (((vaddr) >> 12) & 0x1ff) 95 83 96 84 /* Get PTE address accessors for each level. */ … … 156 144 #ifndef __ASM__ 157 145 146 #include <mm/mm.h> 147 #include <arch/interrupt.h> 148 #include <typedefs.h> 149 158 150 /* Page fault error codes. */ 159 151 … … 161 153 * page. 162 154 */ 163 #define PFERR_CODE_P (1 << 0)155 #define PFERR_CODE_P (1 << 0) 164 156 165 157 /** When bit on this position is 1, the page fault was caused by a write. */ 166 #define PFERR_CODE_RW (1 << 1)158 #define PFERR_CODE_RW (1 << 1) 167 159 168 160 /** When bit on this position is 1, the page fault was caused in user mode. */ 169 #define PFERR_CODE_US (1 << 2)161 #define PFERR_CODE_US (1 << 2) 170 162 171 163 /** When bit on this position is 1, a reserved bit was set in page directory. */ 172 #define PFERR_CODE_RSVD (1 << 3)164 #define PFERR_CODE_RSVD (1 << 3) 173 165 174 166 /** When bit on this position os 1, the page fault was caused during instruction 175 167 * fecth. 176 168 */ 177 #define PFERR_CODE_ID (1 << 4)169 #define PFERR_CODE_ID (1 << 4) 178 170 179 171 /** Page Table Entry. */ 180 172 typedef struct { 181 unsigned present : 1;182 unsigned writeable : 1;183 unsigned uaccessible : 1;184 unsigned page_write_through : 1;185 unsigned page_cache_disable : 1;186 unsigned accessed : 1;187 unsigned dirty : 1;188 unsigned unused: 1;189 unsigned global : 1;190 unsigned soft_valid : 1;/**< Valid content even if present bit is cleared. */191 unsigned avl : 2;192 unsigned addr_12_31 : 30;193 unsigned addr_32_51 : 21;194 unsigned no_execute : 1;173 unsigned int present : 1; 174 unsigned int writeable : 1; 175 unsigned int uaccessible : 1; 176 unsigned int page_write_through : 1; 177 unsigned int page_cache_disable : 1; 178 unsigned int accessed : 1; 179 unsigned int dirty : 1; 180 unsigned int unused: 1; 181 unsigned int global : 1; 182 unsigned int soft_valid : 1; /**< Valid content even if present bit is cleared. */ 183 unsigned int avl : 2; 184 unsigned int addr_12_31 : 30; 185 unsigned int addr_32_51 : 21; 186 unsigned int no_execute : 1; 195 187 } __attribute__ ((packed)) pte_t; 196 188 … … 211 203 { 212 204 pte_t *p = &pt[i]; 213 205 214 206 p->addr_12_31 = (a >> 12) & 0xfffff; 215 207 p->addr_32_51 = a >> 32; -
kernel/arch/amd64/include/mm/ptl.h
rfe7abd0 rcefb126 27 27 */ 28 28 29 /** @addtogroup amd64mm 29 /** @addtogroup amd64mm 30 30 * @{ 31 31 */ … … 36 36 #define KERN_amd64_PTL_H_ 37 37 38 #define PTL_NO_EXEC (1<<63)39 #define PTL_ACCESSED (1<<5)40 #define PTL_CACHE_DISABLE (1<<4)41 #define PTL_CACHE_THROUGH (1<<3)42 #define PTL_USER (1<<2)43 #define PTL_WRITABLE (1<<1)44 #define PTL_PRESENT 145 #define PTL_2MB_PAGE (1<<7)38 #define PTL_NO_EXEC (1 << 63) 39 #define PTL_ACCESSED (1 << 5) 40 #define PTL_CACHE_DISABLE (1 << 4) 41 #define PTL_CACHE_THROUGH (1 << 3) 42 #define PTL_USER (1 << 2) 43 #define PTL_WRITABLE (1 << 1) 44 #define PTL_PRESENT 1 45 #define PTL_2MB_PAGE (1 << 7) 46 46 47 47 -
kernel/arch/amd64/include/mm/tlb.h
rfe7abd0 rcefb126 27 27 */ 28 28 29 /** @addtogroup amd64mm 29 /** @addtogroup amd64mm 30 30 * @{ 31 31 */ -
kernel/arch/amd64/include/pm.h
rfe7abd0 rcefb126 71 71 #define PL_USER 3 72 72 73 #define AR_PRESENT (1 << 7)73 #define AR_PRESENT (1 << 7) 74 74 #define AR_DATA (2 << 3) 75 75 #define AR_CODE (3 << 3) -
kernel/arch/amd64/include/proc/thread.h
rfe7abd0 rcefb126 37 37 38 38 /* CAUTION: keep these in sync with low level assembly code in syscall_entry */ 39 #define SYSCALL_USTACK_RSP 040 #define SYSCALL_KSTACK_RSP 139 #define SYSCALL_USTACK_RSP 0 40 #define SYSCALL_KSTACK_RSP 1 41 41 42 42 typedef struct { 43 43 unative_t tls; 44 44 /** User and kernel RSP for syscalls. */ 45 uint64_t syscall_rsp[2]; 45 uint64_t syscall_rsp[2]; 46 46 } thread_arch_t; 47 47 -
kernel/arch/amd64/include/types.h
rfe7abd0 rcefb126 50 50 } fncptr_t; 51 51 52 /* *<Formats for uintptr_t, size_t */52 /* Formats for uintptr_t, size_t */ 53 53 #define PRIp "llx" 54 54 #define PRIs "llu" 55 55 56 /* *<Formats for (u)int8_t, (u)int16_t, (u)int32_t, (u)int64_t and (u)native_t */56 /* Formats for (u)int8_t, (u)int16_t, (u)int32_t, (u)int64_t and (u)native_t */ 57 57 #define PRId8 "d" 58 58 #define PRId16 "d" -
kernel/arch/amd64/src/amd64.c
rfe7abd0 rcefb126 122 122 /* Enable FPU */ 123 123 cpu_setup_fpu(); 124 124 125 125 /* Initialize segmentation */ 126 126 pm_init(); … … 132 132 /* Disable alignment check */ 133 133 clean_AM_flag(); 134 134 135 135 if (config.cpu_active == 1) { 136 136 interrupt_init(); … … 260 260 THREAD->arch.tls = addr; 261 261 write_msr(AMD_MSR_FS, addr); 262 262 263 return 0; 263 264 } -
kernel/arch/amd64/src/boot/boot.S
rfe7abd0 rcefb126 1 # 2 #Copyright (c) 2005 Ondrej Palkovsky3 #Copyright (c) 2006 Martin Decky4 #Copyright (c) 2008 Jakub Jermar5 #All rights reserved.6 # 7 #Redistribution and use in source and binary forms, with or without8 #modification, are permitted provided that the following conditions9 #are met:10 # 11 #- Redistributions of source code must retain the above copyright12 #notice, this list of conditions and the following disclaimer.13 #- Redistributions in binary form must reproduce the above copyright14 #notice, this list of conditions and the following disclaimer in the15 #documentation and/or other materials provided with the distribution.16 #- The name of the author may not be used to endorse or promote products17 #derived from this software without specific prior written permission.18 # 19 #THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR20 #IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES21 #OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.22 #IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,23 #INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT24 #NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,25 #DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY26 #THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT27 #(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF28 #THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.29 # 1 /* 2 * Copyright (c) 2005 Ondrej Palkovsky 3 * Copyright (c) 2006 Martin Decky 4 * Copyright (c) 2008 Jakub Jermar 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 11 * - Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * - Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * - The name of the author may not be used to endorse or promote products 17 * derived from this software without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 30 31 31 #include <arch/boot/boot.h> 32 32 #include <arch/boot/memmap.h> 33 #include <arch/mm/page.h> 33 #include <arch/mm/page.h> 34 34 #include <arch/mm/ptl.h> 35 35 #include <arch/pm.h> … … 37 37 #include <arch/cpuid.h> 38 38 39 #define START_STACK (BOOT_OFFSET - BOOT_STACK_SIZE)39 #define START_STACK (BOOT_OFFSET - BOOT_STACK_SIZE) 40 40 41 41 .section K_TEXT_START, "ax" 42 42 43 43 .code32 44 45 .macro pm_error msg 46 movl \msg, %esi 47 jmp pm_error_halt 48 .endm 49 50 .macro pm_status msg 51 #ifdef CONFIG_EGA 52 pushl %esi 53 movl \msg, %esi 54 call pm_early_puts 55 popl %esi 56 #endif 57 .endm 58 59 .macro pm2_status msg 60 #ifndef CONFIG_FB 61 pm_status \msg 62 #endif 63 .endm 64 44 65 .align 4 45 66 .global multiboot_image_start … … 47 68 .long MULTIBOOT_HEADER_MAGIC 48 69 .long MULTIBOOT_HEADER_FLAGS 49 .long -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS) # checksum70 .long -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS) /* checksum */ 50 71 .long multiboot_header 51 72 .long unmapped_ktext_start … … 56 77 multiboot_image_start: 57 78 cld 58 movl $START_STACK, %esp # initialize stack pointer 59 lgdtl bootstrap_gdtr # initialize Global Descriptor Table register 60 79 80 /* Initialize stack pointer */ 81 movl $START_STACK, %esp 82 83 /* Initialize Global Descriptor Table register */ 84 lgdtl bootstrap_gdtr 85 86 /* Kernel data + stack */ 61 87 movw $gdtselector(KDATA_DES), %cx 62 88 movw %cx, %es 63 movw %cx, %ds # kernel data + stack89 movw %cx, %ds 64 90 movw %cx, %ss 65 91 66 # 67 # Simics seems to remove hidden part of GS on entering user mode 68 # when _visible_ part of GS does not point to user-mode segment. 69 # 70 92 /* 93 * Simics seems to remove hidden part of GS on entering user mode 94 * when _visible_ part of GS does not point to user-mode segment. 95 */ 71 96 movw $gdtselector(UDATA_DES), %cx 72 97 movw %cx, %fs … … 76 101 multiboot_meeting_point: 77 102 78 movl %eax, grub_eax # save parameters from GRUB 103 /* Save GRUB arguments */ 104 movl %eax, grub_eax 79 105 movl %ebx, grub_ebx 80 106 81 # 82 # Protected 32-bit. We want to reuse the code-seg descriptor, 83 # the Default operand size must not be 1 when entering long mode. 84 # 107 pm_status $status_prot 85 108 86 109 movl $(INTEL_CPUID_EXTENDED), %eax … … 89 112 ja extended_cpuid_supported 90 113 91 movl $extended_cpuid_msg, %esi 92 jmp error_halt 114 pm_error $err_extended_cpuid 93 115 94 116 extended_cpuid_supported: … … 99 121 jc long_mode_supported 100 122 101 movl $long_mode_msg, %esi 102 jmp error_halt 123 pm_error $err_long_mode 103 124 104 125 long_mode_supported: … … 107 128 jc noexecute_supported 108 129 109 movl $noexecute_msg, %esi 110 jmp error_halt 130 pm_error $err_noexecute 111 131 112 132 noexecute_supported: … … 117 137 jc fx_supported 118 138 119 movl $fx_msg, %esi 120 jmp error_halt 139 pm_error $err_fx 121 140 122 141 fx_supported: … … 125 144 jc sse2_supported 126 145 127 movl $sse2_msg, %esi 128 jmp error_halt 146 pm_error $err_sse2 129 147 130 148 sse2_supported: 131 149 132 150 #include "vesa_prot.inc" 133 134 # 135 # Enable 64-bit page translation entries - CR4.PAE = 1. 136 # Paging is not enabled until after long mode is enabled. 137 # 151 152 /* 153 * Protected 32-bit. We want to reuse the code-seg descriptor, 154 * the Default operand size must not be 1 when entering long mode. 155 */ 156 157 pm2_status $status_prot2 158 159 /* 160 * Enable 64-bit page translation entries - CR4.PAE = 1. 161 * Paging is not enabled until after long mode is enabled. 162 */ 138 163 139 164 movl %cr4, %eax … … 141 166 movl %eax, %cr4 142 167 143 # set up paging tables 144 168 /* Set up paging tables */ 145 169 leal ptl_0, %eax 146 170 movl %eax, %cr3 147 171 148 # enable long mode 149 150 movl $EFER_MSR_NUM, %ecx # EFER MSR number 151 rdmsr # read EFER 152 btsl $AMD_LME_FLAG, %eax # set LME = 1 153 wrmsr # write EFER 154 155 # enable paging to activate long mode (set CR0.PG = 1) 156 172 /* Enable long mode */ 173 movl $EFER_MSR_NUM, %ecx 174 rdmsr /* read EFER */ 175 btsl $AMD_LME_FLAG, %eax /* set LME = 1 */ 176 wrmsr 177 178 /* Enable paging to activate long mode (set CR0.PG = 1) */ 157 179 movl %cr0, %eax 158 180 btsl $31, %eax 159 181 movl %eax, %cr0 160 182 161 # at this point we are in compatibility mode 162 183 /* At this point we are in compatibility mode */ 163 184 jmpl $gdtselector(KTEXT_DES), $start64 164 185 186 /** Print string to EGA display (in light red) and halt. 187 * 188 * Should be executed from 32 bit protected mode with paging 189 * turned off. Stack is not required. This routine is used even 190 * if CONFIG_EGA is not enabled. Since we are going to halt the 191 * CPU anyway, it is always better to at least try to print 192 * some hints. 193 * 194 * @param %esi Pointer to the NULL-terminated string 195 * to be print. 196 * 197 */ 198 pm_error_halt: 199 movl $0xb8000, %edi /* base of EGA text mode memory */ 200 xorl %eax, %eax 201 202 /* Read bits 8 - 15 of the cursor address */ 203 movw $0x3d4, %dx 204 movb $0xe, %al 205 outb %al, %dx 206 207 movw $0x3d5, %dx 208 inb %dx, %al 209 shl $8, %ax 210 211 /* Read bits 0 - 7 of the cursor address */ 212 movw $0x3d4, %dx 213 movb $0xf, %al 214 outb %al, %dx 215 216 movw $0x3d5, %dx 217 inb %dx, %al 218 219 /* Sanity check for the cursor on screen */ 220 cmp $2000, %ax 221 jb err_cursor_ok 222 223 movw $1998, %ax 224 225 err_cursor_ok: 226 227 movw %ax, %bx 228 shl $1, %eax 229 addl %eax, %edi 230 231 err_ploop: 232 lodsb 233 234 cmp $0, %al 235 je err_ploop_end 236 237 movb $0x0c, %ah /* black background, light red foreground */ 238 stosw 239 240 /* Sanity check for the cursor on the last line */ 241 inc %bx 242 cmp $2000, %bx 243 jb err_ploop 244 245 /* Scroll the screen (24 rows) */ 246 movl %esi, %edx 247 movl $0xb80a0, %esi 248 movl $0xb8000, %edi 249 movl $1920, %ecx 250 rep movsw 251 252 /* Clear the 24th row */ 253 xorl %eax, %eax 254 movl $80, %ecx 255 rep stosw 256 257 /* Go to row 24 */ 258 movl %edx, %esi 259 movl $0xb8f00, %edi 260 movw $1920, %bx 261 262 jmp err_ploop 263 err_ploop_end: 264 265 /* Write bits 8 - 15 of the cursor address */ 266 movw $0x3d4, %dx 267 movb $0xe, %al 268 outb %al, %dx 269 270 movw $0x3d5, %dx 271 movb %bh, %al 272 outb %al, %dx 273 274 /* Write bits 0 - 7 of the cursor address */ 275 movw $0x3d4, %dx 276 movb $0xf, %al 277 outb %al, %dx 278 279 movw $0x3d5, %dx 280 movb %bl, %al 281 outb %al, %dx 282 283 cli 284 hlt1: 285 hlt 286 jmp hlt1 287 288 /** Print string to EGA display (in light green). 289 * 290 * Should be called from 32 bit protected mode with paging 291 * turned off. A stack space of at least 24 bytes is required, 292 * but the function does not establish a stack frame. 293 * 294 * Macros such as pm_status and pm2_status take care that 295 * this function is used only when CONFIG_EGA is enabled 296 * and CONFIG_FB is disabled. 297 * 298 * @param %esi Pointer to the NULL-terminated string 299 * to be print. 300 * 301 */ 302 pm_early_puts: 303 pushl %eax 304 pushl %ebx 305 pushl %ecx 306 pushl %edx 307 pushl %edi 308 309 movl $0xb8000, %edi /* base of EGA text mode memory */ 310 xorl %eax, %eax 311 312 /* Read bits 8 - 15 of the cursor address */ 313 movw $0x3d4, %dx 314 movb $0xe, %al 315 outb %al, %dx 316 317 movw $0x3d5, %dx 318 inb %dx, %al 319 shl $8, %ax 320 321 /* Read bits 0 - 7 of the cursor address */ 322 movw $0x3d4, %dx 323 movb $0xf, %al 324 outb %al, %dx 325 326 movw $0x3d5, %dx 327 inb %dx, %al 328 329 /* Sanity check for the cursor on screen */ 330 cmp $2000, %ax 331 jb pm_puts_cursor_ok 332 333 movw $1998, %ax 334 335 pm_puts_cursor_ok: 336 337 movw %ax, %bx 338 shl $1, %eax 339 addl %eax, %edi 340 341 pm_puts_ploop: 342 lodsb 343 344 cmp $0, %al 345 je pm_puts_ploop_end 346 347 movb $0x0a, %ah /* black background, light green foreground */ 348 stosw 349 350 /* Sanity check for the cursor on the last line */ 351 inc %bx 352 cmp $2000, %bx 353 jb pm_puts_ploop 354 355 /* Scroll the screen (24 rows) */ 356 movl %esi, %edx 357 movl $0xb80a0, %esi 358 movl $0xb8000, %edi 359 movl $1920, %ecx 360 rep movsw 361 362 /* Clear the 24th row */ 363 xorl %eax, %eax 364 movl $80, %ecx 365 rep stosw 366 367 /* Go to row 24 */ 368 movl %edx, %esi 369 movl $0xb8f00, %edi 370 movw $1920, %bx 371 372 jmp pm_puts_ploop 373 pm_puts_ploop_end: 374 375 /* Write bits 8 - 15 of the cursor address */ 376 movw $0x3d4, %dx 377 movb $0xe, %al 378 outb %al, %dx 379 380 movw $0x3d5, %dx 381 movb %bh, %al 382 outb %al, %dx 383 384 /* Write bits 0 - 7 of the cursor address */ 385 movw $0x3d4, %dx 386 movb $0xf, %al 387 outb %al, %dx 388 389 movw $0x3d5, %dx 390 movb %bl, %al 391 outb %al, %dx 392 393 popl %edi 394 popl %edx 395 popl %ecx 396 popl %ebx 397 popl %eax 398 399 ret 400 165 401 .code64 402 403 .macro long_status msg 404 pushq %rdi 405 movq \msg, %rdi 406 call early_puts 407 popq %rdi 408 .endm 409 166 410 start64: 411 412 /* 413 * Long mode. 414 */ 415 167 416 movq $(PA2KA(START_STACK)), %rsp 168 417 169 # call arch_pre_main(grub_eax, grub_ebx) 418 /* Create the first stack frame */ 419 pushq $0 420 movq %rsp, %rbp 421 422 long_status $status_long 423 424 /* Call arch_pre_main(grub_eax, grub_ebx) */ 170 425 xorq %rdi, %rdi 171 426 movl grub_eax, %edi 172 427 xorq %rsi, %rsi 173 428 movl grub_ebx, %esi 174 call arch_pre_main 175 176 # create the first stack frame 177 pushq $0 178 movq %rsp, %rbp 179 180 call main_bsp 181 182 # not reached 183 429 430 movabsq $arch_pre_main, %rax 431 callq *%rax 432 433 long_status $status_main 434 435 /* Call main_bsp() */ 436 movabsq $main_bsp, %rax 437 call *%rax 438 439 /* Not reached */ 184 440 cli 185 441 hlt0: … … 187 443 jmp hlt0 188 444 189 # Print string from %esi to EGA display (in red) and halt 190 error_halt: 191 movl $0xb8000, %edi # base of EGA text mode memory 192 xorl %eax, %eax 193 194 movw $0x3d4, %dx # read bits 8 - 15 of the cursor address 445 /** Print string to EGA display. 446 * 447 * Should be called from long mode (with paging enabled 448 * and stack established). This function is ABI compliant 449 * (without red-zone). 450 * 451 * If CONFIG_EGA is undefined or CONFIG_FB is defined 452 * then this function does nothing. 453 * 454 * @param %rdi Pointer to the NULL-terminated string 455 * to be printed. 456 * 457 */ 458 early_puts: 459 460 #if ((defined(CONFIG_EGA)) && (!defined(CONFIG_FB))) 461 462 /* Prologue, save preserved registers */ 463 pushq %rbp 464 movq %rsp, %rbp 465 pushq %rbx 466 467 movq %rdi, %rsi 468 movq $(PA2KA(0xb8000)), %rdi /* base of EGA text mode memory */ 469 xorq %rax, %rax 470 471 /* Read bits 8 - 15 of the cursor address */ 472 movw $0x3d4, %dx 195 473 movb $0xe, %al 196 474 outb %al, %dx … … 200 478 shl $8, %ax 201 479 202 movw $0x3d4, %dx # read bits 0 - 7 of the cursor address 480 /* Read bits 0 - 7 of the cursor address */ 481 movw $0x3d4, %dx 203 482 movb $0xf, %al 204 483 outb %al, %dx … … 207 486 inb %dx, %al 208 487 209 cmp $1920, %ax 210 jbe cursor_ok 211 212 movw $1920, %ax # sanity check for the cursor on the last line 213 214 cursor_ok: 488 /* Sanity check for the cursor on screen */ 489 cmp $2000, %ax 490 jb early_puts_cursor_ok 491 492 movw $1998, %ax 493 494 early_puts_cursor_ok: 215 495 216 496 movw %ax, %bx 217 shl $1, %eax 218 addl %eax, %edi 219 220 movw $0x0c00, %ax # black background, light red foreground 221 222 ploop: 497 shl $1, %rax 498 addq %rax, %rdi 499 500 early_puts_ploop: 223 501 lodsb 502 224 503 cmp $0, %al 225 je ploop_end 504 je early_puts_ploop_end 505 506 movb $0x0e, %ah /* black background, yellow foreground */ 226 507 stosw 508 509 /* Sanity check for the cursor on the last line */ 227 510 inc %bx 228 jmp ploop 229 ploop_end: 230 231 movw $0x3d4, %dx # write bits 8 - 15 of the cursor address 511 cmp $2000, %bx 512 jb early_puts_ploop 513 514 /* Scroll the screen (24 rows) */ 515 movq %rsi, %rdx 516 movq $(PA2KA(0xb80a0)), %rsi 517 movq $(PA2KA(0xb8000)), %rdi 518 movq $1920, %rcx 519 rep movsw 520 521 /* Clear the 24th row */ 522 xorq %rax, %rax 523 movq $80, %rcx 524 rep stosw 525 526 /* Go to row 24 */ 527 movq %rdx, %rsi 528 movq $(PA2KA(0xb8f00)), %rdi 529 movw $1920, %bx 530 531 jmp early_puts_ploop 532 early_puts_ploop_end: 533 534 /* Write bits 8 - 15 of the cursor address */ 535 movw $0x3d4, %dx 232 536 movb $0xe, %al 233 537 outb %al, %dx … … 237 541 outb %al, %dx 238 542 239 movw $0x3d4, %dx # write bits 0 - 7 of the cursor address 543 /* Write bits 0 - 7 of the cursor address */ 544 movw $0x3d4, %dx 240 545 movb $0xf, %al 241 546 outb %al, %dx … … 245 550 outb %al, %dx 246 551 247 cli 248 hlt1: 249 hlt 250 jmp hlt1 552 /* Epilogue, restore preserved registers */ 553 popq %rbx 554 leave 555 556 #endif 557 558 ret 251 559 252 560 #include "vesa_real.inc" … … 254 562 .section K_INI_PTLS, "aw", @progbits 255 563 256 # 257 # Macro for generating initial page table contents. 258 # @param cnt Number of entries to generat. Must be multiple of 8. 259 # @param g Number of GB that will be added to the mapping. 260 # 261 .macro ptl2gen cnt g 262 .if \cnt 263 ptl2gen "\cnt - 8" \g 264 .quad ((\cnt - 8) * 0x200000) + (\g * 1024 * 1024 * 1024) | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) 265 .quad ((\cnt - 7) * 0x200000) + (\g * 1024 * 1024 * 1024) | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) 266 .quad ((\cnt - 6) * 0x200000) + (\g * 1024 * 1024 * 1024) | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) 267 .quad ((\cnt - 5) * 0x200000) + (\g * 1024 * 1024 * 1024) | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) 268 .quad ((\cnt - 4) * 0x200000) + (\g * 1024 * 1024 * 1024) | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) 269 .quad ((\cnt - 3) * 0x200000) + (\g * 1024 * 1024 * 1024) | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) 270 .quad ((\cnt - 2) * 0x200000) + (\g * 1024 * 1024 * 1024) | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) 271 .quad ((\cnt - 1) * 0x200000) + (\g * 1024 * 1024 * 1024) | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) 272 .endif 564 /** Generate initial page table contents. 565 * 566 * @param cnt Number of entries to generate. Must be multiple of 8. 567 * @param g Number of GB that will be added to the mapping. 568 * 569 */ 570 .macro ptl2gen cnt g 571 .if \cnt 572 ptl2gen "\cnt - 8" \g 573 .quad ((\cnt - 8) * 0x200000) + (\g * 1024 * 1024 * 1024) | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) 574 .quad ((\cnt - 7) * 0x200000) + (\g * 1024 * 1024 * 1024) | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) 575 .quad ((\cnt - 6) * 0x200000) + (\g * 1024 * 1024 * 1024) | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) 576 .quad ((\cnt - 5) * 0x200000) + (\g * 1024 * 1024 * 1024) | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) 577 .quad ((\cnt - 4) * 0x200000) + (\g * 1024 * 1024 * 1024) | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) 578 .quad ((\cnt - 3) * 0x200000) + (\g * 1024 * 1024 * 1024) | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) 579 .quad ((\cnt - 2) * 0x200000) + (\g * 1024 * 1024 * 1024) | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) 580 .quad ((\cnt - 1) * 0x200000) + (\g * 1024 * 1024 * 1024) | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE) 581 .endif 273 582 .endm 274 583 275 # Page table for pages in the first gigabyte. 276 .align 4096 277 .global ptl_2_0g 278 ptl_2_0g: 584 /* Page table for pages in the 1st gigabyte. */ 585 .align 4096 586 ptl_2_0g: 279 587 ptl2gen 512 0 280 588 281 # Page table for pages in the second gigabyte. 282 .align 4096 283 .global ptl_2_1g 589 /* Page table for pages in the 2nd gigabyte. */ 590 .align 4096 284 591 ptl_2_1g: 285 592 ptl2gen 512 1 286 593 287 # Page table for pages in the third gigabyte. 288 .align 4096 289 .global ptl_2_2g 594 /* Page table for pages in the 3rd gigabyte. */ 595 .align 4096 290 596 ptl_2_2g: 291 597 ptl2gen 512 2 292 598 293 # Page table for pages in the fourth gigabyte. 294 .align 4096 295 .global ptl_2_3g 599 /* Page table for pages in the 4th gigabyte. */ 600 .align 4096 296 601 ptl_2_3g: 297 602 ptl2gen 512 3 298 603 299 .align 4096 300 .global ptl_1 604 /* Page table for pages in the 5th gigabyte. */ 605 .align 4096 606 ptl_2_4g: 607 ptl2gen 512 3 608 609 /* Page table for pages in the 6th gigabyte. */ 610 .align 4096 611 ptl_2_5g: 612 ptl2gen 512 3 613 614 /* Page table for pages in the 7th gigabyte. */ 615 .align 4096 616 ptl_2_6g: 617 ptl2gen 512 3 618 619 /* Page table for pages in the 8th gigabyte. */ 620 .align 4096 621 ptl_2_7g: 622 ptl2gen 512 3 623 624 .align 4096 301 625 ptl_1: 302 # Identity mapping for [0; 4G)626 /* Identity mapping for [0; 8G) */ 303 627 .quad ptl_2_0g + (PTL_WRITABLE | PTL_PRESENT) 304 .quad ptl_2_1g + (PTL_WRITABLE | PTL_PRESENT) 628 .quad ptl_2_1g + (PTL_WRITABLE | PTL_PRESENT) 305 629 .quad ptl_2_2g + (PTL_WRITABLE | PTL_PRESENT) 306 630 .quad ptl_2_3g + (PTL_WRITABLE | PTL_PRESENT) 307 .fill 506, 8, 0 308 # Mapping of [0; 1G) at -2G 309 .quad ptl_2_0g + (PTL_WRITABLE | PTL_PRESENT) 310 .fill 1, 8, 0 631 .quad ptl_2_4g + (PTL_WRITABLE | PTL_PRESENT) 632 .quad ptl_2_5g + (PTL_WRITABLE | PTL_PRESENT) 633 .quad ptl_2_6g + (PTL_WRITABLE | PTL_PRESENT) 634 .quad ptl_2_7g + (PTL_WRITABLE | PTL_PRESENT) 635 .fill 504, 8, 0 311 636 312 637 .align 4096 … … 314 639 ptl_0: 315 640 .quad ptl_1 + (PTL_WRITABLE | PTL_PRESENT) 316 .fill 255, 8,0641 .fill 255, 8, 0 317 642 .quad ptl_1 + (PTL_WRITABLE | PTL_PRESENT) 318 .fill 254,8,0 319 .quad ptl_1 + (PTL_WRITABLE | PTL_PRESENT) 643 .fill 255, 8, 0 320 644 321 645 .section K_DATA_START, "aw", @progbits … … 332 656 .long 0 333 657 334 e xtended_cpuid_msg:658 err_extended_cpuid: 335 659 .asciz "Error: Extended CPUID not supported -- CPU is not 64-bit. System halted." 336 long_mode_msg:660 err_long_mode: 337 661 .asciz "Error: 64-bit long mode not supported. System halted." 338 noexecute_msg:662 err_noexecute: 339 663 .asciz "Error: No-execute pages not supported. System halted." 340 fx_msg:664 err_fx: 341 665 .asciz "Error: FXSAVE/FXRESTORE instructions not supported. System halted." 342 sse2_msg:666 err_sse2: 343 667 .asciz "Error: SSE2 instructions not supported. System halted." 668 669 status_prot: 670 .asciz "[prot] " 671 status_vesa_copy: 672 .asciz "[vesa_copy] " 673 status_grub_cmdline: 674 .asciz "[grub_cmdline] " 675 status_vesa_real: 676 .asciz "[vesa_real] " 677 status_prot2: 678 .asciz "[prot2] " 679 status_long: 680 .asciz "[long] " 681 status_main: 682 .asciz "[main] " -
kernel/arch/amd64/src/boot/vesa_ret.inc
rfe7abd0 rcefb126 1 1 .code32 2 2 vesa_init_protected: 3 cld 4 5 /* Initialize stack pointer */ 6 movl $START_STACK, %esp 7 8 /* Kernel data + stack */ 3 9 movw $gdtselector(KDATA_DES), %cx 4 10 movw %cx, %es 5 movw %cx, %ds # kernel data + stack11 movw %cx, %ds 6 12 movw %cx, %ss 7 13 8 #9 #Simics seems to remove hidden part of GS on entering user mode10 #when _visible_ part of GS does not point to user-mode segment.11 #14 /* 15 * Simics seems to remove hidden part of GS on entering user mode 16 * when _visible_ part of GS does not point to user-mode segment. 17 */ 12 18 13 19 movw $gdtselector(UDATA_DES), %cx … … 15 21 movw %cx, %gs 16 22 17 movl $START_STACK, %esp # initialize stack pointer18 19 23 jmpl $gdtselector(KTEXT32_DES), $vesa_meeting_point -
kernel/arch/amd64/src/context.S
rfe7abd0 rcefb126 41 41 context_save_arch: 42 42 movq (%rsp), %rdx # the caller's return %eip 43 44 # In %edi is passed 1st argument45 CONTEXT_SAVE_ARCH_CORE %rdi %rdx46 43 47 xorq %rax,%rax # context_save returns 1 44 # 1st argument passed in %edi 45 CONTEXT_SAVE_ARCH_CORE %rdi %rdx 46 47 xorq %rax, %rax # context_save returns 1 48 48 incq %rax 49 49 ret … … 55 55 # pointed by the 1st argument. Returns 0 in EAX. 56 56 # 57 context_restore_arch: 58 57 context_restore_arch: 59 58 CONTEXT_RESTORE_ARCH_CORE %rdi %rdx 60 61 movq %rdx, (%rsp)62 63 xorq %rax, %rax# context_restore returns 059 60 movq %rdx, (%rsp) 61 62 xorq %rax, %rax # context_restore returns 0 64 63 ret -
kernel/arch/amd64/src/cpu/cpu.c
rfe7abd0 rcefb126 47 47 * Contains only non-MP-Specification specific SMP code. 48 48 */ 49 #define AMD_CPUID_EBX 0x6874754150 #define AMD_CPUID_ECX 0x444d416351 #define AMD_CPUID_EDX 0x69746e6549 #define AMD_CPUID_EBX 0x68747541 50 #define AMD_CPUID_ECX 0x444d4163 51 #define AMD_CPUID_EDX 0x69746e65 52 52 53 #define INTEL_CPUID_EBX 0x756e654754 #define INTEL_CPUID_ECX 0x6c65746e55 #define INTEL_CPUID_EDX 0x49656e6953 #define INTEL_CPUID_EBX 0x756e6547 54 #define INTEL_CPUID_ECX 0x6c65746e 55 #define INTEL_CPUID_EDX 0x49656e69 56 56 57 57 … … 127 127 { 128 128 cpu_info_t info; 129 129 130 130 CPU->arch.vendor = VendorUnknown; 131 131 if (has_cpuid()) { 132 132 cpuid(INTEL_CPUID_LEVEL, &info); 133 133 134 134 /* 135 135 * Check for AMD processor. 136 136 */ 137 if ( info.cpuid_ebx == AMD_CPUID_EBX&&138 info.cpuid_ecx == AMD_CPUID_ECX&&139 info.cpuid_edx == AMD_CPUID_EDX) {137 if ((info.cpuid_ebx == AMD_CPUID_EBX) && 138 (info.cpuid_ecx == AMD_CPUID_ECX) && 139 (info.cpuid_edx == AMD_CPUID_EDX)) { 140 140 CPU->arch.vendor = VendorAMD; 141 141 } 142 142 143 143 /* 144 144 * Check for Intel processor. 145 */ 146 if ( info.cpuid_ebx == INTEL_CPUID_EBX&&147 info.cpuid_ecx == INTEL_CPUID_ECX&&148 info.cpuid_edx == INTEL_CPUID_EDX) {145 */ 146 if ((info.cpuid_ebx == INTEL_CPUID_EBX) && 147 (info.cpuid_ecx == INTEL_CPUID_ECX) && 148 (info.cpuid_edx == INTEL_CPUID_EDX)) { 149 149 CPU->arch.vendor = VendorIntel; 150 150 } 151 151 152 152 cpuid(INTEL_CPUID_STANDARD, &info); 153 153 CPU->arch.family = (info.cpuid_eax >> 8) & 0xf; 154 154 CPU->arch.model = (info.cpuid_eax >> 4) & 0xf; 155 CPU->arch.stepping = (info.cpuid_eax >> 0) & 0xf; 155 CPU->arch.stepping = (info.cpuid_eax >> 0) & 0xf; 156 156 } 157 157 } -
kernel/arch/amd64/src/debug/stacktrace.c
rfe7abd0 rcefb126 37 37 #include <typedefs.h> 38 38 39 #define FRAME_OFFSET_FP_PREV 040 #define FRAME_OFFSET_RA 139 #define FRAME_OFFSET_FP_PREV 0 40 #define FRAME_OFFSET_RA 1 41 41 42 42 bool kernel_frame_pointer_validate(uintptr_t fp) … … 49 49 uint64_t *stack = (void *) fp; 50 50 *prev = stack[FRAME_OFFSET_FP_PREV]; 51 51 52 return true; 52 53 } … … 56 57 uint64_t *stack = (void *) fp; 57 58 *ra = stack[FRAME_OFFSET_RA]; 59 58 60 return true; 59 61 } -
kernel/arch/amd64/src/debugger.c
rfe7abd0 rcefb126 230 230 return; 231 231 232 printf("*** Found ZERO on address % lx(slot %d) ***\n",232 printf("*** Found ZERO on address %" PRIp " (slot %d) ***\n", 233 233 breakpoints[slot].address, slot); 234 234 } else { 235 printf("Data watchpoint - new data: % lx\n",235 printf("Data watchpoint - new data: %" PRIp "\n", 236 236 *((unative_t *) breakpoints[slot].address)); 237 237 } 238 238 } 239 239 240 printf("Reached breakpoint %d:% lx(%s)\n", slot, getip(istate),240 printf("Reached breakpoint %d:%" PRIp " (%s)\n", slot, getip(istate), 241 241 symtab_fmt_name_lookup(getip(istate))); 242 242 … … 349 349 { 350 350 #ifdef __32_BITS__ 351 printf("# Count Address In symbol\n"); 352 printf("-- ----- ---------- ---------\n"); 351 printf("[nr] [count] [address ] [in symbol\n"); 353 352 #endif 354 353 355 354 #ifdef __64_BITS__ 356 printf("# Count Address In symbol\n"); 357 printf("-- ----- ------------------ ---------\n"); 355 printf("[nr] [count] [address ] [in symbol\n"); 358 356 #endif 359 357 … … 365 363 366 364 #ifdef __32_BITS__ 367 printf("%- 2u %-5" PRIs " %p %s\n", i,365 printf("%-4u %7" PRIs " %p %s\n", i, 368 366 breakpoints[i].counter, breakpoints[i].address, 369 367 symbol); … … 371 369 372 370 #ifdef __64_BITS__ 373 printf("%- 2u %-5" PRIs " %p %s\n", i,371 printf("%-4u %7" PRIs " %p %s\n", i, 374 372 breakpoints[i].counter, breakpoints[i].address, 375 373 symbol); -
kernel/arch/amd64/src/delay.S
rfe7abd0 rcefb126 37 37 38 38 asm_delay_loop: 39 0: dec %rdi 40 jnz 0b 39 0: 40 dec %rdi 41 jnz 0b 42 41 43 ret 42 44 43 45 asm_fake_loop: 44 0: dec %rdi 45 jz 0b 46 0: 47 dec %rdi 48 jz 0b 49 46 50 ret -
kernel/arch/amd64/src/fpu_context.c
rfe7abd0 rcefb126 27 27 */ 28 28 29 /** @addtogroup amd64 29 /** @addtogroup amd64 30 30 * @{ 31 31 */ -
kernel/arch/amd64/src/interrupt.c
rfe7abd0 rcefb126 63 63 void (* eoi_function)(void) = NULL; 64 64 65 void decode_istate(int n, istate_t *istate) 66 { 67 const char *symbol = symtab_fmt_name_lookup(istate->rip); 68 69 printf("-----EXCEPTION(%d) OCCURED----- ( %s )\n", n, __func__); 70 printf("%%rip: %#llx (%s)\n", istate->rip, symbol); 71 printf("ERROR_WORD=%#llx\n", istate->error_word); 72 printf("%%cs=%#llx, rflags=%#llx, %%cr0=%#llx\n", istate->cs, 73 istate->rflags, read_cr0()); 74 printf("%%rax=%#llx, %%rcx=%#llx, %%rdx=%#llx\n", istate->rax, 65 void istate_decode(istate_t *istate) 66 { 67 printf("error_word=%#llx\n", istate->error_word); 68 printf("cs =%#0.16llx\trflags=%#0.16llx\n", istate->cs, 69 istate->rflags); 70 printf("rax=%#0.16llx\trbx=%#0.16llx\trcx=%#0.16llx\n", istate->rax, 75 71 istate->rcx, istate->rdx); 76 printf(" %%rsi=%#llx, %%rdi=%#llx, %%r8=%#llx\n", istate->rsi,72 printf("rsi=%#0.16llx\trdi=%#0.16llx\tr8 =%#0.16llx\n", istate->rsi, 77 73 istate->rdi, istate->r8); 78 printf(" %%r9=%#llx, %%r10=%#llx, %%r11=%#llx\n", istate->r9,74 printf("r9 =%#0.16llx\tr10=%#0.16llx\tr11=%#0.16llx\n", istate->r9, 79 75 istate->r10, istate->r11); 80 printf("%%rsp=%#llx\n", &istate->stack[0]);81 82 stack_trace_istate(istate);83 76 } 84 77 … … 95 88 { 96 89 fault_if_from_uspace(istate, "Unserviced interrupt: %u.", n); 97 decode_istate(n, istate); 98 panic("Unserviced interrupt."); 90 panic_badtrap(istate, n, "Unserviced interrupt."); 99 91 } 100 92 … … 102 94 { 103 95 fault_if_from_uspace(istate, "Divide error."); 104 decode_istate(n, istate); 105 panic("Divide error."); 96 panic_badtrap(istate, n, "Divide error."); 106 97 } 107 98 … … 129 120 fault_if_from_uspace(istate, "General protection fault."); 130 121 } 131 132 decode_istate(n, istate); 133 panic("General protection fault."); 122 panic_badtrap(istate, n, "General protection fault."); 134 123 } 135 124 … … 137 126 { 138 127 fault_if_from_uspace(istate, "Stack fault."); 139 decode_istate(n, istate); 140 panic("Stack fault."); 128 panic_badtrap(istate, n, "Stack fault."); 141 129 } 142 130 … … 214 202 exc_register(12, "ss_fault", true, (iroutine_t) ss_fault); 215 203 exc_register(13, "gp_fault", true, (iroutine_t) gp_fault); 216 exc_register(14, "ident_mapper", true, (iroutine_t) ident_page_fault);217 204 218 205 #ifdef CONFIG_SMP -
kernel/arch/amd64/src/mm/page.c
rfe7abd0 rcefb126 39 39 #include <mm/frame.h> 40 40 #include <mm/as.h> 41 #include <arch/interrupt.h>42 41 #include <arch/asm.h> 43 42 #include <config.h> … … 48 47 #include <align.h> 49 48 50 /* Definitions for identity page mapper */51 pte_t helper_ptl1[512] __attribute__((aligned (PAGE_SIZE)));52 pte_t helper_ptl2[512] __attribute__((aligned (PAGE_SIZE)));53 pte_t helper_ptl3[512] __attribute__((aligned (PAGE_SIZE)));54 extern pte_t ptl_0; /* From boot.S */55 56 #define PTL1_PRESENT(ptl0, page) (!(GET_PTL1_FLAGS_ARCH(ptl0, PTL0_INDEX_ARCH(page)) & PAGE_NOT_PRESENT))57 #define PTL2_PRESENT(ptl1, page) (!(GET_PTL2_FLAGS_ARCH(ptl1, PTL1_INDEX_ARCH(page)) & PAGE_NOT_PRESENT))58 #define PTL3_PRESENT(ptl2, page) (!(GET_PTL3_FLAGS_ARCH(ptl2, PTL2_INDEX_ARCH(page)) & PAGE_NOT_PRESENT))59 60 #define PTL1_ADDR(ptl0, page) ((pte_t *)PA2KA(GET_PTL1_ADDRESS_ARCH(ptl0, PTL0_INDEX_ARCH(page))))61 #define PTL2_ADDR(ptl1, page) ((pte_t *)PA2KA(GET_PTL2_ADDRESS_ARCH(ptl1, PTL1_INDEX_ARCH(page))))62 #define PTL3_ADDR(ptl2, page) ((pte_t *)PA2KA(GET_PTL3_ADDRESS_ARCH(ptl2, PTL2_INDEX_ARCH(page))))63 64 #define SETUP_PTL1(ptl0, page, tgt) { \65 SET_PTL1_ADDRESS_ARCH(ptl0, PTL0_INDEX_ARCH(page), (uintptr_t)KA2PA(tgt)); \66 SET_PTL1_FLAGS_ARCH(ptl0, PTL0_INDEX_ARCH(page), PAGE_WRITE | PAGE_EXEC); \67 }68 #define SETUP_PTL2(ptl1, page, tgt) { \69 SET_PTL2_ADDRESS_ARCH(ptl1, PTL1_INDEX_ARCH(page), (uintptr_t)KA2PA(tgt)); \70 SET_PTL2_FLAGS_ARCH(ptl1, PTL1_INDEX_ARCH(page), PAGE_WRITE | PAGE_EXEC); \71 }72 #define SETUP_PTL3(ptl2, page, tgt) { \73 SET_PTL3_ADDRESS_ARCH(ptl2, PTL2_INDEX_ARCH(page), (uintptr_t)KA2PA(tgt)); \74 SET_PTL3_FLAGS_ARCH(ptl2, PTL2_INDEX_ARCH(page), PAGE_WRITE | PAGE_EXEC); \75 }76 #define SETUP_FRAME(ptl3, page, tgt) { \77 SET_FRAME_ADDRESS_ARCH(ptl3, PTL3_INDEX_ARCH(page), (uintptr_t)KA2PA(tgt)); \78 SET_FRAME_FLAGS_ARCH(ptl3, PTL3_INDEX_ARCH(page), PAGE_WRITE | PAGE_EXEC); \79 }80 81 82 49 void page_arch_init(void) 83 50 { 84 uintptr_t cur;85 unsigned int i;86 int identity_flags = PAGE_CACHEABLE | PAGE_EXEC | PAGE_GLOBAL | PAGE_WRITE;87 88 51 if (config.cpu_active == 1) { 52 uintptr_t cur; 53 unsigned int identity_flags = 54 PAGE_CACHEABLE | PAGE_EXEC | PAGE_GLOBAL | PAGE_WRITE; 55 89 56 page_mapping_operations = &pt_mapping_operations; 90 57 91 58 page_table_lock(AS_KERNEL, true); 92 59 93 60 /* 94 61 * PA2KA(identity) mapping for all frames. 95 62 */ 96 for (cur = 0; cur < last_frame; cur += FRAME_SIZE) { 97 /* Standard identity mapping */ 63 for (cur = 0; cur < last_frame; cur += FRAME_SIZE) 98 64 page_mapping_insert(AS_KERNEL, PA2KA(cur), cur, identity_flags); 99 }100 65 101 /* Upper kernel mapping 102 * - from zero to top of kernel (include bottom addresses 103 * because some are needed for init) 104 */ 105 for (cur = PA2KA_CODE(0); cur < config.base + config.kernel_size; cur += FRAME_SIZE) 106 page_mapping_insert(AS_KERNEL, cur, KA2PA(cur), identity_flags); 66 page_table_unlock(AS_KERNEL, true); 107 67 108 for (cur = config.stack_base; cur < config.stack_base + config.stack_size; cur += FRAME_SIZE)109 page_mapping_insert(AS_KERNEL, cur, KA2PA(cur), identity_flags);110 111 for (i = 0; i < init.cnt; i++) {112 for (cur = init.tasks[i].addr; cur < init.tasks[i].addr + init.tasks[i].size; cur += FRAME_SIZE)113 page_mapping_insert(AS_KERNEL, PA2KA_CODE(KA2PA(cur)), KA2PA(cur), identity_flags);114 }115 116 page_table_unlock(AS_KERNEL, true);117 118 68 exc_register(14, "page_fault", true, (iroutine_t) page_fault); 119 69 write_cr3((uintptr_t) AS_KERNEL->genarch.page_table); … … 122 72 } 123 73 124 125 /** Identity page mapper126 *127 * We need to map whole physical memory identically before the page subsystem128 * is initializaed. This thing clears page table and fills in the specific129 * items.130 */131 void ident_page_fault(unsigned int n, istate_t *istate)132 {133 uintptr_t page;134 static uintptr_t oldpage = 0;135 pte_t *aptl_1, *aptl_2, *aptl_3;136 137 page = read_cr2();138 if (oldpage) {139 /* Unmap old address */140 aptl_1 = PTL1_ADDR(&ptl_0, oldpage);141 aptl_2 = PTL2_ADDR(aptl_1, oldpage);142 aptl_3 = PTL3_ADDR(aptl_2, oldpage);143 144 SET_FRAME_FLAGS_ARCH(aptl_3, PTL3_INDEX_ARCH(oldpage), PAGE_NOT_PRESENT);145 if (KA2PA(aptl_3) == KA2PA(helper_ptl3))146 SET_PTL3_FLAGS_ARCH(aptl_2, PTL2_INDEX_ARCH(oldpage), PAGE_NOT_PRESENT);147 if (KA2PA(aptl_2) == KA2PA(helper_ptl2))148 SET_PTL2_FLAGS_ARCH(aptl_1, PTL1_INDEX_ARCH(oldpage), PAGE_NOT_PRESENT);149 if (KA2PA(aptl_1) == KA2PA(helper_ptl1))150 SET_PTL1_FLAGS_ARCH(&ptl_0, PTL0_INDEX_ARCH(oldpage), PAGE_NOT_PRESENT);151 }152 if (PTL1_PRESENT(&ptl_0, page))153 aptl_1 = PTL1_ADDR(&ptl_0, page);154 else {155 SETUP_PTL1(&ptl_0, page, helper_ptl1);156 aptl_1 = helper_ptl1;157 }158 159 if (PTL2_PRESENT(aptl_1, page))160 aptl_2 = PTL2_ADDR(aptl_1, page);161 else {162 SETUP_PTL2(aptl_1, page, helper_ptl2);163 aptl_2 = helper_ptl2;164 }165 166 if (PTL3_PRESENT(aptl_2, page))167 aptl_3 = PTL3_ADDR(aptl_2, page);168 else {169 SETUP_PTL3(aptl_2, page, helper_ptl3);170 aptl_3 = helper_ptl3;171 }172 173 SETUP_FRAME(aptl_3, page, page);174 175 oldpage = page;176 }177 178 179 74 void page_fault(unsigned int n, istate_t *istate) 180 75 { 181 uintptr_t page; 182 pf_access_t access; 183 184 page = read_cr2(); 76 uintptr_t page = read_cr2(); 185 77 186 78 if (istate->error_word & PFERR_CODE_RSVD) 187 79 panic("Reserved bit set in page table entry."); 80 81 pf_access_t access; 188 82 189 83 if (istate->error_word & PFERR_CODE_RW) … … 196 90 if (as_page_fault(page, access, istate) == AS_PF_FAULT) { 197 91 fault_if_from_uspace(istate, "Page fault: %#x.", page); 198 199 decode_istate(n, istate); 200 printf("Page fault address: %llx.\n", page); 201 panic("Page fault."); 92 panic_memtrap(istate, access, page, "Page fault."); 202 93 } 203 94 } 204 205 95 206 96 uintptr_t hw_map(uintptr_t physaddr, size_t size) 207 97 { 208 98 if (last_frame + ALIGN_UP(size, PAGE_SIZE) > KA2PA(KERNEL_ADDRESS_SPACE_END_ARCH)) 209 panic("Unable to map physical memory %p (% dbytes).", physaddr,99 panic("Unable to map physical memory %p (%" PRIs " bytes).", physaddr, 210 100 size); 211 101 212 102 uintptr_t virtaddr = PA2KA(last_frame); 213 103 pfn_t i; 214 104 215 105 page_table_lock(AS_KERNEL, true); 106 216 107 for (i = 0; i < ADDR2PFN(ALIGN_UP(size, PAGE_SIZE)); i++) 217 108 page_mapping_insert(AS_KERNEL, virtaddr + PFN2ADDR(i), physaddr + PFN2ADDR(i), PAGE_NOT_CACHEABLE | PAGE_WRITE); 109 218 110 page_table_unlock(AS_KERNEL, true); 219 111 -
kernel/arch/amd64/src/proc/scheduler.c
rfe7abd0 rcefb126 38 38 #include <proc/thread.h> 39 39 #include <arch.h> 40 #include <arch/context.h> /* SP_DELTA */40 #include <arch/context.h> 41 41 #include <arch/asm.h> 42 42 #include <print.h> … … 58 58 CPU->arch.tss->rsp0 = 59 59 (uintptr_t) &THREAD->kstack[THREAD_STACK_SIZE - SP_DELTA]; 60 60 61 61 /* 62 62 * Syscall support. 63 63 */ 64 64 swapgs(); 65 write_msr(AMD_MSR_GS, (uintptr_t) THREAD->arch.syscall_rsp);65 write_msr(AMD_MSR_GS, (uintptr_t) THREAD->arch.syscall_rsp); 66 66 swapgs(); 67 67 68 68 /* TLS support - set FS to thread local storage */ 69 69 write_msr(AMD_MSR_FS, THREAD->arch.tls); -
kernel/arch/amd64/src/proc/task.c
rfe7abd0 rcefb126 39 39 /** Perform amd64 specific task initialization. 40 40 * 41 * @param t Task to be initialized. 41 * @param task Task to be initialized. 42 * 42 43 */ 43 void task_create_arch(task_t *t )44 void task_create_arch(task_t *task) 44 45 { 45 t ->arch.iomapver = 0;46 bitmap_initialize(&t ->arch.iomap, NULL, 0);46 task->arch.iomapver = 0; 47 bitmap_initialize(&task->arch.iomap, NULL, 0); 47 48 } 48 49 49 50 /** Perform amd64 specific task destruction. 50 51 * 51 * @param t Task to be initialized. 52 * @param task Task to be initialized. 53 * 52 54 */ 53 void task_destroy_arch(task_t *t )55 void task_destroy_arch(task_t *task) 54 56 { 55 if (t ->arch.iomap.map)56 free(t ->arch.iomap.map);57 if (task->arch.iomap.map) 58 free(task->arch.iomap.map); 57 59 } 58 60 -
kernel/arch/amd64/src/proc/thread.c
rfe7abd0 rcefb126 37 37 /** Perform amd64 specific thread initialization. 38 38 * 39 * @param t Thread to be initialized. 39 * @param thread Thread to be initialized. 40 * 40 41 */ 41 void thread_create_arch(thread_t *t )42 void thread_create_arch(thread_t *thread) 42 43 { 43 t->arch.tls = 0; 44 t->arch.syscall_rsp[SYSCALL_USTACK_RSP] = 0; 44 thread->arch.tls = 0; 45 thread->arch.syscall_rsp[SYSCALL_USTACK_RSP] = 0; 46 45 47 /* 46 48 * Kernel RSP can be precalculated at thread creation time. 47 49 */ 48 t ->arch.syscall_rsp[SYSCALL_KSTACK_RSP] =49 (uintptr_t) &t ->kstack[PAGE_SIZE - sizeof(uint64_t)];50 thread->arch.syscall_rsp[SYSCALL_KSTACK_RSP] = 51 (uintptr_t) &thread->kstack[PAGE_SIZE - sizeof(uint64_t)]; 50 52 } 51 53 -
kernel/arch/amd64/src/smp/ap.S
rfe7abd0 rcefb126 55 55 xorw %ax, %ax 56 56 movw %ax, %ds 57 58 lgdtl ap_gdtr # initialize Global Descriptor Table register57 58 lgdtl ap_gdtr # initialize Global Descriptor Table register 59 59 60 60 movl %cr0, %eax 61 61 orl $1, %eax 62 movl %eax, %cr0 # switch to protected mode62 movl %eax, %cr0 # switch to protected mode 63 63 jmpl $gdtselector(KTEXT32_DES), $jump_to_kernel - BOOT_OFFSET + AP_BOOT_OFFSET 64 64 65 65 jump_to_kernel: 66 66 .code32 … … 72 72 movw %ax, %gs 73 73 74 # Enable 64-bit page transaltion entries - CR4.PAE = 1.74 # Enable 64-bit page transaltion entries (CR4.PAE = 1). 75 75 # Paging is not enabled until after long mode is enabled 76 76 … … 78 78 btsl $5, %eax 79 79 movl %eax, %cr4 80 80 81 81 leal ptl_0, %eax 82 82 movl %eax, %cr3 83 83 84 84 # Enable long mode 85 movl $EFER_MSR_NUM, %ecx # EFER MSR number86 rdmsr # Read EFER87 btsl $AMD_LME_FLAG, %eax # Set LME=188 wrmsr # Write EFER85 movl $EFER_MSR_NUM, %ecx # EFER MSR number 86 rdmsr # Read EFER 87 btsl $AMD_LME_FLAG, %eax # Set LME=1 88 wrmsr # Write EFER 89 89 90 # Enable paging to activate long mode (set CR0.PG =1)90 # Enable paging to activate long mode (set CR0.PG = 1) 91 91 movl %cr0, %eax 92 92 btsl $31, %eax … … 98 98 .code64 99 99 start64: 100 movq (ctx), %rsp 100 movabsq $ctx, %rsp 101 movq (%rsp), %rsp 102 101 103 pushq $0 102 104 movq %rsp, %rbp 103 call main_ap - AP_BOOT_OFFSET + BOOT_OFFSET # never returns 105 106 movabsq $main_ap, %rax 107 callq *%rax # never returns 104 108 105 109 #endif /* CONFIG_SMP */ -
kernel/arch/arm32/Makefile.inc
rfe7abd0 rcefb126 46 46 arch/$(KARCH)/src/context.S \ 47 47 arch/$(KARCH)/src/dummy.S \ 48 arch/$(KARCH)/src/panic.S \49 48 arch/$(KARCH)/src/cpu/cpu.c \ 50 49 arch/$(KARCH)/src/ddi/ddi.c \ -
kernel/arch/arm32/include/exception.h
rfe7abd0 rcefb126 28 28 */ 29 29 30 /** @addtogroup arm32 30 /** @addtogroup arm32 31 31 * @{ 32 32 */ … … 141 141 extern void install_exception_handlers(void); 142 142 extern void exception_init(void); 143 extern void print_istate(istate_t *istate);144 143 extern void reset_exception_entry(void); 145 144 extern void irq_exception_entry(void); -
kernel/arch/arm32/include/mach/integratorcp/integratorcp.h
rfe7abd0 rcefb126 36 36 */ 37 37 38 #ifndef KERN_arm32_ MACHINE_H_39 #define KERN_arm32_ MACHINE_H_38 #ifndef KERN_arm32_icp_H_ 39 #define KERN_arm32_icp_H_ 40 40 41 41 #include <arch/machine_func.h> … … 106 106 extern void icp_frame_init(void); 107 107 108 extern struct arm_machine_ops icp_machine_ops; 109 108 110 #endif 109 111 -
kernel/arch/arm32/include/mach/testarm/testarm.h
rfe7abd0 rcefb126 37 37 */ 38 38 39 #ifndef KERN_arm32_ MACHINE_H_40 #define KERN_arm32_ MACHINE_H_39 #ifndef KERN_arm32_testarm_H_ 40 #define KERN_arm32_testarm_H_ 41 41 42 42 #include <arch/machine_func.h> … … 76 76 extern void gxemul_frame_init(void); 77 77 78 extern struct arm_machine_ops gxemul_machine_ops; 78 79 79 80 #endif -
kernel/arch/arm32/include/machine_func.h
rfe7abd0 rcefb126 46 46 #include <arch/exception.h> 47 47 48 #define MACHINE_GENFUNC machine_genfunc49 50 48 struct arm_machine_ops { 51 49 void (*machine_init)(void); … … 59 57 }; 60 58 61 extern struct arm_machine_ops machine_ops; 59 /** Pointer to arm_machine_ops structure being used. */ 60 extern struct arm_machine_ops *machine_ops; 62 61 62 /** Initialize machine_ops pointer. */ 63 extern void machine_ops_init(void); 63 64 64 65 /** Maps HW devices to the kernel address space using #hw_map. */ … … 104 105 extern void machine_input_init(void); 105 106 106 extern void machine_genfunc(void);107 107 #endif 108 108 -
kernel/arch/arm32/src/arm32.c
rfe7abd0 rcefb126 45 45 #include <interrupt.h> 46 46 #include <arch/regutils.h> 47 #include <arch/machine_func.h> 47 48 #include <userspace.h> 48 49 #include <macros.h> 49 50 #include <str.h> 50 51 #include <arch/ras.h> 51 52 #ifdef MACHINE_testarm53 #include <arch/mach/testarm/testarm.h>54 #endif55 56 #ifdef MACHINE_integratorcp57 #include <arch/mach/integratorcp/integratorcp.h>58 #endif59 60 52 61 53 /** Performs arm32-specific initialization before main_bsp() is called. */ … … 71 63 bootinfo->tasks[i].name); 72 64 } 65 66 /* Initialize machine_ops pointer. */ 67 machine_ops_init(); 73 68 } 74 69 -
kernel/arch/arm32/src/asm.S
rfe7abd0 rcefb126 1 # 2 #Copyright (c) 2007 Michal Kebrt3 #All rights reserved.4 # 5 #Redistribution and use in source and binary forms, with or without6 #modification, are permitted provided that the following conditions7 #are met:8 # 9 #- Redistributions of source code must retain the above copyright10 #notice, this list of conditions and the following disclaimer.11 #- Redistributions in binary form must reproduce the above copyright12 #notice, this list of conditions and the following disclaimer in the13 #documentation and/or other materials provided with the distribution.14 #- The name of the author may not be used to endorse or promote products15 #derived from this software without specific prior written permission.16 # 17 #THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR18 #IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES19 #OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.20 #IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,21 #INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT22 #NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,23 #DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY24 #THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT25 #(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF26 #THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.27 # 1 /* 2 * Copyright (c) 2007 Michal Kebrt 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * - Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * - Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * - The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 28 29 30 29 .text 31 30 … … 37 36 .global memcpy_from_uspace_failover_address 38 37 .global memcpy_to_uspace_failover_address 38 .global early_putchar 39 39 40 40 memsetb: … … 47 47 memcpy_from_uspace: 48 48 memcpy_to_uspace: 49 add r3, r1, #3 50 bic r3, r3, #3 51 cmp r1, r3 52 stmdb sp!, {r4, r5, lr} 53 mov r5, r0 /* save dst */ 54 beq 4f 55 1: 56 cmp r2, #0 57 movne ip, #0 58 beq 3f 59 2: 60 ldrb r3, [ip, r1] 61 strb r3, [ip, r0] 62 add ip, ip, #1 63 cmp ip, r2 64 bne 2b 65 3: 66 mov r0, r5 67 ldmia sp!, {r4, r5, pc} 68 4: 69 add r3, r0, #3 70 bic r3, r3, #3 71 cmp r0, r3 72 bne 1b 73 movs r4, r2, lsr #2 74 moveq lr, r4 75 beq 6f 76 mov lr, #0 77 mov ip, lr 78 5: 79 ldr r3, [ip, r1] 80 add lr, lr, #1 81 cmp lr, r4 82 str r3, [ip, r0] 83 add ip, ip, #4 84 bne 5b 85 6: 86 ands r4, r2, #3 87 beq 3b 88 mov r3, lr, lsl #2 89 add r0, r3, r0 90 add ip, r3, r1 91 mov r2, #0 92 7: 93 ldrb r3, [r2, ip] 94 strb r3, [r2, r0] 95 add r2, r2, #1 96 cmp r2, r4 97 bne 7b 98 b 3b 49 add r3, r1, #3 50 bic r3, r3, #3 51 cmp r1, r3 52 stmdb sp!, {r4, r5, lr} 53 mov r5, r0 /* save dst */ 54 beq 4f 55 56 1: 57 cmp r2, #0 58 movne ip, #0 59 beq 3f 60 61 2: 62 ldrb r3, [ip, r1] 63 strb r3, [ip, r0] 64 add ip, ip, #1 65 cmp ip, r2 66 bne 2b 67 68 3: 69 mov r0, r5 70 ldmia sp!, {r4, r5, pc} 71 72 4: 73 add r3, r0, #3 74 bic r3, r3, #3 75 cmp r0, r3 76 bne 1b 77 movs r4, r2, lsr #2 78 moveq lr, r4 79 beq 6f 80 mov lr, #0 81 mov ip, lr 82 83 5: 84 ldr r3, [ip, r1] 85 add lr, lr, #1 86 cmp lr, r4 87 str r3, [ip, r0] 88 add ip, ip, #4 89 bne 5b 90 91 6: 92 ands r4, r2, #3 93 beq 3b 94 mov r3, lr, lsl #2 95 add r0, r3, r0 96 add ip, r3, r1 97 mov r2, #0 98 99 7: 100 ldrb r3, [r2, ip] 101 strb r3, [r2, r0] 102 add r2, r2, #1 103 cmp r2, r4 104 bne 7b 105 b 3b 99 106 100 107 memcpy_from_uspace_failover_address: 101 108 memcpy_to_uspace_failover_address: 102 mov r0, #0 103 ldmia sp!, {r4, r5, pc} 109 mov r0, #0 110 ldmia sp!, {r4, r5, pc} 111 112 early_putchar: 113 mov pc, lr -
kernel/arch/arm32/src/exc_handler.S
rfe7abd0 rcefb126 98 98 stmfd r13!, {r13, lr}^ 99 99 stmfd r13!, {r2} 100 101 # Stop stack traces here 102 mov fp, #0 103 100 104 b 2f 101 105 … … 123 127 stmfd r13!, {r2} 124 128 2: 125 # Stop stack traces here126 mov fp, #0127 129 .endm 128 130 -
kernel/arch/arm32/src/exception.c
rfe7abd0 rcefb126 37 37 #include <arch/memstr.h> 38 38 #include <arch/regutils.h> 39 #include <arch/machine_func.h> 39 40 #include <interrupt.h> 40 41 #include <arch/mm/page_fault.h> … … 43 44 #include <syscall/syscall.h> 44 45 #include <stacktrace.h> 45 46 #ifdef MACHINE_testarm47 #include <arch/mach/testarm/testarm.h>48 #endif49 50 #ifdef MACHINE_integratorcp51 #include <arch/mach/integratorcp/integratorcp.h>52 #endif53 46 54 47 /** Offset used in calculation of exception handler's relative address. … … 180 173 * @param istate Structure to be printed. 181 174 */ 182 void print_istate(istate_t *istate)175 void istate_decode(istate_t *istate) 183 176 { 184 printf("istate dump:\n"); 185 186 printf(" r0: %x r1: %x r2: %x r3: %x\n", 177 printf("r0 =%#0.8lx\tr1 =%#0.8lx\tr2 =%#0.8lx\tr3 =%#0.8lx\n", 187 178 istate->r0, istate->r1, istate->r2, istate->r3); 188 printf(" r4: %x r5: %x r6: %x r7: %x\n",179 printf("r4 =%#0.8lx\tr5 =%#0.8lx\tr6 =%#0.8lx\tr7 =%#0.8lx\n", 189 180 istate->r4, istate->r5, istate->r6, istate->r7); 190 printf(" r8: %x r8: %x r10: %x fp: %x\n",181 printf("r8 =%#0.8lx\tr9 =%#0.8lx\tr10=%#0.8lx\tfp =%#0.8lx\n", 191 182 istate->r8, istate->r9, istate->r10, istate->fp); 192 printf(" r12: %x sp: %x lr: %x spsr: %x\n",183 printf("r12=%#0.8lx\tsp =%#0.8lx\tlr =%#0.8lx\tspsr=%#0.8lx\n", 193 184 istate->r12, istate->sp, istate->lr, istate->spsr); 194 195 printf(" pc: %x\n", istate->pc);196 197 stack_trace_istate(istate);198 185 } 199 186 -
kernel/arch/arm32/src/interrupt.c
rfe7abd0 rcefb126 36 36 #include <arch/asm.h> 37 37 #include <arch/regutils.h> 38 #include <arch/machine_func.h> 38 39 #include <ddi/irq.h> 39 40 #include <ddi/device.h> 40 41 #include <interrupt.h> 41 42 #ifdef MACHINE_testarm43 #include <arch/mach/testarm/testarm.h>44 #endif45 46 #ifdef MACHINE_integratorcp47 #include <arch/mach/integratorcp/integratorcp.h>48 #endif49 42 50 43 /** Initial size of a table holding interrupt handlers. */ -
kernel/arch/arm32/src/mach/integratorcp/integratorcp.c
rfe7abd0 rcefb126 56 56 static icp_hw_map_t icp_hw_map; 57 57 static irq_t icp_timer_irq; 58 struct arm_machine_ops machine_ops = {58 struct arm_machine_ops icp_machine_ops = { 59 59 icp_init, 60 60 icp_timer_irq_start, -
kernel/arch/arm32/src/mach/testarm/testarm.c
rfe7abd0 rcefb126 56 56 static irq_t gxemul_timer_irq; 57 57 58 struct arm_machine_ops machine_ops = {58 struct arm_machine_ops gxemul_machine_ops = { 59 59 gxemul_init, 60 60 gxemul_timer_irq_start, -
kernel/arch/arm32/src/machine_func.c
rfe7abd0 rcefb126 39 39 40 40 #include <arch/machine_func.h> 41 #include <arch/mach/integratorcp/integratorcp.h> 42 #include <arch/mach/testarm/testarm.h> 41 43 44 /** Pointer to machine_ops structure being used. */ 45 struct arm_machine_ops *machine_ops; 46 47 /** Initialize machine_ops pointer. */ 48 void machine_ops_init(void) 49 { 50 #if defined(MACHINE_testarm) 51 machine_ops = &gxemul_machine_ops; 52 #elif defined(MACHINE_integratorcp) 53 machine_ops = &icp_machine_ops; 54 #else 55 #error Machine type not defined. 56 #endif 57 } 42 58 43 59 /** Maps HW devices to the kernel address space using #hw_map. */ 44 60 void machine_init(void) 45 61 { 46 (machine_ops .machine_init)();62 (machine_ops->machine_init)(); 47 63 } 48 64 … … 51 67 void machine_timer_irq_start(void) 52 68 { 53 (machine_ops .machine_timer_irq_start)();69 (machine_ops->machine_timer_irq_start)(); 54 70 } 55 71 … … 58 74 void machine_cpu_halt(void) 59 75 { 60 (machine_ops .machine_cpu_halt)();76 (machine_ops->machine_cpu_halt)(); 61 77 } 62 78 … … 68 84 uintptr_t machine_get_memory_size(void) 69 85 { 70 return (machine_ops .machine_get_memory_size)();86 return (machine_ops->machine_get_memory_size)(); 71 87 } 72 88 … … 78 94 void machine_irq_exception(unsigned int exc_no, istate_t *istate) 79 95 { 80 (machine_ops .machine_irq_exception)(exc_no, istate);96 (machine_ops->machine_irq_exception)(exc_no, istate); 81 97 } 82 98 … … 87 103 void machine_frame_init(void) 88 104 { 89 (machine_ops .machine_frame_init)();105 (machine_ops->machine_frame_init)(); 90 106 } 91 107 … … 95 111 void machine_output_init(void) 96 112 { 97 (machine_ops .machine_output_init)();113 (machine_ops->machine_output_init)(); 98 114 } 99 115 … … 103 119 void machine_input_init(void) 104 120 { 105 (machine_ops.machine_input_init)(); 106 } 107 108 /* 109 * Generic function to use, if sepcific function doesn't define any of the above functions. 110 */ 111 void machine_genfunc() 112 { 121 (machine_ops->machine_input_init)(); 113 122 } 114 123 -
kernel/arch/arm32/src/mm/frame.c
rfe7abd0 rcefb126 36 36 #include <mm/frame.h> 37 37 #include <arch/mm/frame.h> 38 #include <arch/machine_func.h> 38 39 #include <config.h> 39 40 #ifdef MACHINE_testarm41 #include <arch/mach/testarm/testarm.h>42 #endif43 44 #ifdef MACHINE_integratorcp45 #include <arch/mach/integratorcp/integratorcp.h>46 #endif47 40 48 41 /** Address of the last frame in the memory. */ -
kernel/arch/arm32/src/mm/page.c
rfe7abd0 rcefb126 27 27 */ 28 28 29 /** @addtogroup arm32mm 29 /** @addtogroup arm32mm 30 30 * @{ 31 31 */ -
kernel/arch/arm32/src/mm/page_fault.c
rfe7abd0 rcefb126 183 183 if (ret == AS_PF_FAULT) { 184 184 fault_if_from_uspace(istate, "Page fault: %#x.", badvaddr); 185 print_istate(istate); 186 printf("page fault - pc: %x, va: %x, status: %x(%x), " 187 "access:%d\n", istate->pc, badvaddr, fsr.status, fsr, 188 access); 189 190 panic("Page fault."); 185 panic_memtrap(istate, access, badvaddr, "Page fault."); 191 186 } 192 187 } … … 203 198 204 199 if (ret == AS_PF_FAULT) { 205 printf("prefetch_abort\n"); 206 print_istate(istate); 207 panic("page fault - prefetch_abort at address: %x.", 208 istate->pc); 200 panic_memtrap(istate, PF_ACCESS_EXEC, istate->pc, 201 "Page fault - prefetch_abort."); 209 202 } 210 203 } -
kernel/arch/ia32/Makefile.inc
rfe7abd0 rcefb126 76 76 ARCH_SOURCES = \ 77 77 arch/$(KARCH)/src/context.S \ 78 arch/$(KARCH)/src/debug/panic.s \79 78 arch/$(KARCH)/src/debug/stacktrace.c \ 80 79 arch/$(KARCH)/src/debug/stacktrace_asm.S \ -
kernel/arch/ia32/include/bios/bios.h
rfe7abd0 rcefb126 27 27 */ 28 28 29 /** @addtogroup ia32 29 /** @addtogroup ia32 30 30 * @{ 31 31 */ … … 38 38 #include <typedefs.h> 39 39 40 #define BIOS_EBDA_PTR 0x40e40 #define BIOS_EBDA_PTR 0x40e 41 41 42 42 extern uintptr_t ebda; -
kernel/arch/ia32/include/drivers/i8259.h
rfe7abd0 rcefb126 48 48 49 49 extern void i8259_init(void); 50 extern void pic_enable_irqs(uint16_t irqmask);51 extern void pic_disable_irqs(uint16_t irqmask);50 extern void pic_enable_irqs(uint16_t); 51 extern void pic_disable_irqs(uint16_t); 52 52 extern void pic_eoi(void); 53 53 -
kernel/arch/ia32/include/fpu_context.h
rfe7abd0 rcefb126 27 27 */ 28 28 29 /** @addtogroup ia32 29 /** @addtogroup ia32 30 30 * @{ 31 31 */ … … 38 38 #include <typedefs.h> 39 39 40 #define FPU_CONTEXT_ALIGN 16 41 42 void fpu_fxsr(void); 43 void fpu_fsr(void); 44 40 #define FPU_CONTEXT_ALIGN 16 45 41 46 42 typedef struct { 47 uint8_t fpu[512]; /* FXSAVE & FXRSTOR storage area */43 uint8_t fpu[512]; /* FXSAVE & FXRSTOR storage area */ 48 44 } fpu_context_t; 45 46 extern void fpu_fxsr(void); 47 extern void fpu_fsr(void); 49 48 50 49 #endif -
kernel/arch/ia32/include/interrupt.h
rfe7abd0 rcefb126 72 72 typedef struct istate { 73 73 uint32_t eax; 74 uint32_t ebx; 74 75 uint32_t ecx; 75 76 uint32_t edx; 77 uint32_t edi; 78 uint32_t esi; 76 79 uint32_t ebp; 80 81 uint32_t ebp_frame; /* imitation of frame pointer linkage */ 82 uint32_t eip_frame; /* imitation of return address linkage */ 77 83 78 84 uint32_t gs; … … 81 87 uint32_t ds; 82 88 83 uint32_t error_word; 89 uint32_t error_word; /* real or fake error word */ 84 90 uint32_t eip; 85 91 uint32_t cs; 86 92 uint32_t eflags; 87 uint32_t stack[]; 93 uint32_t esp; /* only if istate_t is from uspace */ 94 uint32_t ss; /* only if istate_t is from uspace */ 88 95 } istate_t; 89 96 … … 113 120 extern void (* eoi_function)(void); 114 121 115 extern void decode_istate(istate_t *istate);116 122 extern void interrupt_init(void); 117 123 extern void trap_virtual_enable_irqs(uint16_t irqmask); -
kernel/arch/ia32/include/mm/asid.h
rfe7abd0 rcefb126 27 27 */ 28 28 29 /** @addtogroup ia32mm 29 /** @addtogroup ia32mm 30 30 * @{ 31 31 */ … … 47 47 typedef int32_t asid_t; 48 48 49 #define ASID_MAX_ARCH 349 #define ASID_MAX_ARCH 3 50 50 51 #define asid_get() (ASID_START + 1)51 #define asid_get() (ASID_START + 1) 52 52 #define asid_put(asid) 53 53 -
kernel/arch/ia32/include/smp/apic.h
rfe7abd0 rcefb126 347 347 348 348 extern uint32_t apic_id_mask; 349 extern uint8_t bsp_l_apic; 349 350 350 351 extern void apic_init(void); … … 355 356 extern int l_apic_send_init_ipi(uint8_t); 356 357 extern void l_apic_debug(void); 357 extern uint8_t l_apic_id(void);358 358 359 359 extern uint32_t io_apic_read(uint8_t); -
kernel/arch/ia32/include/smp/mps.h
rfe7abd0 rcefb126 27 27 */ 28 28 29 /** @addtogroup ia32 29 /** @addtogroup ia32 30 30 * @{ 31 31 */ … … 41 41 #include <arch/smp/smp.h> 42 42 43 #define CT_EXT_ENTRY_TYPE 044 #define CT_EXT_ENTRY_LEN 143 #define CT_EXT_ENTRY_TYPE 0 44 #define CT_EXT_ENTRY_LEN 1 45 45 46 46 struct mps_fs { … … 70 70 uint16_t ext_table_length; 71 71 uint8_t ext_table_checksum; 72 uint8_t xxx;72 uint8_t reserved; 73 73 uint8_t base_table[0]; 74 74 } __attribute__ ((packed)); … … 81 81 uint8_t cpu_signature[4]; 82 82 uint32_t feature_flags; 83 uint32_t xxx[2];83 uint32_t reserved[2]; 84 84 } __attribute__ ((packed)); 85 85 … … 102 102 uint8_t intr_type; 103 103 uint8_t poel; 104 uint8_t xxx;104 uint8_t reserved; 105 105 uint8_t src_bus_id; 106 106 uint8_t src_bus_irq; … … 113 113 uint8_t intr_type; 114 114 uint8_t poel; 115 uint8_t xxx;115 uint8_t reserved; 116 116 uint8_t src_bus_id; 117 117 uint8_t src_bus_irq; -
kernel/arch/ia32/include/smp/smp.h
rfe7abd0 rcefb126 27 27 */ 28 28 29 /** @addtogroup ia32 29 /** @addtogroup ia32 30 30 * @{ 31 31 */ … … 40 40 /** SMP config opertaions interface. */ 41 41 struct smp_config_operations { 42 size_t (* cpu_count)(void); /**< Return number of detected processors. */ 43 bool (* cpu_enabled)(size_t i); /**< Check whether the processor of index i is enabled. */ 44 bool (*cpu_bootstrap)(size_t i); /**< Check whether the processor of index i is BSP. */ 45 uint8_t (*cpu_apic_id)(size_t i); /**< Return APIC ID of the processor of index i. */ 46 int (*irq_to_pin)(unsigned int irq); /**< Return mapping between irq and APIC pin. */ 42 /** Check whether a processor is enabled. */ 43 bool (* cpu_enabled)(size_t); 44 45 /** Check whether a processor is BSP. */ 46 bool (*cpu_bootstrap)(size_t); 47 48 /** Return APIC ID of a processor. */ 49 uint8_t (*cpu_apic_id)(size_t); 50 51 /** Return mapping between IRQ and APIC pin. */ 52 int (*irq_to_pin)(unsigned int); 47 53 }; 48 54 49 extern int smp_irq_to_pin(unsigned int irq);55 extern int smp_irq_to_pin(unsigned int); 50 56 51 57 #endif -
kernel/arch/ia32/src/asm.S
rfe7abd0 rcefb126 1 # 2 # Copyright (c) 2001-2004 Jakub Jermar 3 # All rights reserved. 4 # 5 # Redistribution and use in source and binary forms, with or without 6 # modification, are permitted provided that the following conditions 7 # are met: 8 # 9 # - Redistributions of source code must retain the above copyright 10 # notice, this list of conditions and the following disclaimer. 11 # - Redistributions in binary form must reproduce the above copyright 12 # notice, this list of conditions and the following disclaimer in the 13 # documentation and/or other materials provided with the distribution. 14 # - The name of the author may not be used to endorse or promote products 15 # derived from this software without specific prior written permission. 16 # 17 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 # 28 29 ## very low and hardware-level functions 30 31 # Mask for interrupts 0 - 31 (bits 0 - 31) where 0 means that int has no error 32 # word and 1 means interrupt with error word 33 #define ERROR_WORD_INTERRUPT_LIST 0x00027d00 1 /* 2 * Copyright (c) 2001 Jakub Jermar 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * - Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * - Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * - The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 /** Very low and hardware-level functions 30 * 31 */ 32 33 /** 34 * Mask for interrupts 0 - 31 (bits 0 - 31) where 0 means that int 35 * has no error word and 1 means interrupt with error word 36 * 37 */ 38 #define ERROR_WORD_INTERRUPT_LIST 0x00027d00 39 40 #include <arch/pm.h> 41 #include <arch/mm/page.h> 34 42 35 43 .text 36 37 44 .global paging_on 38 45 .global enable_l_apic_in_msr … … 45 52 .global memcpy_to_uspace 46 53 .global memcpy_to_uspace_failover_address 47 48 49 # Wrapper for generic memsetb 54 .global early_putchar 55 56 /* Wrapper for generic memsetb */ 50 57 memsetb: 51 58 jmp _memsetb 52 59 53 # Wrapper for generic memsetw 60 /* Wrapper for generic memsetw */ 54 61 memsetw: 55 62 jmp _memsetw 56 63 57 58 #define MEMCPY_DST 4 59 #define MEMCPY_SRC 8 60 #define MEMCPY_SIZE 12 64 #define MEMCPY_DST 4 65 #define MEMCPY_SRC 8 66 #define MEMCPY_SIZE 12 61 67 62 68 /** Copy memory to/from userspace. … … 68 74 * or copy_to_uspace(). 69 75 * 70 * @param MEMCPY_DST(%esp) Destination address.71 * @param MEMCPY_SRC(%esp) Source address.72 * @param MEMCPY_SIZE(%esp) Size.76 * @param MEMCPY_DST(%esp) Destination address. 77 * @param MEMCPY_SRC(%esp) Source address. 78 * @param MEMCPY_SIZE(%esp) Size. 73 79 * 74 80 * @return MEMCPY_DST(%esp) on success and 0 on failure. 81 * 75 82 */ 76 83 memcpy: 77 84 memcpy_from_uspace: 78 85 memcpy_to_uspace: 79 movl %edi, %edx /* save %edi */80 movl %esi, %eax /* save %esi */86 movl %edi, %edx /* save %edi */ 87 movl %esi, %eax /* save %esi */ 81 88 82 89 movl MEMCPY_SIZE(%esp), %ecx 83 shrl $2, %ecx /* size / 4 */90 shrl $2, %ecx /* size / 4 */ 84 91 85 92 movl MEMCPY_DST(%esp), %edi 86 93 movl MEMCPY_SRC(%esp), %esi 87 94 88 rep movsl /* copy whole words */ 89 95 /* Copy whole words */ 96 rep movsl 97 90 98 movl MEMCPY_SIZE(%esp), %ecx 91 andl $3, %ecx /* size % 4 */99 andl $3, %ecx /* size % 4 */ 92 100 jz 0f 93 101 94 rep movsb /* copy the rest byte by byte */ 95 96 0: 97 movl %edx, %edi 98 movl %eax, %esi 99 movl MEMCPY_DST(%esp), %eax /* MEMCPY_DST(%esp), success */ 100 ret 101 102 /* Copy the rest byte by byte */ 103 rep movsb 104 105 0: 106 107 movl %edx, %edi 108 movl %eax, %esi 109 110 /* MEMCPY_DST(%esp), success */ 111 movl MEMCPY_DST(%esp), %eax 112 ret 113 102 114 /* 103 115 * We got here from as_page_fault() after the memory operations … … 108 120 movl %edx, %edi 109 121 movl %eax, %esi 110 xorl %eax, %eax /* return 0, failure */ 122 123 /* Return 0, failure */ 124 xorl %eax, %eax 111 125 ret 112 126 113 ## Turn paging on 114 # 115 # Enable paging and write-back caching in CR0. 116 # 127 /** Turn paging on 128 * 129 * Enable paging and write-back caching in CR0. 130 * 131 */ 117 132 paging_on: 118 133 movl %cr0, %edx 119 orl $(1 << 31), %edx # paging on 120 # clear Cache Disable and not Write Though 134 orl $(1 << 31), %edx /* paging on */ 135 136 /* Clear Cache Disable and not Write Though */ 121 137 andl $~((1 << 30) | (1 << 29)), %edx 122 movl %edx, %cr0138 movl %edx, %cr0 123 139 jmp 0f 124 0: 125 ret 126 127 128 ## Enable local APIC 129 # 130 # Enable local APIC in MSR. 131 # 140 141 0: 142 ret 143 144 /** Enable local APIC 145 * 146 * Enable local APIC in MSR. 147 * 148 */ 132 149 enable_l_apic_in_msr: 133 150 movl $0x1b, %ecx … … 138 155 ret 139 156 140 # Clear nested flag 141 # overwrites %ecx 157 /** Clear nested flag 158 * 159 */ 142 160 .macro CLEAR_NT_FLAG 143 161 pushfl 144 pop %ecx 145 and $0xffffbfff, %ecx 146 push %ecx 162 andl $0xffffbfff, (%esp) 147 163 popfl 148 .endm 164 .endm 149 165 150 166 /* … … 160 176 sysenter_handler: 161 177 sti 162 pushl %ebp # remember user stack 163 pushl %edi # remember return user address 164 165 pushl %gs # remember TLS 166 167 pushl %eax # syscall number 168 subl $8, %esp # unused sixth and fifth argument 169 pushl %esi # fourth argument 170 pushl %ebx # third argument 171 pushl %ecx # second argument 172 pushl %edx # first argument 173 178 pushl %ebp /* remember user stack */ 179 pushl %edi /* remember return user address */ 180 181 xorl %ebp, %ebp /* stop stack traces here */ 182 183 pushl %gs /* remember TLS */ 184 185 pushl %eax /* syscall number */ 186 subl $8, %esp /* unused sixth and fifth argument */ 187 pushl %esi /* fourth argument */ 188 pushl %ebx /* third argument */ 189 pushl %ecx /* second argument */ 190 pushl %edx /* first argument */ 191 174 192 movw $16, %ax 175 193 movw %ax, %ds 176 194 movw %ax, %es 177 195 178 196 cld 179 197 call syscall_handler 180 addl $28, %esp # remove arguments from stack 181 182 pop %gs # restore TLS 183 184 pop %edx # prepare return EIP for SYSEXIT 185 pop %ecx # prepare userspace ESP for SYSEXIT 186 187 sysexit # return to userspace 188 189 190 ## Declare interrupt handlers 191 # 192 # Declare interrupt handlers for n interrupt 193 # vectors starting at vector i. 194 # 195 # The handlers setup data segment registers 196 # and call exc_dispatch(). 197 # 198 #define INTERRUPT_ALIGN 64 198 addl $28, %esp /* remove arguments from stack */ 199 200 pop %gs /* restore TLS */ 201 202 pop %edx /* prepare return EIP for SYSEXIT */ 203 pop %ecx /* prepare userspace ESP for SYSEXIT */ 204 205 sysexit /* return to userspace */ 206 207 #define ISTATE_OFFSET_EAX 0 208 #define ISTATE_OFFSET_EBX 4 209 #define ISTATE_OFFSET_ECX 8 210 #define ISTATE_OFFSET_EDX 12 211 #define ISTATE_OFFSET_EDI 16 212 #define ISTATE_OFFSET_ESI 20 213 #define ISTATE_OFFSET_EBP 24 214 #define ISTATE_OFFSET_EBP_FRAME 28 215 #define ISTATE_OFFSET_EIP_FRAME 32 216 #define ISTATE_OFFSET_GS 36 217 #define ISTATE_OFFSET_FS 40 218 #define ISTATE_OFFSET_ES 44 219 #define ISTATE_OFFSET_DS 48 220 #define ISTATE_OFFSET_ERROR_WORD 52 221 #define ISTATE_OFFSET_EIP 56 222 #define ISTATE_OFFSET_CS 60 223 #define ISTATE_OFFSET_EFLAGS 64 224 #define ISTATE_OFFSET_ESP 68 225 #define ISTATE_OFFSET_SS 72 226 227 /* 228 * Size of the istate structure without the hardware-saved part 229 * and without the error word. 230 */ 231 #define ISTATE_SOFT_SIZE 52 232 233 /** Declare interrupt handlers 234 * 235 * Declare interrupt handlers for n interrupt 236 * vectors starting at vector i. 237 * 238 * The handlers setup data segment registers 239 * and call exc_dispatch(). 240 * 241 */ 242 #define INTERRUPT_ALIGN 256 243 199 244 .macro handler i n 200 201 .ifeq \i - 0x30 # Syscall handler245 .ifeq \i - 0x30 246 /* Syscall handler */ 202 247 pushl %ds 203 248 pushl %es … … 205 250 pushl %gs 206 251 207 # 208 # Push syscall arguments onto the stack 209 # 210 # NOTE: The idea behind the order of arguments passed in registers is to 211 # use all scratch registers first and preserved registers next. 212 # An optimized libc syscall wrapper can make use of this setup. 213 # 252 /* 253 * Push syscall arguments onto the stack 254 * 255 * NOTE: The idea behind the order of arguments passed 256 * in registers is to use all scratch registers 257 * first and preserved registers next. An optimized 258 * libc syscall wrapper can make use of this setup. 259 * 260 */ 214 261 pushl %eax 215 262 pushl %ebp … … 220 267 pushl %edx 221 268 222 # we must fill the data segment registers269 /* We must fill the data segment registers */ 223 270 movw $16, %ax 224 271 movw %ax, %ds 225 272 movw %ax, %es 226 273 274 xorl %ebp, %ebp 275 227 276 cld 228 277 sti 229 # syscall_handler(edx, ecx, ebx, esi, edi, ebp, eax) 278 279 /* Call syscall_handler(edx, ecx, ebx, esi, edi, ebp, eax) */ 230 280 call syscall_handler 231 281 cli 232 addl $28, %esp # clean-up of parameters 282 283 movl 20(%esp), %ebp /* restore EBP */ 284 addl $28, %esp /* clean-up of parameters */ 233 285 234 286 popl %gs … … 241 293 .else 242 294 /* 243 * This macro distinguishes between two versions of ia32 exceptions. 244 * One version has error word and the other does not have it. 245 * The latter version fakes the error word on the stack so that the 246 * handlers and istate_t can be the same for both types. 295 * This macro distinguishes between two versions of ia32 296 * exceptions. One version has error word and the other 297 * does not have it. The latter version fakes the error 298 * word on the stack so that the handlers and istate_t 299 * can be the same for both types. 247 300 */ 248 301 .iflt \i - 32 249 302 .if (1 << \i) & ERROR_WORD_INTERRUPT_LIST 250 303 /* 251 * With error word,do nothing304 * Exception with error word: do nothing 252 305 */ 253 306 .else 254 307 /* 255 * Version without error word308 * Exception without error word: fake up one 256 309 */ 257 subl $4, %esp310 pushl $0 258 311 .endif 259 312 .else 260 313 /* 261 * Version without error word314 * Interrupt: fake up one 262 315 */ 263 subl $4, %esp316 pushl $0 264 317 .endif 265 318 266 pushl %ds 267 pushl %es 268 pushl %fs 269 pushl %gs 270 271 pushl %ebp 272 pushl %edx 273 pushl %ecx 274 pushl %eax 275 276 # we must fill the data segment registers 277 278 movw $16, %ax 279 movw %ax, %ds 280 movw %ax, %es 281 282 # stop stack traces here 319 subl $ISTATE_SOFT_SIZE, %esp 320 321 /* 322 * Save the general purpose registers. 323 */ 324 movl %eax, ISTATE_OFFSET_EAX(%esp) 325 movl %ebx, ISTATE_OFFSET_EBX(%esp) 326 movl %ecx, ISTATE_OFFSET_ECX(%esp) 327 movl %edx, ISTATE_OFFSET_EDX(%esp) 328 movl %edi, ISTATE_OFFSET_EDI(%esp) 329 movl %esi, ISTATE_OFFSET_ESI(%esp) 330 movl %ebp, ISTATE_OFFSET_EBP(%esp) 331 332 /* 333 * Save the selector registers. 334 */ 335 movl %gs, %eax 336 movl %fs, %ebx 337 movl %es, %ecx 338 movl %ds, %edx 339 340 movl %eax, ISTATE_OFFSET_GS(%esp) 341 movl %ebx, ISTATE_OFFSET_FS(%esp) 342 movl %ecx, ISTATE_OFFSET_ES(%esp) 343 movl %edx, ISTATE_OFFSET_DS(%esp) 344 345 /* 346 * Switch to kernel selectors. 347 */ 348 movl $16, %eax 349 movl %eax, %ds 350 movl %eax, %es 351 352 /* 353 * Imitate a regular stack frame linkage. 354 * Stop stack traces here if we came from userspace. 355 */ 356 cmpl $8, ISTATE_OFFSET_CS(%esp) 357 jz 0f 283 358 xorl %ebp, %ebp 284 359 285 pushl %esp # *istate 286 pushl $(\i) # intnum 287 call exc_dispatch # exc_dispatch(intnum, *istate) 288 addl $8, %esp # Clear arguments from stack 289 290 CLEAR_NT_FLAG # Modifies %ecx 291 292 popl %eax 293 popl %ecx 294 popl %edx 295 popl %ebp 296 297 popl %gs 298 popl %fs 299 popl %es 300 popl %ds 301 302 # skip error word, no matter whether real or fake 303 addl $4, %esp 304 iret 360 0: 361 362 movl %ebp, ISTATE_OFFSET_EBP_FRAME(%esp) 363 movl ISTATE_OFFSET_EIP(%esp), %eax 364 movl %eax, ISTATE_OFFSET_EIP_FRAME(%esp) 365 leal ISTATE_OFFSET_EBP_FRAME(%esp), %ebp 366 367 cld 368 369 pushl %esp /* pass istate address */ 370 pushl $(\i) /* pass intnum */ 371 372 /* Call exc_dispatch(intnum, istate) */ 373 call exc_dispatch 374 375 addl $8, %esp /* clear arguments from the stack */ 376 377 CLEAR_NT_FLAG 378 379 /* 380 * Restore the selector registers. 381 */ 382 movl ISTATE_OFFSET_GS(%esp), %eax 383 movl ISTATE_OFFSET_FS(%esp), %ebx 384 movl ISTATE_OFFSET_ES(%esp), %ecx 385 movl ISTATE_OFFSET_DS(%esp), %edx 386 387 movl %eax, %gs 388 movl %ebx, %fs 389 movl %ecx, %es 390 movl %edx, %ds 391 392 /* 393 * Restore the scratch registers and the preserved 394 * registers the handler cloberred itself 395 * (i.e. EBX and EBP). 396 */ 397 movl ISTATE_OFFSET_EAX(%esp), %eax 398 movl ISTATE_OFFSET_EBX(%esp), %ebx 399 movl ISTATE_OFFSET_ECX(%esp), %ecx 400 movl ISTATE_OFFSET_EDX(%esp), %edx 401 movl ISTATE_OFFSET_EBP(%esp), %ebp 402 403 addl $(ISTATE_SOFT_SIZE + 4), %esp 404 iret 405 305 406 .endif 306 407 307 408 .align INTERRUPT_ALIGN 308 .if (\n - \i) - 1409 .if (\n - \i) - 1 309 410 handler "(\i + 1)", \n 310 411 .endif 311 412 .endm 312 413 313 # keep in sync with pm.h !!! 314 IDT_ITEMS = 64 414 /* Keep in sync with pm.h! */ 415 #define IDT_ITEMS 64 416 315 417 .align INTERRUPT_ALIGN 316 418 interrupt_handlers: 317 h_start: 318 handler 0 IDT_ITEMS 319 h_end: 419 h_start: 420 handler 0 IDT_ITEMS 421 h_end: 422 423 /** Print Unicode character to EGA display. 424 * 425 * If CONFIG_EGA is undefined or CONFIG_FB is defined 426 * then this function does nothing. 427 * 428 * Since the EGA can only display Extended ASCII (usually 429 * ISO Latin 1) characters, some of the Unicode characters 430 * can be displayed in a wrong way. Only the newline character 431 * is interpreted, all other characters (even unprintable) are 432 * printed verbatim. 433 * 434 * @param %ebp+0x08 Unicode character to be printed. 435 * 436 */ 437 early_putchar: 438 439 #if ((defined(CONFIG_EGA)) && (!defined(CONFIG_FB))) 440 441 /* Prologue, save preserved registers */ 442 pushl %ebp 443 movl %esp, %ebp 444 pushl %ebx 445 pushl %esi 446 pushl %edi 447 448 movl $(PA2KA(0xb8000)), %edi /* base of EGA text mode memory */ 449 xorl %eax, %eax 450 451 /* Read bits 8 - 15 of the cursor address */ 452 movw $0x3d4, %dx 453 movb $0xe, %al 454 outb %al, %dx 455 456 movw $0x3d5, %dx 457 inb %dx, %al 458 shl $8, %ax 459 460 /* Read bits 0 - 7 of the cursor address */ 461 movw $0x3d4, %dx 462 movb $0xf, %al 463 outb %al, %dx 464 465 movw $0x3d5, %dx 466 inb %dx, %al 467 468 /* Sanity check for the cursor on screen */ 469 cmp $2000, %ax 470 jb early_putchar_cursor_ok 471 472 movw $1998, %ax 473 474 early_putchar_cursor_ok: 475 476 movw %ax, %bx 477 shl $1, %eax 478 addl %eax, %edi 479 480 movl 0x08(%ebp), %eax 481 482 cmp $0x0a, %al 483 jne early_putchar_print 484 485 /* Interpret newline */ 486 487 movw %bx, %ax /* %bx -> %dx:%ax */ 488 xorw %dx, %dx 489 490 movw $80, %cx 491 idivw %cx, %ax /* %dx = %bx % 80 */ 492 493 /* %bx <- %bx + 80 - (%bx % 80) */ 494 addw %cx, %bx 495 subw %dx, %bx 496 497 jmp early_putchar_newline 498 499 early_putchar_print: 500 501 /* Print character */ 502 503 movb $0x0e, %ah /* black background, yellow foreground */ 504 stosw 505 inc %bx 506 507 early_putchar_newline: 508 509 /* Sanity check for the cursor on the last line */ 510 cmp $2000, %bx 511 jb early_putchar_no_scroll 512 513 /* Scroll the screen (24 rows) */ 514 movl $(PA2KA(0xb80a0)), %esi 515 movl $(PA2KA(0xb8000)), %edi 516 movl $1920, %ecx 517 rep movsw 518 519 /* Clear the 24th row */ 520 xorl %eax, %eax 521 movl $80, %ecx 522 rep stosw 523 524 /* Go to row 24 */ 525 movw $1920, %bx 526 527 early_putchar_no_scroll: 528 529 /* Write bits 8 - 15 of the cursor address */ 530 movw $0x3d4, %dx 531 movb $0xe, %al 532 outb %al, %dx 533 534 movw $0x3d5, %dx 535 movb %bh, %al 536 outb %al, %dx 537 538 /* Write bits 0 - 7 of the cursor address */ 539 movw $0x3d4, %dx 540 movb $0xf, %al 541 outb %al, %dx 542 543 movw $0x3d5, %dx 544 movb %bl, %al 545 outb %al, %dx 546 547 /* Epilogue, restore preserved registers */ 548 popl %edi 549 popl %esi 550 popl %ebx 551 leave 552 553 #endif 554 555 ret 320 556 321 557 .data -
kernel/arch/ia32/src/bios/bios.c
rfe7abd0 rcefb126 27 27 */ 28 28 29 /** @addtogroup ia32 29 /** @addtogroup ia32 30 30 * @{ 31 31 */ -
kernel/arch/ia32/src/boot/boot.S
rfe7abd0 rcefb126 1 # 2 # Copyright (c) 2001-2004Jakub Jermar3 # Copyright (c) 2005-2006Martin Decky4 #All rights reserved.5 # 6 #Redistribution and use in source and binary forms, with or without7 #modification, are permitted provided that the following conditions8 #are met:9 # 10 #- Redistributions of source code must retain the above copyright11 #notice, this list of conditions and the following disclaimer.12 #- Redistributions in binary form must reproduce the above copyright13 #notice, this list of conditions and the following disclaimer in the14 #documentation and/or other materials provided with the distribution.15 #- The name of the author may not be used to endorse or promote products16 #derived from this software without specific prior written permission.17 # 18 #THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR19 #IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES20 #OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.21 #IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,22 #INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT23 #NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,24 #DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY25 #THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT26 #(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF27 #THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.28 # 1 /* 2 * Copyright (c) 2001 Jakub Jermar 3 * Copyright (c) 2005 Martin Decky 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 10 * - Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * - Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * - The name of the author may not be used to endorse or promote products 16 * derived from this software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 */ 29 29 30 30 #include <arch/boot/boot.h> … … 34 34 #include <arch/cpuid.h> 35 35 36 #define START_STACK (BOOT_OFFSET - BOOT_STACK_SIZE)36 #define START_STACK (BOOT_OFFSET - BOOT_STACK_SIZE) 37 37 38 38 .section K_TEXT_START, "ax" 39 39 40 40 .code32 41 42 .macro pm_error msg 43 movl \msg, %esi 44 jmp pm_error_halt 45 .endm 46 47 .macro pm_status msg 48 #ifdef CONFIG_EGA 49 pushl %esi 50 movl \msg, %esi 51 call pm_early_puts 52 popl %esi 53 #endif 54 .endm 55 56 .macro pm2_status msg 57 pushl \msg 58 call early_puts 59 .endm 60 41 61 .align 4 42 62 .global multiboot_image_start … … 44 64 .long MULTIBOOT_HEADER_MAGIC 45 65 .long MULTIBOOT_HEADER_FLAGS 46 .long -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS) # checksum66 .long -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS) /* checksum */ 47 67 .long multiboot_header 48 68 .long unmapped_ktext_start … … 53 73 multiboot_image_start: 54 74 cld 55 movl $START_STACK, %esp # initialize stack pointer 56 lgdt KA2PA(bootstrap_gdtr) # initialize Global Descriptor Table register 57 75 76 /* Initialize stack pointer */ 77 movl $START_STACK, %esp 78 79 /* Initialize Global Descriptor Table register */ 80 lgdtl KA2PA(bootstrap_gdtr) 81 82 /* Kernel data + stack */ 58 83 movw $gdtselector(KDATA_DES), %cx 59 84 movw %cx, %es 60 85 movw %cx, %fs 61 86 movw %cx, %gs 62 movw %cx, %ds # kernel data + stack87 movw %cx, %ds 63 88 movw %cx, %ss 64 89 … … 66 91 multiboot_meeting_point: 67 92 68 movl %eax, grub_eax # save parameters from GRUB 93 /* Save GRUB arguments */ 94 movl %eax, grub_eax 69 95 movl %ebx, grub_ebx 96 97 pm_status $status_prot 70 98 71 99 movl $(INTEL_CPUID_LEVEL), %eax 72 100 cpuid 73 cmp $0x0, %eax # any function > 0?101 cmp $0x0, %eax /* any function > 0? */ 74 102 jbe pse_unsupported 75 103 … … 80 108 81 109 pse_unsupported: 82 movl $pse_msg, %esi83 jmp error_halt110 111 pm_error $err_pse 84 112 85 113 pse_supported: 86 114 87 115 #include "vesa_prot.inc" 88 89 # map kernel and turn paging on116 117 /* Map kernel and turn paging on */ 90 118 call map_kernel 91 119 92 # call arch_pre_main(grub_eax, grub_ebx) 120 /* Create the first stack frame */ 121 pushl $0 122 movl %esp, %ebp 123 124 pm2_status $status_prot2 125 126 /* Call arch_pre_main(grub_eax, grub_ebx) */ 93 127 pushl grub_ebx 94 128 pushl grub_eax 95 129 call arch_pre_main 96 97 # Create the first stack frame 98 pushl $0 99 movl %esp, %ebp 100 130 131 pm2_status $status_main 132 133 /* Call main_bsp() */ 101 134 call main_bsp 102 135 103 # not reached136 /* Not reached */ 104 137 cli 105 138 hlt0: … … 107 140 jmp hlt0 108 141 142 /** Setup mapping for the kernel. 143 * 144 * Setup mapping for both the unmapped and mapped sections 145 * of the kernel. For simplicity, we map the entire 4G space. 146 * 147 */ 109 148 .global map_kernel 110 149 map_kernel: 111 #112 # Here we setup mapping for both the unmapped and mapped sections of the kernel.113 # For simplicity, we map the entire 4G space.114 #115 150 movl %cr4, %ecx 116 orl $(1 << 4), %ecx # turn PSE on117 andl $(~(1 << 5)), %ecx # turn PAE off151 orl $(1 << 4), %ecx /* PSE on */ 152 andl $(~(1 << 5)), %ecx /* PAE off */ 118 153 movl %ecx, %cr4 119 154 … … 126 161 movl $((1 << 7) | (1 << 1) | (1 << 0)), %eax 127 162 orl %ebx, %eax 128 movl %eax, (%esi, %ecx, 4) # mapping 0x00000000 + %ecx * 4M => 0x00000000 + %ecx * 4M 129 movl %eax, (%edi, %ecx, 4) # mapping 0x80000000 + %ecx * 4M => 0x00000000 + %ecx * 4M 163 /* Mapping 0x00000000 + %ecx * 4M => 0x00000000 + %ecx * 4M */ 164 movl %eax, (%esi, %ecx, 4) 165 /* Mapping 0x80000000 + %ecx * 4M => 0x00000000 + %ecx * 4M */ 166 movl %eax, (%edi, %ecx, 4) 130 167 addl $(4 * 1024 * 1024), %ebx 131 168 … … 137 174 138 175 movl %cr0, %ebx 139 orl $(1 << 31), %ebx # turn paging on176 orl $(1 << 31), %ebx /* paging on */ 140 177 movl %ebx, %cr0 141 178 ret 142 179 143 # Print string from %esi to EGA display (in red) and halt 144 error_halt: 145 movl $0xb8000, %edi # base of EGA text mode memory 180 /** Print string to EGA display (in light red) and halt. 181 * 182 * Should be executed from 32 bit protected mode with paging 183 * turned off. Stack is not required. This routine is used even 184 * if CONFIG_EGA is not enabled. Since we are going to halt the 185 * CPU anyway, it is always better to at least try to print 186 * some hints. 187 * 188 * @param %esi NULL-terminated string to print. 189 * 190 */ 191 pm_error_halt: 192 movl $0xb8000, %edi /* base of EGA text mode memory */ 146 193 xorl %eax, %eax 147 194 148 movw $0x3d4, %dx # read bits 8 - 15 of the cursor address 195 /* Read bits 8 - 15 of the cursor address */ 196 movw $0x3d4, %dx 149 197 movb $0xe, %al 150 198 outb %al, %dx … … 154 202 shl $8, %ax 155 203 156 movw $0x3d4, %dx # read bits 0 - 7 of the cursor address 204 /* Read bits 0 - 7 of the cursor address */ 205 movw $0x3d4, %dx 157 206 movb $0xf, %al 158 207 outb %al, %dx … … 161 210 inb %dx, %al 162 211 163 cmp $1920, %ax 164 jbe cursor_ok 165 166 movw $1920, %ax # sanity check for the cursor on the last line 167 168 cursor_ok: 212 /* Sanity check for the cursor on screen */ 213 cmp $2000, %ax 214 jb err_cursor_ok 215 216 movw $1998, %ax 217 218 err_cursor_ok: 169 219 170 220 movw %ax, %bx … … 172 222 addl %eax, %edi 173 223 174 movw $0x0c00, %ax # black background, light red foreground 175 176 ploop: 224 err_ploop: 177 225 lodsb 226 178 227 cmp $0, %al 179 je ploop_end 228 je err_ploop_end 229 230 movb $0x0c, %ah /* black background, light red foreground */ 180 231 stosw 232 233 /* Sanity check for the cursor on the last line */ 181 234 inc %bx 182 jmp ploop 183 ploop_end: 184 185 movw $0x3d4, %dx # write bits 8 - 15 of the cursor address 235 cmp $2000, %bx 236 jb err_ploop 237 238 /* Scroll the screen (24 rows) */ 239 movl %esi, %edx 240 movl $0xb80a0, %esi 241 movl $0xb8000, %edi 242 movl $1920, %ecx 243 rep movsw 244 245 /* Clear the 24th row */ 246 xorl %eax, %eax 247 movl $80, %ecx 248 rep stosw 249 250 /* Go to row 24 */ 251 movl %edx, %esi 252 movl $0xb8f00, %edi 253 movw $1920, %bx 254 255 jmp err_ploop 256 err_ploop_end: 257 258 /* Write bits 8 - 15 of the cursor address */ 259 movw $0x3d4, %dx 186 260 movb $0xe, %al 187 261 outb %al, %dx … … 191 265 outb %al, %dx 192 266 193 movw $0x3d4, %dx # write bits 0 - 7 of the cursor address 267 /* Write bits 0 - 7 of the cursor address */ 268 movw $0x3d4, %dx 194 269 movb $0xf, %al 195 270 outb %al, %dx … … 204 279 jmp hlt1 205 280 281 /** Print string to EGA display (in light green). 282 * 283 * Should be called from 32 bit protected mode with paging 284 * turned off. A stack space of at least 24 bytes is required, 285 * but the function does not establish a stack frame. 286 * 287 * Macros such as pm_status take care that this function 288 * is used only when CONFIG_EGA is enabled. 289 * 290 * @param %esi NULL-terminated string to print. 291 * 292 */ 293 pm_early_puts: 294 pushl %eax 295 pushl %ebx 296 pushl %ecx 297 pushl %edx 298 pushl %edi 299 300 movl $0xb8000, %edi /* base of EGA text mode memory */ 301 xorl %eax, %eax 302 303 /* Read bits 8 - 15 of the cursor address */ 304 movw $0x3d4, %dx 305 movb $0xe, %al 306 outb %al, %dx 307 308 movw $0x3d5, %dx 309 inb %dx, %al 310 shl $8, %ax 311 312 /* Read bits 0 - 7 of the cursor address */ 313 movw $0x3d4, %dx 314 movb $0xf, %al 315 outb %al, %dx 316 317 movw $0x3d5, %dx 318 inb %dx, %al 319 320 /* Sanity check for the cursor on screen */ 321 cmp $2000, %ax 322 jb pm_puts_cursor_ok 323 324 movw $1998, %ax 325 326 pm_puts_cursor_ok: 327 328 movw %ax, %bx 329 shl $1, %eax 330 addl %eax, %edi 331 332 pm_puts_ploop: 333 lodsb 334 335 cmp $0, %al 336 je pm_puts_ploop_end 337 338 movb $0x0a, %ah /* black background, light green foreground */ 339 stosw 340 341 /* Sanity check for the cursor on the last line */ 342 inc %bx 343 cmp $2000, %bx 344 jb pm_puts_ploop 345 346 /* Scroll the screen (24 rows) */ 347 movl %esi, %edx 348 movl $0xb80a0, %esi 349 movl $0xb8000, %edi 350 movl $1920, %ecx 351 rep movsw 352 353 /* Clear the 24th row */ 354 xorl %eax, %eax 355 movl $80, %ecx 356 rep stosw 357 358 /* Go to row 24 */ 359 movl %edx, %esi 360 movl $0xb8f00, %edi 361 movw $1920, %bx 362 363 jmp pm_puts_ploop 364 pm_puts_ploop_end: 365 366 /* Write bits 8 - 15 of the cursor address */ 367 movw $0x3d4, %dx 368 movb $0xe, %al 369 outb %al, %dx 370 371 movw $0x3d5, %dx 372 movb %bh, %al 373 outb %al, %dx 374 375 /* Write bits 0 - 7 of the cursor address */ 376 movw $0x3d4, %dx 377 movb $0xf, %al 378 outb %al, %dx 379 380 movw $0x3d5, %dx 381 movb %bl, %al 382 outb %al, %dx 383 384 popl %edi 385 popl %edx 386 popl %ecx 387 popl %ebx 388 popl %eax 389 390 ret 391 392 /** Print string to EGA display. 393 * 394 * Should be called from 32 bit protected mode (with paging 395 * enabled and stack established). This function is ABI compliant. 396 * 397 * If CONFIG_EGA is undefined or CONFIG_FB is defined 398 * then this function does nothing. 399 * 400 * @param %ebp+0x08 NULL-terminated string to print. 401 * 402 */ 403 early_puts: 404 405 #if ((defined(CONFIG_EGA)) && (!defined(CONFIG_FB))) 406 407 /* Prologue, save preserved registers */ 408 pushl %ebp 409 movl %esp, %ebp 410 pushl %ebx 411 pushl %esi 412 pushl %edi 413 414 movl 0x08(%ebp), %esi 415 movl $(PA2KA(0xb8000)), %edi /* base of EGA text mode memory */ 416 xorl %eax, %eax 417 418 /* Read bits 8 - 15 of the cursor address */ 419 movw $0x3d4, %dx 420 movb $0xe, %al 421 outb %al, %dx 422 423 movw $0x3d5, %dx 424 inb %dx, %al 425 shl $8, %ax 426 427 /* Read bits 0 - 7 of the cursor address */ 428 movw $0x3d4, %dx 429 movb $0xf, %al 430 outb %al, %dx 431 432 movw $0x3d5, %dx 433 inb %dx, %al 434 435 /* Sanity check for the cursor on screen */ 436 cmp $2000, %ax 437 jb early_puts_cursor_ok 438 439 movw $1998, %ax 440 441 early_puts_cursor_ok: 442 443 movw %ax, %bx 444 shl $1, %eax 445 addl %eax, %edi 446 447 early_puts_ploop: 448 lodsb 449 450 cmp $0, %al 451 je early_puts_ploop_end 452 453 movb $0x0e, %ah /* black background, yellow foreground */ 454 stosw 455 456 /* Sanity check for the cursor on the last line */ 457 inc %bx 458 cmp $2000, %bx 459 jb early_puts_ploop 460 461 /* Scroll the screen (24 rows) */ 462 movl %esi, %edx 463 movl $(PA2KA(0xb80a0)), %esi 464 movl $(PA2KA(0xb8000)), %edi 465 movl $1920, %ecx 466 rep movsw 467 468 /* Clear the 24th row */ 469 xorl %eax, %eax 470 movl $80, %ecx 471 rep stosw 472 473 /* Go to row 24 */ 474 movl %edx, %esi 475 movl $(PA2KA(0xb8f00)), %edi 476 movw $1920, %bx 477 478 jmp early_puts_ploop 479 early_puts_ploop_end: 480 481 /* Write bits 8 - 15 of the cursor address */ 482 movw $0x3d4, %dx 483 movb $0xe, %al 484 outb %al, %dx 485 486 movw $0x3d5, %dx 487 movb %bh, %al 488 outb %al, %dx 489 490 /* Write bits 0 - 7 of the cursor address */ 491 movw $0x3d4, %dx 492 movb $0xf, %al 493 outb %al, %dx 494 495 movw $0x3d5, %dx 496 movb %bl, %al 497 outb %al, %dx 498 499 /* Epilogue, restore preserved registers */ 500 popl %edi 501 popl %esi 502 popl %ebx 503 leave 504 505 #endif 506 507 ret 508 206 509 #include "vesa_real.inc" 207 510 … … 218 521 .long 0 219 522 220 pse_msg:523 err_pse: 221 524 .asciz "Page Size Extension not supported. System halted." 222 525 526 status_prot: 527 .asciz "[prot] " 528 status_vesa_copy: 529 .asciz "[vesa_copy] " 530 status_grub_cmdline: 531 .asciz "[grub_cmdline] " 532 status_vesa_real: 533 .asciz "[vesa_real] " 534 status_prot2: 535 .asciz "[prot2] " 536 status_main: 537 .asciz "[main] " -
kernel/arch/ia32/src/boot/vesa_prot.inc
rfe7abd0 rcefb126 5 5 #define MBINFO_OFFSET_CMDLINE 16 6 6 7 # copy real mode VESA initialization code 7 /* Copy real mode VESA initialization code */ 8 9 pm_status $status_vesa_copy 8 10 9 11 mov $vesa_init, %esi … … 12 14 rep movsb 13 15 14 # check for GRUB command line 16 /* Check for GRUB command line */ 17 18 pm_status $status_grub_cmdline 15 19 16 20 mov grub_eax, %eax … … 23 27 jnc no_cmdline 24 28 25 # skip the kernel path in command line29 /* Skip the kernel path in command line */ 26 30 27 31 mov MBINFO_OFFSET_CMDLINE(%ebx), %esi … … 52 56 space_loop_done: 53 57 54 # copy at most 23 characters from command line58 /* Copy at most 23 characters from command line */ 55 59 56 60 mov $VESA_INIT_SEGMENT << 4, %edi … … 68 72 cmd_loop_done: 69 73 70 # zero termination74 /* Zero termination */ 71 75 72 76 xor %eax, %eax … … 75 79 no_cmdline: 76 80 77 # jump to the real mode 81 /* Jump to the real mode */ 82 83 pm_status $status_vesa_real 78 84 79 85 mov $VESA_INIT_SEGMENT << 4, %edi … … 81 87 82 88 vesa_meeting_point: 83 # returned back to protected mode89 /* Returned back to protected mode */ 84 90 85 91 mov %ax, KA2PA(vesa_scanline) -
kernel/arch/ia32/src/boot/vesa_real.inc
rfe7abd0 rcefb126 31 31 vesa_init: 32 32 jmp $gdtselector(VESA_INIT_DES), $vesa_init_real - vesa_init 33 33 34 34 .code16 35 35 vesa_init_real: … … 55 55 pushl %eax 56 56 57 # parse default mode string57 /* Parse default mode string */ 58 58 59 59 mov $default_mode - vesa_init, %di … … 65 65 mov (%di), %al 66 66 67 # check for digit67 /* Check for digit */ 68 68 69 69 cmp $'0', %al … … 75 75 sub $'0', %al 76 76 77 # multiply default_width by 10 and add digit77 /* Multiply default_width by 10 and add digit */ 78 78 79 79 mov default_width - vesa_init, %bx … … 96 96 mov (%di), %al 97 97 98 # check for digit98 /* Check for digit */ 99 99 100 100 cmp $'0', %al … … 106 106 sub $'0', %al 107 107 108 # multiply default_height by 10 and add digit108 /* Multiply default_height by 10 and add digit */ 109 109 110 110 mov default_height - vesa_init, %bx … … 127 127 mov (%di), %al 128 128 129 # check for digit129 /* Check for digit */ 130 130 131 131 cmp $'0', %al … … 137 137 sub $'0', %al 138 138 139 # multiply default_bpp by 10 and add digit139 /* Multiply default_bpp by 10 and add digit */ 140 140 141 141 mov default_bpp - vesa_init, %bx … … 167 167 168 168 next_mode: 169 # try next mode 169 /* Try next mode */ 170 170 171 mov %gs:(%si), %cx 171 172 cmp $VESA_END_OF_MODES, %cx … … 186 187 jne no_mode 187 188 188 # check for proper attributes (supported, color, graphics, linear framebuffer) 189 /* 190 * Check for proper attributes (supported, 191 * color, graphics, linear framebuffer). 192 */ 189 193 190 194 mov VESA_MODE_ATTRIBUTES_OFFSET(%di), %ax … … 193 197 jne next_mode 194 198 195 # check for proper resolution199 /* Check for proper resolution */ 196 200 197 201 mov default_width - vesa_init, %ax … … 203 207 jne next_mode 204 208 205 # check for proper bpp209 /* Check for proper bpp */ 206 210 207 211 mov default_bpp - vesa_init, %al … … 213 217 jne next_mode 214 218 215 # for 24 bpp modes accept also 32 bit bpp219 /* For 24 bpp modes accept also 32 bit bpp */ 216 220 217 221 mov $32, %al … … 230 234 jnz no_mode 231 235 232 # set 3:2:3 VGA palette236 /* Set 3:2:3 VGA palette */ 233 237 234 238 mov VESA_MODE_BPP_OFFSET(%di), %al … … 241 245 mov $0x100, %ecx 242 246 243 bt $5, %ax # test if VGA compatible registers are present 247 /* Test if VGA compatible registers are present */ 248 bt $5, %ax 244 249 jnc vga_compat 245 250 246 # try VESA routine to set palette 251 /* Use VESA routine to set the palette */ 252 247 253 mov $VESA_SET_PALETTE, %ax 248 254 xor %bl, %bl … … 254 260 255 261 vga_compat: 256 # try VGA registers to set palette 257 movw $0x3c6, %dx # set palette mask 262 263 /* Use VGA registers to set the palette */ 264 265 movw $0x3c6, %dx /* set palette mask */ 258 266 movb $0xff, %al 259 267 outb %al, %dx 260 268 261 movw $0x3c8, %dx # first index to set269 movw $0x3c8, %dx /* first index to set */ 262 270 xor %al, %al 263 271 outb %al, %dx 264 272 265 movw $0x3c9, %dx # data port273 movw $0x3c9, %dx /* data port */ 266 274 267 275 vga_loop: … … 284 292 vga_not_set: 285 293 286 # store mode parameters 287 # eax = bpp[8] scanline[16] 288 # ebx = width[16] height[16] 289 # edx = red_mask[8] red_pos[8] green_mask[8] green_pos[8] 290 # esi = blue_mask[8] blue_pos[8] 291 # edi = linear frame buffer 294 /* 295 * Store mode parameters: 296 * eax = bpp[8] scanline[16] 297 * ebx = width[16] height[16] 298 * edx = red_mask[8] red_pos[8] green_mask[8] green_pos[8] 299 * esi = blue_mask[8] blue_pos[8] 300 * edi = linear frame buffer 301 */ 292 302 293 303 mov VESA_MODE_BPP_OFFSET(%di), %al … … 328 338 329 339 no_mode: 330 # no prefered mode found 340 341 /* No prefered mode found */ 342 331 343 mov $0x111, %cx 332 344 push %di … … 339 351 cmp $VESA_OK, %al 340 352 jnz text_mode 341 jz set_mode # force relative jump353 jz set_mode /* force relative jump */ 342 354 343 355 text_mode: 344 # reset to EGA text mode (because of problems with VESA) 356 357 /* Reset to EGA text mode (because of problems with VESA) */ 358 345 359 mov $0x0003, %ax 346 360 int $0x10 347 361 mov $0xffffffff, %edi 348 362 xor %ax, %ax 349 jz vesa_leave_real # force relative jump363 jz vesa_leave_real /* force relative jump */ 350 364 351 365 vga323: -
kernel/arch/ia32/src/boot/vesa_ret.inc
rfe7abd0 rcefb126 1 1 .code32 2 2 vesa_init_protected: 3 cld 4 5 /* Initialize stack pointer */ 6 movl $START_STACK, %esp 7 8 /* Kernel data + stack */ 3 9 movw $gdtselector(KDATA_DES), %cx 4 10 movw %cx, %es 5 11 movw %cx, %fs 6 12 movw %cx, %gs 7 movw %cx, %ds # kernel data + stack13 movw %cx, %ds 8 14 movw %cx, %ss 9 15 10 movl $START_STACK, %esp # initialize stack pointer11 12 16 jmpl $gdtselector(KTEXT_DES), $vesa_meeting_point -
kernel/arch/ia32/src/ia32.c
rfe7abd0 rcefb126 139 139 { 140 140 #ifdef CONFIG_SMP 141 if (config.cpu_active > 1) {141 if (config.cpu_active > 1) { 142 142 l_apic_init(); 143 143 l_apic_debug(); -
kernel/arch/ia32/src/interrupt.c
rfe7abd0 rcefb126 63 63 void (* eoi_function)(void) = NULL; 64 64 65 void decode_istate(istate_t *istate) 66 { 67 const char *symbol = symtab_fmt_name_lookup(istate->eip); 68 69 if (CPU) 70 printf("----------------EXCEPTION OCCURED (cpu%u)----------------\n", CPU->id); 71 else 72 printf("----------------EXCEPTION OCCURED----------------\n"); 73 74 printf("%%eip: %#lx (%s)\n", istate->eip, symbol); 75 printf("ERROR_WORD=%#lx\n", istate->error_word); 76 printf("%%cs=%#lx,flags=%#lx\n", istate->cs, istate->eflags); 77 printf("%%eax=%#lx, %%ecx=%#lx, %%edx=%#lx, %%esp=%p\n", istate->eax, istate->ecx, istate->edx, &istate->stack[0]); 78 printf("stack: %#lx, %#lx, %#lx, %#lx\n", istate->stack[0], istate->stack[1], istate->stack[2], istate->stack[3]); 79 printf(" %#lx, %#lx, %#lx, %#lx\n", istate->stack[4], istate->stack[5], istate->stack[6], istate->stack[7]); 80 81 stack_trace_istate(istate); 65 void istate_decode(istate_t *istate) 66 { 67 printf("error_word=%p\n", istate->error_word); 68 printf("eflags=%p\n", istate->eflags); 69 70 printf("cs =%p\tds =%p\tes =%p\n", istate->cs, istate->ds, istate->es); 71 printf("fs =%p\tgs =%p", istate->fs, istate->gs); 72 if (istate_from_uspace(istate)) 73 printf("\tss =%p\n", istate->ss); 74 else 75 printf("\n"); 76 77 printf("eax=%p\tebx=%p\tecx=%p\n", istate->eax, istate->ebx, 78 istate->ecx); 79 printf("edx=%p\tedi=%p\tesi=%p\n", istate->edx, istate->edi, 80 istate->esi); 81 printf("ebp=%p\tesp=%p\teip=%p\n", istate->ebp, 82 istate_from_uspace(istate) ? istate->esp : (uintptr_t) &istate->esp, 83 istate->eip); 82 84 } 83 85 … … 94 96 { 95 97 fault_if_from_uspace(istate, "Unserviced interrupt: %u.", n); 96 97 decode_istate(istate); 98 panic("Unserviced interrupt: %u.", n); 98 panic_badtrap(istate, n, "Unserviced interrupt: %u.", n); 99 99 } 100 100 … … 102 102 { 103 103 fault_if_from_uspace(istate, "Divide error."); 104 105 decode_istate(istate); 106 panic("Divide error."); 104 panic_badtrap(istate, n, "Divide error."); 107 105 } 108 106 … … 128 126 fault_if_from_uspace(istate, "General protection fault."); 129 127 } 130 131 decode_istate(istate); 132 panic("General protection fault."); 128 panic_badtrap(istate, n, "General protection fault."); 133 129 } 134 130 … … 136 132 { 137 133 fault_if_from_uspace(istate, "Stack fault."); 138 139 decode_istate(istate); 140 panic("Stack fault."); 134 panic_badtrap(istate, n, "Stack fault."); 141 135 } 142 136 … … 149 143 ); 150 144 151 fault_if_from_uspace(istate, "SIMD FP exception(19), MXCSR : %#zx.",145 fault_if_from_uspace(istate, "SIMD FP exception(19), MXCSR=%#0.8x.", 152 146 (unative_t) mxcsr); 153 154 decode_istate(istate); 155 printf("MXCSR: %#lx\n", mxcsr); 156 panic("SIMD FP exception(19)."); 147 panic_badtrap(istate, n, "SIMD FP exception, MXCSR=%#0.8x"); 157 148 } 158 149 … … 164 155 #else 165 156 fault_if_from_uspace(istate, "FPU fault."); 166 panic ("FPU fault.");157 panic_badtrap(istate, n, "FPU fault."); 167 158 #endif 168 159 } -
kernel/arch/ia32/src/mm/as.c
rfe7abd0 rcefb126 27 27 */ 28 28 29 /** @addtogroup ia32mm 29 /** @addtogroup ia32mm 30 30 * @{ 31 31 */ -
kernel/arch/ia32/src/mm/frame.c
rfe7abd0 rcefb126 47 47 #include <print.h> 48 48 49 #define PHYSMEM_LIMIT32 0x07c000000ull 50 #define PHYSMEM_LIMIT64 0x200000000ull 51 49 52 size_t hardcoded_unmapped_ktext_size = 0; 50 53 size_t hardcoded_unmapped_kdata_size = 0; … … 55 58 { 56 59 unsigned int i; 57 60 58 61 for (i = 0; i < e820counter; i++) { 59 62 uint64_t base = e820table[i].base_address; … … 61 64 62 65 #ifdef __32_BITS__ 63 /* Ignore physical memory above 4 GB */ 64 if ((base >> 32) != 0) 66 /* 67 * XXX FIXME: 68 * 69 * Ignore zones which start above PHYSMEM_LIMIT32 70 * or clip zones which go beyond PHYSMEM_LIMIT32. 71 * 72 * The PHYSMEM_LIMIT32 (2 GB - 64 MB) is a rather 73 * arbitrary constant which allows to have at 74 * least 64 MB in the kernel address space to 75 * map hardware resources. 76 * 77 * The kernel uses fixed 1:1 identity mapping 78 * of the physical memory with 2:2 GB split. 79 * This is a severe limitation of the current 80 * kernel memory management. 81 * 82 */ 83 84 if (base > PHYSMEM_LIMIT32) 65 85 continue; 66 86 67 /* Clip regions above 4 GB */ 68 if (((base + size) >> 32) != 0) 69 size = 0xffffffff - base; 70 #endif 71 72 pfn_t pfn; 73 size_t count; 87 if (base + size > PHYSMEM_LIMIT32) 88 size = PHYSMEM_LIMIT32 - base; 89 #endif 90 91 #ifdef __64_BITS__ 92 /* 93 * XXX FIXME: 94 * 95 * Ignore zones which start above PHYSMEM_LIMIT64 96 * or clip zones which go beyond PHYSMEM_LIMIT64. 97 * 98 * The PHYSMEM_LIMIT64 (8 GB) is the size of the 99 * fixed 1:1 identically mapped physical memory 100 * accessible during the bootstrap process. 101 * This is a severe limitation of the current 102 * kernel memory management. 103 * 104 */ 105 106 if (base > PHYSMEM_LIMIT64) 107 continue; 108 109 if (base + size > PHYSMEM_LIMIT64) 110 size = PHYSMEM_LIMIT64 - base; 111 #endif 74 112 75 113 if (e820table[i].type == MEMMAP_MEMORY_AVAILABLE) { 76 /* To be safe, make available zone possibly smaller */ 77 pfn = ADDR2PFN(ALIGN_UP(base, FRAME_SIZE)); 78 count = SIZE2FRAMES(ALIGN_DOWN(size, FRAME_SIZE)); 114 /* To be safe, make the available zone possibly smaller */ 115 uint64_t new_base = ALIGN_UP(base, FRAME_SIZE); 116 uint64_t new_size = ALIGN_DOWN(size - (new_base - base), 117 FRAME_SIZE); 118 119 pfn_t pfn = ADDR2PFN(new_base); 120 size_t count = SIZE2FRAMES(new_size); 79 121 80 122 pfn_t conf; … … 87 129 88 130 // XXX this has to be removed 89 if (last_frame < ALIGN_UP( base +size, FRAME_SIZE))90 last_frame = ALIGN_UP( base +size, FRAME_SIZE);131 if (last_frame < ALIGN_UP(new_base + new_size, FRAME_SIZE)) 132 last_frame = ALIGN_UP(new_base + new_size, FRAME_SIZE); 91 133 } 92 134 93 135 if (e820table[i].type == MEMMAP_MEMORY_RESERVED) { 94 /* To be safe, make reserved zone possibly larger */ 95 pfn = ADDR2PFN(ALIGN_DOWN(base, FRAME_SIZE)); 96 count = SIZE2FRAMES(ALIGN_UP(size, FRAME_SIZE)); 97 98 zone_create(pfn, count, 0, ZONE_RESERVED); 136 /* To be safe, make the reserved zone possibly larger */ 137 uint64_t new_base = ALIGN_DOWN(base, FRAME_SIZE); 138 uint64_t new_size = ALIGN_UP(size + (base - new_base), 139 FRAME_SIZE); 140 141 zone_create(ADDR2PFN(new_base), SIZE2FRAMES(new_size), 0, 142 ZONE_RESERVED); 99 143 } 100 144 101 145 if (e820table[i].type == MEMMAP_MEMORY_ACPI) { 102 /* To be safe, make firmware zone possibly larger */ 103 pfn = ADDR2PFN(ALIGN_DOWN(base, (uintptr_t) FRAME_SIZE)); 104 count = SIZE2FRAMES(ALIGN_UP(size, (uintptr_t) FRAME_SIZE)); 105 106 zone_create(pfn, count, 0, ZONE_FIRMWARE); 146 /* To be safe, make the firmware zone possibly larger */ 147 uint64_t new_base = ALIGN_DOWN(base, FRAME_SIZE); 148 uint64_t new_size = ALIGN_UP(size + (base - new_base), 149 FRAME_SIZE); 150 151 zone_create(ADDR2PFN(new_base), SIZE2FRAMES(new_size), 0, 152 ZONE_FIRMWARE); 107 153 } 108 154 } … … 121 167 { 122 168 unsigned int i; 123 const char *name;169 printf("[base ] [size ] [name ]\n"); 124 170 125 printf("Base Size Name\n");126 printf("------------------ ------------------ ---------\n");127 128 171 for (i = 0; i < e820counter; i++) { 172 const char *name; 173 129 174 if (e820table[i].type <= MEMMAP_MEMORY_UNUSABLE) 130 175 name = e820names[e820table[i].type]; … … 132 177 name = "invalid"; 133 178 134 printf("%# 18llx %#18llx%s\n", e820table[i].base_address,179 printf("%#018" PRIx64 " %#018" PRIx64" %s\n", e820table[i].base_address, 135 180 e820table[i].size, name); 136 181 } … … 150 195 hardcoded_unmapped_kdata_size)); 151 196 #endif 152 197 153 198 init_e820_memory(minconf); 154 199 -
kernel/arch/ia32/src/mm/page.c
rfe7abd0 rcefb126 115 115 if (as_page_fault(page, access, istate) == AS_PF_FAULT) { 116 116 fault_if_from_uspace(istate, "Page fault: %#x.", page); 117 118 decode_istate(istate); 119 printf("page fault address: %#lx\n", page); 120 panic("Page fault."); 117 panic_memtrap(istate, access, page, "Page fault."); 121 118 } 122 119 } -
kernel/arch/ia32/src/mm/tlb.c
rfe7abd0 rcefb126 27 27 */ 28 28 29 /** @addtogroup ia32mm 29 /** @addtogroup ia32mm 30 30 * @{ 31 31 */ -
kernel/arch/ia32/src/smp/apic.c
rfe7abd0 rcefb126 76 76 77 77 uint32_t apic_id_mask = 0; 78 uint8_t bsp_l_apic = 0; 79 78 80 static irq_t l_apic_timer_irq; 79 81 … … 154 156 } 155 157 158 /** Get Local APIC ID. 159 * 160 * @return Local APIC ID. 161 * 162 */ 163 static uint8_t l_apic_id(void) 164 { 165 l_apic_id_t idreg; 166 167 idreg.value = l_apic[L_APIC_ID]; 168 return idreg.apic_id; 169 } 170 156 171 /** Initialize APIC on BSP. */ 157 172 void apic_init(void) … … 208 223 l_apic_init(); 209 224 l_apic_debug(); 225 226 bsp_l_apic = l_apic_id(); 210 227 } 211 228 … … 460 477 { 461 478 #ifdef LAPIC_VERBOSE 462 printf("LVT on cpu%" PRIs ", LAPIC ID: %" PRIu8 "\n", CPU->id, l_apic_id()); 479 printf("LVT on cpu%" PRIs ", LAPIC ID: %" PRIu8 "\n", 480 CPU->id, l_apic_id()); 463 481 464 482 lvt_tm_t tm; 465 483 tm.value = l_apic[LVT_Tm]; 466 printf("LVT Tm: vector=%hhd, %s, %s, %s\n", tm.vector, delivs_str[tm.delivs], mask_str[tm.masked], tm_mode_str[tm.mode]); 484 printf("LVT Tm: vector=%" PRIu8 ", %s, %s, %s\n", 485 tm.vector, delivs_str[tm.delivs], mask_str[tm.masked], 486 tm_mode_str[tm.mode]); 467 487 468 488 lvt_lint_t lint; 469 489 lint.value = l_apic[LVT_LINT0]; 470 printf("LVT LINT0: vector=%hhd, %s, %s, %s, irr=%d, %s, %s\n", tm.vector, delmod_str[lint.delmod], delivs_str[lint.delivs], intpol_str[lint.intpol], lint.irr, trigmod_str[lint.trigger_mode], mask_str[lint.masked]); 471 lint.value = l_apic[LVT_LINT1]; 472 printf("LVT LINT1: vector=%hhd, %s, %s, %s, irr=%d, %s, %s\n", tm.vector, delmod_str[lint.delmod], delivs_str[lint.delivs], intpol_str[lint.intpol], lint.irr, trigmod_str[lint.trigger_mode], mask_str[lint.masked]); 490 printf("LVT LINT0: vector=%" PRIu8 ", %s, %s, %s, irr=%u, %s, %s\n", 491 tm.vector, delmod_str[lint.delmod], delivs_str[lint.delivs], 492 intpol_str[lint.intpol], lint.irr, trigmod_str[lint.trigger_mode], 493 mask_str[lint.masked]); 494 495 lint.value = l_apic[LVT_LINT1]; 496 printf("LVT LINT1: vector=%" PRIu8 ", %s, %s, %s, irr=%u, %s, %s\n", 497 tm.vector, delmod_str[lint.delmod], delivs_str[lint.delivs], 498 intpol_str[lint.intpol], lint.irr, trigmod_str[lint.trigger_mode], 499 mask_str[lint.masked]); 473 500 474 501 lvt_error_t error; 475 502 error.value = l_apic[LVT_Err]; 476 printf("LVT Err: vector=%hhd, %s, %s\n", error.vector, delivs_str[error.delivs], mask_str[error.masked]); 503 printf("LVT Err: vector=%" PRIu8 ", %s, %s\n", error.vector, 504 delivs_str[error.delivs], mask_str[error.masked]); 477 505 #endif 478 }479 480 /** Get Local APIC ID.481 *482 * @return Local APIC ID.483 *484 */485 uint8_t l_apic_id(void)486 {487 l_apic_id_t idreg;488 489 idreg.value = l_apic[L_APIC_ID];490 return idreg.apic_id;491 506 } 492 507 -
kernel/arch/ia32/src/smp/mps.c
rfe7abd0 rcefb126 27 27 */ 28 28 29 /** @addtogroup ia32 29 /** @addtogroup ia32 30 30 * @{ 31 31 */ … … 52 52 */ 53 53 54 #define FS_SIGNATURE 0x5f504d5f 55 #define CT_SIGNATURE 0x504d4350 56 57 static int mps_fs_check(uint8_t *base); 58 static int mps_ct_check(void); 59 60 static int configure_via_ct(void); 61 static int configure_via_default(uint8_t n); 62 63 static int ct_processor_entry(struct __processor_entry *pr); 64 static void ct_bus_entry(struct __bus_entry *bus); 65 static void ct_io_apic_entry(struct __io_apic_entry *ioa); 66 static void ct_io_intr_entry(struct __io_intr_entry *iointr); 67 static void ct_l_intr_entry(struct __l_intr_entry *lintr); 68 69 static void ct_extended_entries(void); 54 #define FS_SIGNATURE 0x5f504d5f 55 #define CT_SIGNATURE 0x504d4350 70 56 71 57 static struct mps_fs *fs; 72 58 static struct mps_ct *ct; 73 59 74 struct __processor_entry *processor_entries = NULL; 75 struct __bus_entry *bus_entries = NULL; 76 struct __io_apic_entry *io_apic_entries = NULL; 77 struct __io_intr_entry *io_intr_entries = NULL; 78 struct __l_intr_entry *l_intr_entries = NULL; 79 80 unsigned int processor_entry_cnt = 0; 81 unsigned int bus_entry_cnt = 0; 82 unsigned int io_apic_entry_cnt = 0; 83 unsigned int io_intr_entry_cnt = 0; 84 unsigned int l_intr_entry_cnt = 0; 85 86 /* 87 * Implementation of IA-32 SMP configuration interface. 88 */ 89 static size_t get_cpu_count(void); 90 static bool is_cpu_enabled(size_t i); 91 static bool is_bsp(size_t i); 92 static uint8_t get_cpu_apic_id(size_t i); 93 static int mps_irq_to_pin(unsigned int irq); 94 60 static struct __processor_entry *processor_entries = NULL; 61 static struct __bus_entry *bus_entries = NULL; 62 static struct __io_apic_entry *io_apic_entries = NULL; 63 static struct __io_intr_entry *io_intr_entries = NULL; 64 static struct __l_intr_entry *l_intr_entries = NULL; 65 66 static size_t io_apic_cnt = 0; 67 68 static size_t processor_entry_cnt = 0; 69 static size_t bus_entry_cnt = 0; 70 static size_t io_apic_entry_cnt = 0; 71 static size_t io_intr_entry_cnt = 0; 72 static size_t l_intr_entry_cnt = 0; 73 74 static uint8_t mps_cpu_apic_id(size_t i) 75 { 76 ASSERT(i < processor_entry_cnt); 77 78 return processor_entries[i].l_apic_id; 79 } 80 81 static bool mps_cpu_enabled(size_t i) 82 { 83 ASSERT(i < processor_entry_cnt); 84 85 /* 86 * FIXME: The current local APIC driver limits usable 87 * CPU IDs to 8. 88 * 89 */ 90 if (i > 7) 91 return false; 92 93 return (bool) ((processor_entries[i].cpu_flags & 0x01) == 0x01); 94 } 95 96 static bool mps_cpu_bootstrap(size_t i) 97 { 98 ASSERT(i < processor_entry_cnt); 99 100 return (bool) ((processor_entries[i].cpu_flags & 0x02) == 0x02); 101 } 102 103 static int mps_irq_to_pin(unsigned int irq) 104 { 105 size_t i; 106 107 for (i = 0; i < io_intr_entry_cnt; i++) { 108 if (io_intr_entries[i].src_bus_irq == irq && 109 io_intr_entries[i].intr_type == 0) 110 return io_intr_entries[i].dst_io_apic_pin; 111 } 112 113 return -1; 114 } 115 116 /** Implementation of IA-32 SMP configuration interface. 117 * 118 */ 95 119 struct smp_config_operations mps_config_operations = { 96 .cpu_count = get_cpu_count, 97 .cpu_enabled = is_cpu_enabled, 98 .cpu_bootstrap = is_bsp, 99 .cpu_apic_id = get_cpu_apic_id, 120 .cpu_enabled = mps_cpu_enabled, 121 .cpu_bootstrap = mps_cpu_bootstrap, 122 .cpu_apic_id = mps_cpu_apic_id, 100 123 .irq_to_pin = mps_irq_to_pin 101 124 }; 102 125 103 size_t get_cpu_count(void) 104 { 105 return processor_entry_cnt; 106 } 107 108 bool is_cpu_enabled(size_t i) 109 { 110 ASSERT(i < processor_entry_cnt); 111 return (bool) ((processor_entries[i].cpu_flags & 0x01) == 0x01); 112 } 113 114 bool is_bsp(size_t i) 115 { 116 ASSERT(i < processor_entry_cnt); 117 return (bool) ((processor_entries[i].cpu_flags & 0x02) == 0x02); 118 } 119 120 uint8_t get_cpu_apic_id(size_t i) 121 { 122 ASSERT(i < processor_entry_cnt); 123 return processor_entries[i].l_apic_id; 124 } 125 126 127 /* 128 * Used to check the integrity of the MP Floating Structure. 129 */ 130 int mps_fs_check(uint8_t *base) 126 /** Check the integrity of the MP Floating Structure. 127 * 128 */ 129 static bool mps_fs_check(uint8_t *base) 131 130 { 132 131 unsigned int i; … … 136 135 sum = (uint8_t) (sum + base[i]); 137 136 138 return !sum;139 } 140 141 /* 142 * Used to check the integrity of the MP Configuration Table.143 */ 144 intmps_ct_check(void)137 return (sum == 0); 138 } 139 140 /** Check the integrity of the MP Configuration Table. 141 * 142 */ 143 static bool mps_ct_check(void) 145 144 { 146 145 uint8_t *base = (uint8_t *) ct; 147 146 uint8_t *ext = base + ct->base_table_length; 148 147 uint8_t sum; 149 int i;150 151 /* countthe checksum for the base table */152 for (i = 0, sum = 0; i < ct->base_table_length; i++)148 uint16_t i; 149 150 /* Compute the checksum for the base table */ 151 for (i = 0, sum = 0; i < ct->base_table_length; i++) 153 152 sum = (uint8_t) (sum + base[i]); 154 153 155 154 if (sum) 156 return 0;157 158 /* countthe checksum for the extended table */155 return false; 156 157 /* Compute the checksum for the extended table */ 159 158 for (i = 0, sum = 0; i < ct->ext_table_length; i++) 160 159 sum = (uint8_t) (sum + ext[i]); 161 162 return sum == ct->ext_table_checksum; 163 } 164 165 void mps_init(void) 166 { 167 uint8_t *addr[2] = { NULL, (uint8_t *) PA2KA(0xf0000) }; 168 unsigned int i, j, length[2] = { 1024, 64 * 1024 }; 169 170 160 161 return (sum == ct->ext_table_checksum); 162 } 163 164 static void ct_processor_entry(struct __processor_entry *pr) 165 { 171 166 /* 172 * Find MP Floating Pointer Structure 173 * 1a. search first 1K of EBDA 174 * 1b. if EBDA is undefined, search last 1K of base memory 175 * 2. search 64K starting at 0xf0000 167 * Ignore processors which are not marked enabled. 176 168 */ 177 178 addr[0] = (uint8_t *) PA2KA(ebda ? ebda : 639 * 1024); 179 for (i = 0; i < 2; i++) { 180 for (j = 0; j < length[i]; j += 16) { 181 if (*((uint32_t *) &addr[i][j]) == 182 FS_SIGNATURE && mps_fs_check(&addr[i][j])) { 183 fs = (struct mps_fs *) &addr[i][j]; 184 goto fs_found; 185 } 169 if ((pr->cpu_flags & (1 << 0)) == 0) 170 return; 171 172 apic_id_mask |= (1 << pr->l_apic_id); 173 } 174 175 static void ct_bus_entry(struct __bus_entry *bus __attribute__((unused))) 176 { 177 #ifdef MPSCT_VERBOSE 178 char buf[7]; 179 180 memcpy((void *) buf, (void *) bus->bus_type, 6); 181 buf[6] = 0; 182 183 printf("MPS: bus=%" PRIu8 " (%s)\n", bus->bus_id, buf); 184 #endif 185 } 186 187 static void ct_io_apic_entry(struct __io_apic_entry *ioa) 188 { 189 /* This I/O APIC is marked unusable */ 190 if ((ioa->io_apic_flags & 1) == 0) 191 return; 192 193 if (io_apic_cnt++ > 0) { 194 /* 195 * Multiple I/O APICs are currently not supported. 196 */ 197 return; 198 } 199 200 io_apic = (uint32_t *) (uintptr_t) ioa->io_apic; 201 } 202 203 static void ct_io_intr_entry(struct __io_intr_entry *iointr 204 __attribute__((unused))) 205 { 206 #ifdef MPSCT_VERBOSE 207 printf("MPS: "); 208 209 switch (iointr->intr_type) { 210 case 0: 211 printf("INT"); 212 break; 213 case 1: 214 printf("NMI"); 215 break; 216 case 2: 217 printf("SMI"); 218 break; 219 case 3: 220 printf("ExtINT"); 221 break; 222 } 223 224 printf(", "); 225 226 switch (iointr->poel & 3) { 227 case 0: 228 printf("bus-like"); 229 break; 230 case 1: 231 printf("active high"); 232 break; 233 case 2: 234 printf("reserved"); 235 break; 236 case 3: 237 printf("active low"); 238 break; 239 } 240 241 printf(", "); 242 243 switch ((iointr->poel >> 2) & 3) { 244 case 0: 245 printf("bus-like"); 246 break; 247 case 1: 248 printf("edge-triggered"); 249 break; 250 case 2: 251 printf("reserved"); 252 break; 253 case 3: 254 printf("level-triggered"); 255 break; 256 } 257 258 printf(", bus=%" PRIu8 " irq=%" PRIu8 " io_apic=%" PRIu8" pin=%" 259 PRIu8 "\n", iointr->src_bus_id, iointr->src_bus_irq, 260 iointr->dst_io_apic_id, iointr->dst_io_apic_pin); 261 #endif 262 } 263 264 static void ct_l_intr_entry(struct __l_intr_entry *lintr 265 __attribute__((unused))) 266 { 267 #ifdef MPSCT_VERBOSE 268 printf("MPS: "); 269 270 switch (lintr->intr_type) { 271 case 0: 272 printf("INT"); 273 break; 274 case 1: 275 printf("NMI"); 276 break; 277 case 2: 278 printf("SMI"); 279 break; 280 case 3: 281 printf("ExtINT"); 282 break; 283 } 284 285 printf(", "); 286 287 switch (lintr->poel & 3) { 288 case 0: 289 printf("bus-like"); 290 break; 291 case 1: 292 printf("active high"); 293 break; 294 case 2: 295 printf("reserved"); 296 break; 297 case 3: 298 printf("active low"); 299 break; 300 } 301 302 printf(", "); 303 304 switch ((lintr->poel >> 2) & 3) { 305 case 0: 306 printf("bus-like"); 307 break; 308 case 1: 309 printf("edge-triggered"); 310 break; 311 case 2: 312 printf("reserved"); 313 break; 314 case 3: 315 printf("level-triggered"); 316 break; 317 } 318 319 printf(", bus=%" PRIu8 " irq=%" PRIu8 " l_apic=%" PRIu8" pin=%" 320 PRIu8 "\n", lintr->src_bus_id, lintr->src_bus_irq, 321 lintr->dst_l_apic_id, lintr->dst_l_apic_pin); 322 #endif 323 } 324 325 static void ct_extended_entries(void) 326 { 327 uint8_t *ext = (uint8_t *) ct + ct->base_table_length; 328 uint8_t *cur; 329 330 for (cur = ext; cur < ext + ct->ext_table_length; 331 cur += cur[CT_EXT_ENTRY_LEN]) { 332 switch (cur[CT_EXT_ENTRY_TYPE]) { 333 default: 334 printf("MPS: Skipping MP Configuration Table extended " 335 "entry type %" PRIu8 "\n", cur[CT_EXT_ENTRY_TYPE]); 186 336 } 187 337 } 188 189 return; 190 191 fs_found: 192 printf("%p: MPS Floating Pointer Structure\n", fs); 193 194 if (fs->config_type == 0 && fs->configuration_table) { 195 if (fs->mpfib2 >> 7) { 196 printf("%s: PIC mode not supported\n", __func__); 197 return; 198 } 199 200 ct = (struct mps_ct *)PA2KA((uintptr_t)fs->configuration_table); 201 config.cpu_count = configure_via_ct(); 202 } 203 else 204 config.cpu_count = configure_via_default(fs->config_type); 205 206 return; 207 } 208 209 int configure_via_ct(void) 210 { 211 uint8_t *cur; 212 unsigned int i, cnt; 213 338 } 339 340 static void configure_via_ct(void) 341 { 214 342 if (ct->signature != CT_SIGNATURE) { 215 printf("%s: bad ct->signature\n", __func__); 216 return 1; 217 } 343 printf("MPS: Wrong ct->signature\n"); 344 return; 345 } 346 218 347 if (!mps_ct_check()) { 219 printf("%s: bad ct checksum\n", __func__); 220 return 1; 221 } 348 printf("MPS: Wrong ct checksum\n"); 349 return; 350 } 351 222 352 if (ct->oem_table) { 223 printf("%s: ct->oem_table not supported\n", __func__); 224 return 1; 225 } 226 227 l_apic = (uint32_t *)(uintptr_t)ct->l_apic; 228 229 cnt = 0; 230 cur = &ct->base_table[0]; 353 printf("MPS: ct->oem_table not supported\n"); 354 return; 355 } 356 357 l_apic = (uint32_t *) (uintptr_t) ct->l_apic; 358 359 uint8_t *cur = &ct->base_table[0]; 360 uint16_t i; 361 231 362 for (i = 0; i < ct->entry_count; i++) { 232 363 switch (*cur) { 233 /* Processor entry */ 234 case 0: 364 case 0: /* Processor entry */ 235 365 processor_entries = processor_entries ? 236 366 processor_entries : 237 367 (struct __processor_entry *) cur; 238 368 processor_entry_cnt++; 239 cnt += ct_processor_entry((struct __processor_entry *) 240 cur); 369 ct_processor_entry((struct __processor_entry *) cur); 241 370 cur += 20; 242 371 break; 243 244 /* Bus entry */ 245 case 1: 372 case 1: /* Bus entry */ 246 373 bus_entries = bus_entries ? 247 374 bus_entries : (struct __bus_entry *) cur; … … 250 377 cur += 8; 251 378 break; 252 253 /* I/O Apic */ 254 case 2: 379 case 2: /* I/O APIC */ 255 380 io_apic_entries = io_apic_entries ? 256 381 io_apic_entries : (struct __io_apic_entry *) cur; 257 io_apic_entry_cnt++;382 io_apic_entry_cnt++; 258 383 ct_io_apic_entry((struct __io_apic_entry *) cur); 259 384 cur += 8; 260 385 break; 261 262 /* I/O Interrupt Assignment */ 263 case 3: 386 case 3: /* I/O Interrupt Assignment */ 264 387 io_intr_entries = io_intr_entries ? 265 388 io_intr_entries : (struct __io_intr_entry *) cur; … … 268 391 cur += 8; 269 392 break; 270 271 /* Local Interrupt Assignment */ 272 case 4: 393 case 4: /* Local Interrupt Assignment */ 273 394 l_intr_entries = l_intr_entries ? 274 395 l_intr_entries : (struct __l_intr_entry *) cur; … … 277 398 cur += 8; 278 399 break; 279 280 400 default: 281 401 /* 282 402 * Something is wrong. Fallback to UP mode. 283 403 */ 284 285 printf("%s: ct badness\n", __func__); 286 return 1; 404 printf("MPS: ct badness %" PRIu8 "\n", *cur); 405 return; 287 406 } 288 407 } … … 292 411 */ 293 412 ct_extended_entries(); 294 return cnt; 295 } 296 297 int configure_via_default(uint8_t n __attribute__((unused))) 413 } 414 415 static void configure_via_default(uint8_t n __attribute__((unused))) 298 416 { 299 417 /* 300 418 * Not yet implemented. 301 419 */ 302 printf("%s: not supported\n", __func__); 303 return 1; 304 } 305 306 307 int ct_processor_entry(struct __processor_entry *pr __attribute__((unused))) 308 { 420 printf("MPS: Default configuration not supported\n"); 421 } 422 423 void mps_init(void) 424 { 425 uint8_t *addr[2] = { NULL, (uint8_t *) PA2KA(0xf0000) }; 426 unsigned int i; 427 unsigned int j; 428 unsigned int length[2] = { 1024, 64 * 1024 }; 429 309 430 /* 310 * Ignore processors which are not marked enabled. 431 * Find MP Floating Pointer Structure 432 * 1a. search first 1K of EBDA 433 * 1b. if EBDA is undefined, search last 1K of base memory 434 * 2. search 64K starting at 0xf0000 311 435 */ 312 if ((pr->cpu_flags & (1 << 0)) == 0) 313 return 0; 314 315 apic_id_mask |= (1 << pr->l_apic_id); 316 return 1; 317 } 318 319 void ct_bus_entry(struct __bus_entry *bus __attribute__((unused))) 320 { 321 #ifdef MPSCT_VERBOSE 322 char buf[7]; 323 memcpy((void *) buf, (void *) bus->bus_type, 6); 324 buf[6] = 0; 325 printf("bus%d: %s\n", bus->bus_id, buf); 326 #endif 327 } 328 329 void ct_io_apic_entry(struct __io_apic_entry *ioa) 330 { 331 static unsigned int io_apic_count = 0; 332 333 /* this ioapic is marked unusable */ 334 if ((ioa->io_apic_flags & 1) == 0) 335 return; 336 337 if (io_apic_count++ > 0) { 338 /* 339 * Multiple IO APIC's are currently not supported. 340 */ 341 return; 342 } 343 344 io_apic = (uint32_t *)(uintptr_t)ioa->io_apic; 345 } 346 347 //#define MPSCT_VERBOSE 348 void ct_io_intr_entry(struct __io_intr_entry *iointr __attribute__((unused))) 349 { 350 #ifdef MPSCT_VERBOSE 351 switch (iointr->intr_type) { 352 case 0: 353 printf("INT"); 354 break; 355 case 1: 356 printf("NMI"); 357 break; 358 case 2: 359 printf("SMI"); 360 break; 361 case 3: 362 printf("ExtINT"); 363 break; 364 } 365 putchar(','); 366 switch (iointr->poel & 3) { 367 case 0: 368 printf("bus-like"); 369 break; 370 case 1: 371 printf("active high"); 372 break; 373 case 2: 374 printf("reserved"); 375 break; 376 case 3: 377 printf("active low"); 378 break; 379 } 380 putchar(','); 381 switch ((iointr->poel >> 2) & 3) { 382 case 0: 383 printf("bus-like"); 384 break; 385 case 1: 386 printf("edge-triggered"); 387 break; 388 case 2: 389 printf("reserved"); 390 break; 391 case 3: 392 printf("level-triggered"); 393 break; 394 } 395 putchar(','); 396 printf("bus%d,irq%d", iointr->src_bus_id, iointr->src_bus_irq); 397 putchar(','); 398 printf("io_apic%d,pin%d", iointr->dst_io_apic_id, 399 iointr->dst_io_apic_pin); 400 putchar('\n'); 401 #endif 402 } 403 404 void ct_l_intr_entry(struct __l_intr_entry *lintr __attribute__((unused))) 405 { 406 #ifdef MPSCT_VERBOSE 407 switch (lintr->intr_type) { 408 case 0: 409 printf("INT"); 410 break; 411 case 1: 412 printf("NMI"); 413 break; 414 case 2: 415 printf("SMI"); 416 break; 417 case 3: 418 printf("ExtINT"); 419 break; 420 } 421 putchar(','); 422 switch (lintr->poel & 3) { 423 case 0: 424 printf("bus-like"); 425 break; 426 case 1: 427 printf("active high"); 428 break; 429 case 2: 430 printf("reserved"); 431 break; 432 case 3: 433 printf("active low"); 434 break; 435 } 436 putchar(','); 437 switch ((lintr->poel >> 2) & 3) { 438 case 0: 439 printf("bus-like"); 440 break; 441 case 1: 442 printf("edge-triggered"); 443 break; 444 case 2: 445 printf("reserved"); 446 break; 447 case 3: 448 printf("level-triggered"); 449 break; 450 } 451 putchar(','); 452 printf("bus%d,irq%d", lintr->src_bus_id, lintr->src_bus_irq); 453 putchar(','); 454 printf("l_apic%d,pin%d", lintr->dst_l_apic_id, lintr->dst_l_apic_pin); 455 putchar('\n'); 456 #endif 457 } 458 459 void ct_extended_entries(void) 460 { 461 uint8_t *ext = (uint8_t *) ct + ct->base_table_length; 462 uint8_t *cur; 463 464 for (cur = ext; cur < ext + ct->ext_table_length; 465 cur += cur[CT_EXT_ENTRY_LEN]) { 466 switch (cur[CT_EXT_ENTRY_TYPE]) { 467 default: 468 printf("%p: skipping MP Configuration Table extended " 469 "entry type %d\n", cur, cur[CT_EXT_ENTRY_TYPE]); 470 break; 436 437 addr[0] = (uint8_t *) PA2KA(ebda ? ebda : 639 * 1024); 438 for (i = 0; i < 2; i++) { 439 for (j = 0; j < length[i]; j += 16) { 440 if ((*((uint32_t *) &addr[i][j]) == 441 FS_SIGNATURE) && (mps_fs_check(&addr[i][j]))) { 442 fs = (struct mps_fs *) &addr[i][j]; 443 goto fs_found; 444 } 471 445 } 472 446 } 473 } 474 475 int mps_irq_to_pin(unsigned int irq) 476 { 477 unsigned int i; 478 479 for (i = 0; i < io_intr_entry_cnt; i++) { 480 if (io_intr_entries[i].src_bus_irq == irq && 481 io_intr_entries[i].intr_type == 0) 482 return io_intr_entries[i].dst_io_apic_pin; 483 } 484 485 return -1; 447 448 return; 449 450 fs_found: 451 printf("%p: MPS Floating Pointer Structure\n", fs); 452 453 if ((fs->config_type == 0) && (fs->configuration_table)) { 454 if (fs->mpfib2 >> 7) { 455 printf("MPS: PIC mode not supported\n"); 456 return; 457 } 458 459 ct = (struct mps_ct *) PA2KA((uintptr_t) fs->configuration_table); 460 configure_via_ct(); 461 } else 462 configure_via_default(fs->config_type); 463 464 if (processor_entry_cnt > 0) 465 config.cpu_count = processor_entry_cnt; 486 466 } 487 467 -
kernel/arch/ia32/src/smp/smp.c
rfe7abd0 rcefb126 62 62 void smp_init(void) 63 63 { 64 uintptr_t l_apic_address, io_apic_address;65 66 64 if (acpi_madt) { 67 65 acpi_madt_parse(); 68 66 ops = &madt_config_operations; 69 67 } 68 70 69 if (config.cpu_count == 1) { 71 70 mps_init(); 72 71 ops = &mps_config_operations; 73 72 } 74 75 l_apic_address = (uintptr_t) frame_alloc(ONE_FRAME, 76 FRAME_ATOMIC | FRAME_KA); 77 if (!l_apic_address) 78 panic("Cannot allocate address for l_apic."); 79 80 io_apic_address = (uintptr_t) frame_alloc(ONE_FRAME, 81 FRAME_ATOMIC | FRAME_KA); 82 if (!io_apic_address) 83 panic("Cannot allocate address for io_apic."); 84 73 85 74 if (config.cpu_count > 1) { 86 page_table_lock(AS_KERNEL, true); 87 page_mapping_insert(AS_KERNEL, l_apic_address, 88 (uintptr_t) l_apic, PAGE_NOT_CACHEABLE | PAGE_WRITE); 89 page_mapping_insert(AS_KERNEL, io_apic_address, 90 (uintptr_t) io_apic, PAGE_NOT_CACHEABLE | PAGE_WRITE); 91 page_table_unlock(AS_KERNEL, true); 92 93 l_apic = (uint32_t *) l_apic_address; 94 io_apic = (uint32_t *) io_apic_address; 75 l_apic = (uint32_t *) hw_map((uintptr_t) l_apic, PAGE_SIZE); 76 io_apic = (uint32_t *) hw_map((uintptr_t) io_apic, PAGE_SIZE); 95 77 } 96 78 } … … 108 90 109 91 ASSERT(ops != NULL); 110 92 111 93 /* 112 94 * We need to access data in frame 0. 113 95 * We boldly make use of kernel address space mapping. 114 96 */ 115 97 116 98 /* 117 99 * Set the warm-reset vector to the real-mode address of 4K-aligned ap_boot() 118 100 */ 119 101 *((uint16_t *) (PA2KA(0x467 + 0))) = 120 (uint16_t) (((uintptr_t) ap_boot) >> 4); /* segment */121 *((uint16_t *) (PA2KA(0x467 + 2))) = 0; /* offset */102 (uint16_t) (((uintptr_t) ap_boot) >> 4); /* segment */ 103 *((uint16_t *) (PA2KA(0x467 + 2))) = 0; /* offset */ 122 104 123 105 /* … … 125 107 * BIOS will not do the POST after the INIT signal. 126 108 */ 127 pio_write_8((ioport8_t *) 0x70, 0xf);128 pio_write_8((ioport8_t *) 0x71, 0xa);129 109 pio_write_8((ioport8_t *) 0x70, 0xf); 110 pio_write_8((ioport8_t *) 0x71, 0xa); 111 130 112 pic_disable_irqs(0xffff); 131 113 apic_init(); 132 114 133 uint8_t apic = l_apic_id(); 134 135 for (i = 0; i < ops->cpu_count(); i++) { 136 descriptor_t *gdt_new; 137 115 for (i = 0; i < config.cpu_count; i++) { 138 116 /* 139 117 * Skip processors marked unusable. … … 141 119 if (!ops->cpu_enabled(i)) 142 120 continue; 143 121 144 122 /* 145 123 * The bootstrap processor is already up. … … 147 125 if (ops->cpu_bootstrap(i)) 148 126 continue; 149 150 if (ops->cpu_apic_id(i) == apic) {151 printf(" %s: bad processor entry #%u, will not send IPI "152 "to myself\n", __FUNCTION__,i);127 128 if (ops->cpu_apic_id(i) == bsp_l_apic) { 129 printf("kmp: bad processor entry #%u, will not send IPI " 130 "to myself\n", i); 153 131 continue; 154 132 } … … 162 140 * the memory subsystem 163 141 */ 164 gdt_new = (descriptor_t *) malloc(GDT_ITEMS * 165 sizeof(descriptor_t), FRAME_ATOMIC); 142 descriptor_t *gdt_new = 143 (descriptor_t *) malloc(GDT_ITEMS * sizeof(descriptor_t), 144 FRAME_ATOMIC); 166 145 if (!gdt_new) 167 146 panic("Cannot allocate memory for GDT."); 168 147 169 148 memcpy(gdt_new, gdt, GDT_ITEMS * sizeof(descriptor_t)); 170 149 memsetb(&gdt_new[TSS_DES], sizeof(descriptor_t), 0); … … 172 151 protected_ap_gdtr.base = KA2PA((uintptr_t) gdt_new); 173 152 gdtr.base = (uintptr_t) gdt_new; 174 153 175 154 if (l_apic_send_init_ipi(ops->cpu_apic_id(i))) { 176 155 /* … … 181 160 if (waitq_sleep_timeout(&ap_completion_wq, 1000000, 182 161 SYNCH_FLAGS_NONE) == ESYNCH_TIMEOUT) { 183 unsigned int cpu = (config.cpu_active > i) ?184 config.cpu_active : i;185 162 printf("%s: waiting for cpu%u (APIC ID = %d) " 186 "timed out\n", __FUNCTION__, cpu,163 "timed out\n", __FUNCTION__, i, 187 164 ops->cpu_apic_id(i)); 188 165 } -
kernel/arch/ia64/src/asm.S
rfe7abd0 rcefb126 1 # 2 #Copyright (c) 2005 Jakub Jermar3 #All rights reserved.4 # 5 #Redistribution and use in source and binary forms, with or without6 #modification, are permitted provided that the following conditions7 #are met:8 # 9 #- Redistributions of source code must retain the above copyright10 #notice, this list of conditions and the following disclaimer.11 #- Redistributions in binary form must reproduce the above copyright12 #notice, this list of conditions and the following disclaimer in the13 #documentation and/or other materials provided with the distribution.14 #- The name of the author may not be used to endorse or promote products15 #derived from this software without specific prior written permission.16 # 17 #THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR18 #IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES19 #OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.20 #IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,21 #INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT22 #NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,23 #DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY24 #THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT25 #(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF26 #THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.27 # 1 /* 2 * Copyright (c) 2005 Jakub Jermar 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * - Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * - Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * - The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 28 29 29 #include <arch/register.h> 30 30 31 31 .text 32 33 /** Copy memory from/to userspace.34 *35 * This memcpy() has been taken from the assembler output of36 * the generic _memcpy() and modified to have the failover part.37 *38 * @param in0 Destination address.39 * @param in1 Source address.40 * @param in2 Number of byte to copy.41 */42 32 .global memcpy 43 33 .global memcpy_from_uspace … … 45 35 .global memcpy_from_uspace_failover_address 46 36 .global memcpy_to_uspace_failover_address 37 38 /** Copy memory from/to userspace. 39 * 40 * This memcpy() has been taken from the assembler output of 41 * the generic _memcpy() and modified to have the failover part. 42 * 43 * @param in0 Destination address. 44 * @param in1 Source address. 45 * @param in2 Number of byte to copy. 46 * 47 */ 47 48 memcpy: 48 49 memcpy_from_uspace: 49 50 memcpy_to_uspace: 50 51 alloc loc0 = ar.pfs, 3, 1, 0, 0 51 52 52 53 adds r14 = 7, in1 53 54 mov r2 = ar.lc … … 55 56 and r14 = -8, r14 ;; 56 57 cmp.ne p6, p7 = r14, in1 57 (p7) br.cond.dpnt 3f ;; 58 0: 59 cmp.ne p6, p7 = 0, in2 60 (p7) br.cond.dpnt 2f ;; 61 (p6) adds r14 = -1, in2 62 (p6) mov r16 = r0 63 (p6) mov r17 = r0 ;; 64 (p6) mov ar.lc = r14 65 1: 66 add r14 = r16, in1 67 add r15 = r16, in0 68 adds r17 = 1, r17 ;; 69 ld1 r14 = [r14] 70 mov r16 = r17 ;; 71 st1 [r15] = r14 72 br.cloop.sptk.few 1b ;; 73 2: 74 mov ar.lc = r2 75 mov ar.pfs = loc0 76 br.ret.sptk.many rp 77 3: 78 adds r14 = 7, in0 ;; 79 and r14 = -8, r14 ;; 80 cmp.eq p6, p7 = r14, in0 81 (p7) br.cond.dptk 0b 82 shr.u r18 = in2, 3 ;; 83 cmp.ne p6, p7 = 0, r18 84 (p7) br.cond.dpnt 5f ;; 85 (p6) adds r14 = -1, r18 86 (p6) mov r16 = r0 87 (p6) mov r17 = r0 ;; 88 (p6) mov ar.lc = r14 89 4: 90 shladd r14 = r16, 3, r0 91 adds r16 = 1, r17 ;; 92 add r15 = in1, r14 93 add r14 = in0, r14 94 mov r17 = r16 ;; 95 ld8 r15 = [r15] ;; 96 st8 [r14] = r15 97 br.cloop.sptk.few 4b 98 5: 99 and r15 = 7, in2 100 shladd r14 = r18, 3, r0 101 mov r16 = r0 102 mov r18 = r0 ;; 103 cmp.eq p6, p7 = 0, r15 104 add in0 = r14, in0 105 adds r15 = -1, r15 106 add r17 = r14, in1 107 (p6) br.cond.dpnt 2b ;; 108 mov ar.lc = r15 109 6: 110 add r14 = r16, r17 111 add r15 = r16, in0 112 adds r16 = 1, r18 ;; 113 ld1 r14 = [r14] 114 mov r18 = r16 ;; 115 st1 [r15] = r14 116 br.cloop.sptk.few 6b ;; 117 mov ar.lc = r2 118 mov ar.pfs = loc0 119 br.ret.sptk.many rp 120 58 (p7) br.cond.dpnt 3f ;; 59 60 0: 61 62 cmp.ne p6, p7 = 0, in2 63 (p7) br.cond.dpnt 2f ;; 64 (p6) adds r14 = -1, in2 65 (p6) mov r16 = r0 66 (p6) mov r17 = r0 ;; 67 (p6) mov ar.lc = r14 68 69 1: 70 71 add r14 = r16, in1 72 add r15 = r16, in0 73 adds r17 = 1, r17 ;; 74 ld1 r14 = [r14] 75 mov r16 = r17 ;; 76 st1 [r15] = r14 77 br.cloop.sptk.few 1b ;; 78 79 2: 80 81 mov ar.lc = r2 82 mov ar.pfs = loc0 83 br.ret.sptk.many rp 84 85 3: 86 87 adds r14 = 7, in0 ;; 88 and r14 = -8, r14 ;; 89 cmp.eq p6, p7 = r14, in0 90 (p7) br.cond.dptk 0b 91 shr.u r18 = in2, 3 ;; 92 cmp.ne p6, p7 = 0, r18 93 (p7) br.cond.dpnt 5f ;; 94 (p6) adds r14 = -1, r18 95 (p6) mov r16 = r0 96 (p6) mov r17 = r0 ;; 97 (p6) mov ar.lc = r14 98 99 4: 100 101 shladd r14 = r16, 3, r0 102 adds r16 = 1, r17 ;; 103 add r15 = in1, r14 104 add r14 = in0, r14 105 mov r17 = r16 ;; 106 ld8 r15 = [r15] ;; 107 st8 [r14] = r15 108 br.cloop.sptk.few 4b 109 110 5: 111 112 and r15 = 7, in2 113 shladd r14 = r18, 3, r0 114 mov r16 = r0 115 mov r18 = r0 ;; 116 cmp.eq p6, p7 = 0, r15 117 add in0 = r14, in0 118 adds r15 = -1, r15 119 add r17 = r14, in1 120 (p6) br.cond.dpnt 2b ;; 121 mov ar.lc = r15 122 123 6: 124 125 add r14 = r16, r17 126 add r15 = r16, in0 127 adds r16 = 1, r18 ;; 128 ld1 r14 = [r14] 129 mov r18 = r16 ;; 130 st1 [r15] = r14 131 br.cloop.sptk.few 6b ;; 132 mov ar.lc = r2 133 mov ar.pfs = loc0 134 br.ret.sptk.many rp 135 121 136 memcpy_from_uspace_failover_address: 122 137 memcpy_to_uspace_failover_address: 123 mov r8 = r0 /* return 0 on failure */ 138 /* Return 0 on failure */ 139 mov r8 = r0 124 140 mov ar.pfs = loc0 125 141 br.ret.sptk.many rp … … 136 152 cpu_halt: 137 153 br cpu_halt 138 139 .global panic_printf140 panic_printf:141 {142 br.call.sptk.many b0=printf143 }144 br halt145 154 146 155 /** Switch to userspace - low level code. … … 152 161 * @param in4 Value to be stored in IPSR. 153 162 * @param in5 Value to be stored in RSC. 163 * 154 164 */ 155 165 .global switch_to_userspace 156 166 switch_to_userspace: 157 167 alloc loc0 = ar.pfs, 6, 3, 0, 0 158 rsm (PSR_IC_MASK | PSR_I_MASK) /* disable interruption collection and interrupts */ 168 169 /* Disable interruption collection and interrupts */ 170 rsm (PSR_IC_MASK | PSR_I_MASK) 159 171 srlz.d ;; 160 172 srlz.i ;; … … 163 175 mov cr.iip = in0 164 176 mov r12 = in1 165 177 166 178 xor r1 = r1, r1 167 179 … … 172 184 movl loc2 = PFM_MASK ;; 173 185 and loc1 = loc2, loc1 ;; 174 mov cr.ifs = loc1 ;; /* prevent decrementing BSP by rfi */175 186 mov cr.ifs = loc1 ;; /* prevent decrementing BSP by rfi */ 187 176 188 invala 177 189 178 190 mov loc1 = ar.rsc ;; 179 and loc1 = ~3, loc1 ;; 180 mov ar.rsc = loc1 ;; /* put RSE into enforced lazy mode */181 191 and loc1 = ~3, loc1 ;; 192 mov ar.rsc = loc1 ;; /* put RSE into enforced lazy mode */ 193 182 194 flushrs ;; 183 195 … … 188 200 189 201 rfi ;; 202 203 .global early_putchar 204 early_putchar: 205 br.ret.sptk.many b0 -
kernel/arch/ia64/src/interrupt.c
rfe7abd0 rcefb126 133 133 } 134 134 135 static void dump_interrupted_context(istate_t *istate) 136 { 137 putchar('\n'); 138 printf("Interrupted context dump:\n"); 135 void istate_decode(istate_t *istate) 136 { 139 137 printf("ar.bsp=%p\tar.bspstore=%p\n", istate->ar_bsp, 140 138 istate->ar_bspstore); … … 183 181 184 182 fault_if_from_uspace(istate, "General Exception (%s).", desc); 185 186 dump_interrupted_context(istate); 187 panic("General Exception (%s).", desc); 183 panic_badtrap(istate, vector, "General Exception (%s).", desc); 188 184 } 189 185 … … 195 191 fault_if_from_uspace(istate, "Interruption: %#hx (%s).", 196 192 (uint16_t) vector, vector_to_string(vector)); 197 dump_interrupted_context(istate); 198 panic("Interruption: %#hx (%s).", (uint16_t) vector, 199 vector_to_string(vector)); 193 panic_badtrap(istate, vector, "Interruption: %#hx (%s).", 194 (uint16_t) vector, vector_to_string(vector)); 200 195 #endif 201 196 } … … 226 221 fault_if_from_uspace(istate, "Interruption: %#hx (%s).", 227 222 (uint16_t) vector, vector_to_string(vector)); 228 dump_interrupted_context(istate); 229 panic("Interruption: %#hx (%s).", (uint16_t) vector, 230 vector_to_string(vector)); 223 panic_badtrap(istate, vector, "Interruption: %#hx (%s).", 224 (uint16_t) vector, vector_to_string(vector)); 231 225 } 232 226 -
kernel/arch/ia64/src/mm/tlb.c
rfe7abd0 rcefb126 500 500 if (as_page_fault(va, PF_ACCESS_EXEC, istate) == AS_PF_FAULT) { 501 501 fault_if_from_uspace(istate, "Page fault at %p.", va); 502 panic ("%s: va=%p, rid=%d, iip=%p.", __func__, va, rid,503 istate->cr_iip);502 panic_memtrap(istate, PF_ACCESS_EXEC, va, 503 "Page fault."); 504 504 } 505 505 } … … 622 622 if (as_page_fault(va, PF_ACCESS_READ, istate) == AS_PF_FAULT) { 623 623 fault_if_from_uspace(istate, "Page fault at %p.", va); 624 panic ("%s: va=%p, rid=%d, iip=%p.", __func__, va, rid,625 istate->cr_iip);624 panic_memtrap(istate, PF_ACCESS_READ, va, 625 "Page fault."); 626 626 } 627 627 } … … 671 671 if (as_page_fault(va, PF_ACCESS_WRITE, istate) == AS_PF_FAULT) { 672 672 fault_if_from_uspace(istate, "Page fault at %p.", va); 673 panic ("%s: va=%p, rid=%d, iip=%p.", __func__, va, rid,674 istate->cr_iip);673 panic_memtrap(istate, PF_ACCESS_WRITE, va, 674 "Page fault."); 675 675 } 676 676 } … … 708 708 if (as_page_fault(va, PF_ACCESS_EXEC, istate) == AS_PF_FAULT) { 709 709 fault_if_from_uspace(istate, "Page fault at %p.", va); 710 panic ("%s: va=%p, rid=%d, iip=%p.", __func__, va, rid,711 istate->cr_iip);710 panic_memtrap(istate, PF_ACCESS_EXEC, va, 711 "Page fault."); 712 712 } 713 713 } … … 745 745 if (as_page_fault(va, PF_ACCESS_READ, istate) == AS_PF_FAULT) { 746 746 fault_if_from_uspace(istate, "Page fault at %p.", va); 747 panic ("%s: va=%p, rid=%d, iip=%p.", __func__, va, rid,748 istate->cr_iip);747 panic_memtrap(istate, PF_ACCESS_READ, va, 748 "Page fault."); 749 749 } 750 750 } … … 778 778 if (as_page_fault(va, PF_ACCESS_WRITE, istate) == AS_PF_FAULT) { 779 779 fault_if_from_uspace(istate, "Page fault at %p.", va); 780 panic("%s: va=%p, rid=%d, iip=%p.", __func__, va, rid, 781 istate->cr_iip); 780 panic_memtrap(istate, PF_ACCESS_WRITE, va, "Page fault."); 782 781 } 783 782 page_table_unlock(AS, true); … … 819 818 if (as_page_fault(va, PF_ACCESS_READ, istate) == AS_PF_FAULT) { 820 819 fault_if_from_uspace(istate, "Page fault at %p.", va); 821 panic("%s: va=%p, rid=%d.", __func__, va, rid); 820 panic_memtrap(istate, PF_ACCESS_READ, va, 821 "Page fault."); 822 822 } 823 823 } -
kernel/arch/mips32/Makefile.inc
rfe7abd0 rcefb126 54 54 arch/$(KARCH)/src/start.S \ 55 55 arch/$(KARCH)/src/context.S \ 56 arch/$(KARCH)/src/panic.S \57 56 arch/$(KARCH)/src/mips32.c \ 58 57 arch/$(KARCH)/src/asm.S \ -
kernel/arch/mips32/src/asm.S
rfe7abd0 rcefb126 1 # 2 # Copyright (c) 2003-2004Jakub Jermar3 #All rights reserved.4 # 5 #Redistribution and use in source and binary forms, with or without6 #modification, are permitted provided that the following conditions7 #are met:8 # 9 #- Redistributions of source code must retain the above copyright10 #notice, this list of conditions and the following disclaimer.11 #- Redistributions in binary form must reproduce the above copyright12 #notice, this list of conditions and the following disclaimer in the13 #documentation and/or other materials provided with the distribution.14 #- The name of the author may not be used to endorse or promote products15 #derived from this software without specific prior written permission.16 # 17 #THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR18 #IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES19 #OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.20 #IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,21 #INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT22 #NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,23 #DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY24 #THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT25 #(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF26 #THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.27 # 1 /* 2 * Copyright (c) 2003 Jakub Jermar 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * - Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * - Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * - The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 28 29 29 #include <arch/asm/regname.h> … … 57 57 nop 58 58 59 60 59 .global memsetb 61 60 memsetb: … … 63 62 nop 64 63 65 66 64 .global memsetw 67 65 memsetw: 68 66 j _memsetw 69 67 nop 70 71 68 72 69 .global memcpy … … 78 75 memcpy_from_uspace: 79 76 memcpy_to_uspace: 80 move $t2, $a0 # save dst77 move $t2, $a0 /* save dst */ 81 78 82 79 addiu $v0, $a1, 3 83 li $v1, -4 # 0xfffffffffffffffc80 li $v1, -4 /* 0xfffffffffffffffc */ 84 81 and $v0, $v0, $v1 85 82 beq $a1, $v0, 3f … … 149 146 move $v0, $zero 150 147 151 152 153 148 .macro fpu_gp_save reg ctx 154 149 mfc1 $t0, $\reg … … 164 159 cfc1 $t0, $1 165 160 sw $t0, (\reg + 32) * 4(\ctx) 166 .endm 161 .endm 167 162 168 163 .macro fpu_ct_restore reg ctx … … 170 165 ctc1 $t0, $\reg 171 166 .endm 172 173 167 174 168 .global fpu_context_save … … 313 307 j $ra 314 308 nop 309 310 .global early_putchar 311 early_putchar: 312 j $ra 313 nop -
kernel/arch/mips32/src/debugger.c
rfe7abd0 rcefb126 260 260 unsigned int i; 261 261 262 printf("# Count Address INPROG ONESHOT FUNCCALL In symbol\n"); 263 printf("-- ----- ---------- ------ ------- -------- ---------\n"); 262 printf("[nr] [count] [address ] [inprog] [oneshot] [funccall] [in symbol\n"); 264 263 265 264 for (i = 0; i < BKPOINTS_MAX; i++) { … … 268 267 breakpoints[i].address); 269 268 270 printf("%- 2u %-5d %#10zx %-6s %-7s %-8s %s\n", i,269 printf("%-4u %7" PRIs " %p %-8s %-9s %-10s %s\n", i, 271 270 breakpoints[i].counter, breakpoints[i].address, 272 271 ((breakpoints[i].flags & BKPOINT_INPROG) ? "true" : -
kernel/arch/mips32/src/exception.c
rfe7abd0 rcefb126 72 72 }; 73 73 74 static void print_regdump(istate_t *istate) 75 { 76 printf("PC: %#x(%s) RA: %#x(%s), SP(%p)\n", istate->epc, 77 symtab_fmt_name_lookup(istate->epc), istate->ra, 78 symtab_fmt_name_lookup(istate->ra), istate->sp); 74 void istate_decode(istate_t *istate) 75 { 76 printf("at=%p\tv0=%p\tv1=%p\n", istate->at, istate->v0, istate->v1); 77 printf("a0=%p\ta1=%p\ta2=%p\n", istate->a0, istate->a1, istate->a2); 78 printf("a3=%p\tt0=%p\tt1=%p\n", istate->a3, istate->t0, istate->t1); 79 printf("t2=%p\tt3=%p\tt4=%p\n", istate->t2, istate->t3, istate->t4); 80 printf("t5=%p\tt6=%p\tt7=%p\n", istate->t5, istate->t6, istate->t7); 81 printf("t8=%p\tt9=%p\tgp=%p\n", istate->t8, istate->t9, istate->gp); 82 printf("sp=%p\tra=%p\t\n", istate->sp, istate->ra); 83 printf("lo=%p\thi=%p\t\n", istate->lo, istate->hi); 84 printf("cp0_status=%p\tcp0_epc=%p\tk1=%p\n", 85 istate->status, istate->epc, istate->k1); 79 86 } 80 87 … … 82 89 { 83 90 fault_if_from_uspace(istate, "Unhandled exception %s.", exctable[n]); 84 85 print_regdump(istate); 86 panic("Unhandled exception %s.", exctable[n]); 91 panic_badtrap(istate, n, "Unhandled exception %s.", exctable[n]); 87 92 } 88 93 … … 125 130 scheduler_fpu_lazy_request(); 126 131 else { 127 fault_if_from_uspace(istate, "Unhandled Coprocessor Unusable Exception."); 128 panic("Unhandled Coprocessor Unusable Exception."); 132 fault_if_from_uspace(istate, 133 "Unhandled Coprocessor Unusable Exception."); 134 panic_badtrap(istate, n, 135 "Unhandled Coprocessor Unusable Exception."); 129 136 } 130 137 } … … 162 169 static void syscall_exception(unsigned int n, istate_t *istate) 163 170 { 164 panic("Syscall is handled through shortcut.");171 fault_if_from_uspace(istate, "Syscall is handled through shortcut."); 165 172 } 166 173 -
kernel/arch/mips32/src/mm/frame.c
rfe7abd0 rcefb126 249 249 void physmem_print(void) 250 250 { 251 printf("Base Size\n"); 252 printf("---------- ----------\n"); 251 printf("[base ] [size ]\n"); 253 252 254 253 size_t i; -
kernel/arch/mips32/src/mm/tlb.c
rfe7abd0 rcefb126 321 321 void tlb_refill_fail(istate_t *istate) 322 322 { 323 const char *symbol = symtab_fmt_name_lookup(istate->epc); 324 const char *sym2 = symtab_fmt_name_lookup(istate->ra); 325 326 fault_if_from_uspace(istate, "TLB Refill Exception on %p.", 327 cp0_badvaddr_read()); 328 panic("%x: TLB Refill Exception at %x (%s<-%s).", cp0_badvaddr_read(), 329 istate->epc, symbol, sym2); 323 uintptr_t va = cp0_badvaddr_read(); 324 325 fault_if_from_uspace(istate, "TLB Refill Exception on %p.", va); 326 panic_memtrap(istate, PF_ACCESS_READ, va, "TLB Refill Exception."); 330 327 } 331 328 … … 333 330 void tlb_invalid_fail(istate_t *istate) 334 331 { 335 const char *symbol = symtab_fmt_name_lookup(istate->epc); 336 337 fault_if_from_uspace(istate, "TLB Invalid Exception on %p.", 338 cp0_badvaddr_read()); 339 panic("%x: TLB Invalid Exception at %x (%s).", cp0_badvaddr_read(), 340 istate->epc, symbol); 332 uintptr_t va = cp0_badvaddr_read(); 333 334 fault_if_from_uspace(istate, "TLB Invalid Exception on %p.", va); 335 panic_memtrap(istate, PF_ACCESS_READ, va, "TLB Invalid Exception."); 341 336 } 342 337 343 338 void tlb_modified_fail(istate_t *istate) 344 339 { 345 const char *symbol = symtab_fmt_name_lookup(istate->epc); 346 347 fault_if_from_uspace(istate, "TLB Modified Exception on %p.", 348 cp0_badvaddr_read()); 349 panic("%x: TLB Modified Exception at %x (%s).", cp0_badvaddr_read(), 350 istate->epc, symbol); 340 uintptr_t va = cp0_badvaddr_read(); 341 342 fault_if_from_uspace(istate, "TLB Modified Exception on %p.", va); 343 panic_memtrap(istate, PF_ACCESS_WRITE, va, "TLB Modified Exception."); 351 344 } 352 345 … … 455 448 hi_save.value = cp0_entry_hi_read(); 456 449 457 printf("# ASID VPN2 MASK G V D C PFN\n"); 458 printf("-- ---- ------ ---- - - - - ------\n"); 450 printf("[nr] [asid] [vpn2] [mask] [gvdc] [pfn ]\n"); 459 451 460 452 for (i = 0; i < TLB_ENTRY_COUNT; i++) { … … 467 459 lo1.value = cp0_entry_lo1_read(); 468 460 469 printf("%- 2u %-4u %#6x %#4x %1u %1u %1u %1u%#6x\n",461 printf("%-4u %-6u %#6x %#6x %1u%1u%1u%1u %#6x\n", 470 462 i, hi.asid, hi.vpn2, mask.mask, 471 463 lo0.g, lo0.v, lo0.d, lo0.c, lo0.pfn); 472 printf(" %1u %1u %1u %1u%#6x\n",464 printf(" %1u%1u%1u%1u %#6x\n", 473 465 lo1.g, lo1.v, lo1.d, lo1.c, lo1.pfn); 474 466 } -
kernel/arch/ppc32/Makefile.inc
rfe7abd0 rcefb126 40 40 ARCH_SOURCES = \ 41 41 arch/$(KARCH)/src/context.S \ 42 arch/$(KARCH)/src/debug/panic.s \43 42 arch/$(KARCH)/src/debug/stacktrace.c \ 44 43 arch/$(KARCH)/src/debug/stacktrace_asm.S \ -
kernel/arch/ppc32/include/interrupt.h
rfe7abd0 rcefb126 48 48 extern void start_decrementer(void); 49 49 extern void interrupt_init(void); 50 extern void extint_handler( int, istate_t *);50 extern void extint_handler(unsigned int, istate_t *); 51 51 52 52 #endif -
kernel/arch/ppc32/include/mm/tlb.h
rfe7abd0 rcefb126 76 76 77 77 extern void pht_init(void); 78 extern void pht_refill( int, istate_t *);78 extern void pht_refill(unsigned int, istate_t *); 79 79 80 extern bool pht_refill_real( int, istate_t *)80 extern bool pht_refill_real(unsigned int, istate_t *) 81 81 __attribute__ ((section("K_UNMAPPED_TEXT_START"))); 82 extern void tlb_refill_real( int, uint32_t, ptehi_t, ptelo_t, istate_t *)83 __attribute__ ((section("K_UNMAPPED_TEXT_START")));82 extern void tlb_refill_real(unsigned int, uint32_t, ptehi_t, ptelo_t, 83 istate_t *) __attribute__ ((section("K_UNMAPPED_TEXT_START"))); 84 84 85 85 #endif -
kernel/arch/ppc32/include/types.h
rfe7abd0 rcefb126 50 50 } fncptr_t; 51 51 52 /** <Formats for uintptr_t, size_t */52 /** Formats for uintptr_t, size_t */ 53 53 #define PRIp "x" 54 54 #define PRIs "u" 55 55 56 /** <Formats for (u)int8_t, (u)int16_t, (u)int32_t, (u)int64_t and (u)native_t */56 /** Formats for (u)int8_t, (u)int16_t, (u)int32_t, (u)int64_t and (u)native_t */ 57 57 #define PRId8 "d" 58 58 #define PRId16 "d" -
kernel/arch/ppc32/src/asm.S
rfe7abd0 rcefb126 1 # 2 #Copyright (c) 2005 Martin Decky3 #All rights reserved.4 # 5 #Redistribution and use in source and binary forms, with or without6 #modification, are permitted provided that the following conditions7 #are met:8 # 9 #- Redistributions of source code must retain the above copyright10 #notice, this list of conditions and the following disclaimer.11 #- Redistributions in binary form must reproduce the above copyright12 #notice, this list of conditions and the following disclaimer in the13 #documentation and/or other materials provided with the distribution.14 #- The name of the author may not be used to endorse or promote products15 #derived from this software without specific prior written permission.16 # 17 #THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR18 #IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES19 #OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.20 #IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,21 #INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT22 #NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,23 #DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY24 #THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT25 #(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF26 #THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.27 # 1 /* 2 * Copyright (c) 2005 Martin Decky 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * - Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * - Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * - The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 28 29 29 #include <arch/asm/regname.h> … … 42 42 .global memcpy_from_uspace_failover_address 43 43 .global memcpy_to_uspace_failover_address 44 .global early_putchar 44 45 45 46 userspace_asm: 46 47 47 # r3 = uspace_uarg 48 # r4 = stack 49 # r5 = entry 50 51 # disable interrupts 48 /* 49 * r3 = uspace_uarg 50 * r4 = stack 51 * r5 = entry 52 */ 53 54 /* Disable interrupts */ 52 55 53 56 mfmsr r31 … … 55 58 mtmsr r31 56 59 57 # set entry point60 /* Set entry point */ 58 61 59 62 mtsrr0 r5 60 63 61 # set problem state, enable interrupts64 /* Set problem state, enable interrupts */ 62 65 63 66 ori r31, r31, MSR_PR … … 65 68 mtsrr1 r31 66 69 67 # set stack70 /* Set stack */ 68 71 69 72 mr sp, r4 70 73 71 # %r6 is defined to hold pcb_ptr - set it to 074 /* %r6 is defined to hold pcb_ptr - set it to 0 */ 72 75 73 76 xor r6, r6, r6 74 77 75 # jump to userspace78 /* Jump to userspace */ 76 79 77 80 rfi … … 79 82 iret: 80 83 81 # disable interrupts84 /* Disable interrupts */ 82 85 83 86 mfmsr r31 … … 141 144 iret_syscall: 142 145 143 # reset decrementer146 /* Reset decrementer */ 144 147 145 148 li r31, 1000 146 149 mtdec r31 147 150 148 # disable interrupts151 /* Disable interrupts */ 149 152 150 153 mfmsr r31 … … 278 281 memcpy_from_uspace_failover_address: 279 282 memcpy_to_uspace_failover_address: 280 # return zero, failure283 /* Return zero, failure */ 281 284 xor r3, r3, r3 282 285 blr 286 287 early_putchar: 288 blr -
kernel/arch/ppc32/src/interrupt.c
rfe7abd0 rcefb126 52 52 } 53 53 54 void istate_decode(istate_t *istate) 55 { 56 printf("r0 =%p\tr1 =%p\tr2 =%p\n", istate->r0, istate->sp, istate->r2); 57 printf("r3 =%p\tr4 =%p\tr5 =%p\n", istate->r3, istate->r4, istate->r5); 58 printf("r6 =%p\tr7 =%p\tr8 =%p\n", istate->r6, istate->r7, istate->r8); 59 printf("r9 =%p\tr10=%p\tr11=%p\n", 60 istate->r9, istate->r10, istate->r11); 61 printf("r12=%p\tr13=%p\tr14=%p\n", 62 istate->r12, istate->r13, istate->r14); 63 printf("r15=%p\tr16=%p\tr17=%p\n", 64 istate->r15, istate->r16, istate->r17); 65 printf("r18=%p\tr19=%p\tr20=%p\n", 66 istate->r18, istate->r19, istate->r20); 67 printf("r21=%p\tr22=%p\tr23=%p\n", 68 istate->r21, istate->r22, istate->r23); 69 printf("r24=%p\tr25=%p\tr26=%p\n", 70 istate->r24, istate->r25, istate->r26); 71 printf("r27=%p\tr28=%p\tr29=%p\n", 72 istate->r27, istate->r28, istate->r29); 73 printf("r30=%p\tr31=%p\n", istate->r30, istate->r31); 74 printf("cr =%p\tpc =%p\tlr =%p\n", istate->cr, istate->pc, istate->lr); 75 printf("ctr=%p\txer=%p\tdar=%p\n", 76 istate->ctr, istate->xer, istate->dar); 77 printf("srr1=%p\n", istate->srr1); 78 } 79 54 80 /** External interrupts handler 55 81 * 56 82 */ 57 static void exception_external( int n, istate_t *istate)83 static void exception_external(unsigned int n, istate_t *istate) 58 84 { 59 85 uint8_t inum; … … 92 118 } 93 119 94 static void exception_decrementer( int n, istate_t *istate)120 static void exception_decrementer(unsigned int n, istate_t *istate) 95 121 { 96 122 start_decrementer(); -
kernel/arch/ppc32/src/mm/frame.c
rfe7abd0 rcefb126 45 45 void physmem_print(void) 46 46 { 47 printf("Base Size\n"); 48 printf("---------- ----------\n"); 47 printf("[base ] [size ]\n"); 49 48 50 49 size_t i; … … 61 60 62 61 for (i = 0; i < memmap.cnt; i++) { 63 pfn_t start = ADDR2PFN(ALIGN_UP((uintptr_t) memmap.zones[i].start, 64 FRAME_SIZE)); 65 size_t size = SIZE2FRAMES(ALIGN_DOWN(memmap.zones[i].size, FRAME_SIZE)); 62 /* To be safe, make the available zone possibly smaller */ 63 uintptr_t new_start = ALIGN_UP((uintptr_t) memmap.zones[i].start, 64 FRAME_SIZE); 65 size_t new_size = ALIGN_DOWN(memmap.zones[i].size - 66 (new_start - ((uintptr_t) memmap.zones[i].start)), FRAME_SIZE); 67 68 pfn_t pfn = ADDR2PFN(new_start); 69 size_t count = SIZE2FRAMES(new_size); 66 70 67 71 pfn_t conf; 68 if ((minconf < start) || (minconf >= start + size))69 conf = start;72 if ((minconf < pfn) || (minconf >= pfn + count)) 73 conf = pfn; 70 74 else 71 75 conf = minconf; 72 76 73 zone_create(start, size, conf, 0); 74 if (last_frame < ALIGN_UP((uintptr_t) memmap.zones[i].start 75 + memmap.zones[i].size, FRAME_SIZE)) 76 last_frame = ALIGN_UP((uintptr_t) memmap.zones[i].start 77 + memmap.zones[i].size, FRAME_SIZE); 77 zone_create(pfn, count, conf, 0); 78 79 if (last_frame < ALIGN_UP(new_start + new_size, FRAME_SIZE)) 80 last_frame = ALIGN_UP(new_start + new_size, FRAME_SIZE); 78 81 } 79 82 -
kernel/arch/ppc32/src/mm/tlb.c
rfe7abd0 rcefb126 111 111 static void pht_refill_fail(uintptr_t badvaddr, istate_t *istate) 112 112 { 113 const char *symbol = symtab_fmt_name_lookup(istate->pc); 114 const char *sym2 = symtab_fmt_name_lookup(istate->lr); 115 116 fault_if_from_uspace(istate, 117 "PHT Refill Exception on %p.", badvaddr); 118 panic("%p: PHT Refill Exception at %p (%s<-%s).", badvaddr, 119 istate->pc, symbol, sym2); 113 fault_if_from_uspace(istate, "PHT Refill Exception on %p.", badvaddr); 114 panic_memtrap(istate, PF_ACCESS_READ, badvaddr, 115 "PHT Refill Exception."); 120 116 } 121 117 … … 209 205 * 210 206 */ 211 void pht_refill( int n, istate_t *istate)207 void pht_refill(unsigned int n, istate_t *istate) 212 208 { 213 209 as_t *as = (AS == NULL) ? AS_KERNEL : AS; … … 260 256 * 261 257 */ 262 bool pht_refill_real( int n, istate_t *istate)258 bool pht_refill_real(unsigned int n, istate_t *istate) 263 259 { 264 260 uintptr_t badvaddr; … … 366 362 * 367 363 */ 368 void tlb_refill_real(int n, uint32_t tlbmiss, ptehi_t ptehi, ptelo_t ptelo, istate_t *istate) 364 void tlb_refill_real(unsigned int n, uint32_t tlbmiss, ptehi_t ptehi, 365 ptelo_t ptelo, istate_t *istate) 369 366 { 370 367 uint32_t badvaddr = tlbmiss & 0xfffffffc; -
kernel/arch/sparc64/Makefile.inc
rfe7abd0 rcefb126 64 64 arch/$(KARCH)/src/asm.S \ 65 65 arch/$(KARCH)/src/$(USARCH)/asm.S \ 66 arch/$(KARCH)/src/panic.S \67 66 arch/$(KARCH)/src/console.c \ 68 67 arch/$(KARCH)/src/context.S \ -
kernel/arch/sparc64/include/drivers/tick.h
rfe7abd0 rcefb126 27 27 */ 28 28 29 /** @addtogroup sparc64 29 /** @addtogroup sparc64 30 30 * @{ 31 31 */ … … 40 40 41 41 /* mask of the "counter" field of the Tick register */ 42 #define TICK_COUNTER_MASK (~(1l << 63))42 #define TICK_COUNTER_MASK (~(1l << 63)) 43 43 44 44 extern void tick_init(void); 45 extern void tick_interrupt( int n, istate_t *istate);45 extern void tick_interrupt(unsigned int, istate_t *); 46 46 47 47 /** -
kernel/arch/sparc64/include/types.h
rfe7abd0 rcefb126 52 52 typedef uint8_t asi_t; 53 53 54 /** <Formats for uintptr_t, size_t */54 /** Formats for uintptr_t, size_t */ 55 55 #define PRIp "llx" 56 56 #define PRIs "llu" 57 57 58 /** <Formats for (u)int8_t, (u)int16_t, (u)int32_t, (u)int64_t and (u)native_t */58 /** Formats for (u)int8_t, (u)int16_t, (u)int32_t, (u)int64_t and (u)native_t */ 59 59 #define PRId8 "d" 60 60 #define PRId16 "d" -
kernel/arch/sparc64/src/asm.S
rfe7abd0 rcefb126 1 # 2 #Copyright (c) 2005 Jakub Jermar3 #All rights reserved.4 # 5 #Redistribution and use in source and binary forms, with or without6 #modification, are permitted provided that the following conditions7 #are met:8 # 9 #- Redistributions of source code must retain the above copyright10 #notice, this list of conditions and the following disclaimer.11 #- Redistributions in binary form must reproduce the above copyright12 #notice, this list of conditions and the following disclaimer in the13 #documentation and/or other materials provided with the distribution.14 #- The name of the author may not be used to endorse or promote products15 #derived from this software without specific prior written permission.16 # 17 #THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR18 #IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES19 #OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.20 #IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,21 #INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT22 #NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,23 #DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY24 #THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT25 #(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF26 #THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.27 # 1 /* 2 * Copyright (c) 2005 Jakub Jermar 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * - Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * - Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * - The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 28 29 29 #include <arch/arch.h> … … 32 32 .text 33 33 34 .register %g2, #scratch35 .register %g3, #scratch34 .register %g2, #scratch 35 .register %g3, #scratch 36 36 37 37 /* … … 40 40 .global memcpy 41 41 memcpy: 42 mov %o0, %o3 ! save dst 43 add %o1, 7, %g1 44 and %g1, -8, %g1 45 cmp %o1, %g1 46 be,pn %xcc, 3f 47 add %o0, 7, %g1 48 mov 0, %g3 49 0: 50 brz,pn %o2, 2f 51 mov 0, %g2 52 1: 53 ldub [%g3 + %o1], %g1 54 add %g2, 1, %g2 55 cmp %o2, %g2 56 stb %g1, [%g3 + %o0] 57 bne,pt %xcc, 1b 58 mov %g2, %g3 59 2: 60 jmp %o7 + 8 ! exit point 61 mov %o3, %o0 62 3: 63 and %g1, -8, %g1 64 cmp %o0, %g1 65 bne,pt %xcc, 0b 66 mov 0, %g3 67 srlx %o2, 3, %g4 68 brz,pn %g4, 5f 69 mov 0, %g5 70 4: 71 sllx %g3, 3, %g2 72 add %g5, 1, %g3 73 ldx [%o1 + %g2], %g1 74 mov %g3, %g5 75 cmp %g4, %g3 76 bne,pt %xcc, 4b 77 stx %g1, [%o0 + %g2] 78 5: 79 and %o2, 7, %o2 80 brz,pn %o2, 2b 81 sllx %g4, 3, %g1 82 mov 0, %g2 83 add %g1, %o0, %o0 84 add %g1, %o1, %g4 85 mov 0, %g3 86 6: 87 ldub [%g2 + %g4], %g1 88 stb %g1, [%g2 + %o0] 89 add %g3, 1, %g2 90 cmp %o2, %g2 91 bne,pt %xcc, 6b 92 mov %g2, %g3 93 94 jmp %o7 + 8 ! exit point 95 mov %o3, %o0 42 mov %o0, %o3 /* save dst */ 43 add %o1, 7, %g1 44 and %g1, -8, %g1 45 cmp %o1, %g1 46 be,pn %xcc, 3f 47 add %o0, 7, %g1 48 mov 0, %g3 49 50 0: 51 52 brz,pn %o2, 2f 53 mov 0, %g2 54 55 1: 56 57 ldub [%g3 + %o1], %g1 58 add %g2, 1, %g2 59 cmp %o2, %g2 60 stb %g1, [%g3 + %o0] 61 bne,pt %xcc, 1b 62 mov %g2, %g3 63 64 2: 65 66 jmp %o7 + 8 /* exit point */ 67 mov %o3, %o0 68 69 3: 70 71 and %g1, -8, %g1 72 cmp %o0, %g1 73 bne,pt %xcc, 0b 74 mov 0, %g3 75 srlx %o2, 3, %g4 76 brz,pn %g4, 5f 77 mov 0, %g5 78 79 4: 80 81 sllx %g3, 3, %g2 82 add %g5, 1, %g3 83 ldx [%o1 + %g2], %g1 84 mov %g3, %g5 85 cmp %g4, %g3 86 bne,pt %xcc, 4b 87 stx %g1, [%o0 + %g2] 88 89 5: 90 91 and %o2, 7, %o2 92 brz,pn %o2, 2b 93 sllx %g4, 3, %g1 94 mov 0, %g2 95 add %g1, %o0, %o0 96 add %g1, %o1, %g4 97 mov 0, %g3 98 99 6: 100 101 ldub [%g2 + %g4], %g1 102 stb %g1, [%g2 + %o0] 103 add %g3, 1, %g2 104 cmp %o2, %g2 105 bne,pt %xcc, 6b 106 mov %g2, %g3 107 108 jmp %o7 + 8 /* exit point */ 109 mov %o3, %o0 96 110 97 111 /* … … 100 114 .global memcpy_from_uspace 101 115 memcpy_from_uspace: 102 mov %o0, %o3 ! save dst 103 add %o1, 7, %g1 104 and %g1, -8, %g1 105 cmp %o1, %g1 106 be,pn %xcc, 3f 107 add %o0, 7, %g1 108 mov 0, %g3 109 0: 110 brz,pn %o2, 2f 111 mov 0, %g2 112 1: 113 lduba [%g3 + %o1] ASI_AIUS, %g1 114 add %g2, 1, %g2 115 cmp %o2, %g2 116 stb %g1, [%g3 + %o0] 117 bne,pt %xcc, 1b 118 mov %g2, %g3 119 2: 120 jmp %o7 + 8 ! exit point 121 mov %o3, %o0 122 3: 123 and %g1, -8, %g1 124 cmp %o0, %g1 125 bne,pt %xcc, 0b 126 mov 0, %g3 127 srlx %o2, 3, %g4 128 brz,pn %g4, 5f 129 mov 0, %g5 130 4: 131 sllx %g3, 3, %g2 132 add %g5, 1, %g3 133 ldxa [%o1 + %g2] ASI_AIUS, %g1 134 mov %g3, %g5 135 cmp %g4, %g3 136 bne,pt %xcc, 4b 137 stx %g1, [%o0 + %g2] 138 5: 139 and %o2, 7, %o2 140 brz,pn %o2, 2b 141 sllx %g4, 3, %g1 142 mov 0, %g2 143 add %g1, %o0, %o0 144 add %g1, %o1, %g4 145 mov 0, %g3 146 6: 147 lduba [%g2 + %g4] ASI_AIUS, %g1 148 stb %g1, [%g2 + %o0] 149 add %g3, 1, %g2 150 cmp %o2, %g2 151 bne,pt %xcc, 6b 152 mov %g2, %g3 153 154 jmp %o7 + 8 ! exit point 155 mov %o3, %o0 116 mov %o0, %o3 /* save dst */ 117 add %o1, 7, %g1 118 and %g1, -8, %g1 119 cmp %o1, %g1 120 be,pn %xcc, 3f 121 add %o0, 7, %g1 122 mov 0, %g3 123 124 0: 125 126 brz,pn %o2, 2f 127 mov 0, %g2 128 129 1: 130 131 lduba [%g3 + %o1] ASI_AIUS, %g1 132 add %g2, 1, %g2 133 cmp %o2, %g2 134 stb %g1, [%g3 + %o0] 135 bne,pt %xcc, 1b 136 mov %g2, %g3 137 138 2: 139 140 jmp %o7 + 8 /* exit point */ 141 mov %o3, %o0 142 143 3: 144 145 and %g1, -8, %g1 146 cmp %o0, %g1 147 bne,pt %xcc, 0b 148 mov 0, %g3 149 srlx %o2, 3, %g4 150 brz,pn %g4, 5f 151 mov 0, %g5 152 153 4: 154 155 sllx %g3, 3, %g2 156 add %g5, 1, %g3 157 ldxa [%o1 + %g2] ASI_AIUS, %g1 158 mov %g3, %g5 159 cmp %g4, %g3 160 bne,pt %xcc, 4b 161 stx %g1, [%o0 + %g2] 162 163 5: 164 165 and %o2, 7, %o2 166 brz,pn %o2, 2b 167 sllx %g4, 3, %g1 168 mov 0, %g2 169 add %g1, %o0, %o0 170 add %g1, %o1, %g4 171 mov 0, %g3 172 173 6: 174 175 lduba [%g2 + %g4] ASI_AIUS, %g1 176 stb %g1, [%g2 + %o0] 177 add %g3, 1, %g2 178 cmp %o2, %g2 179 bne,pt %xcc, 6b 180 mov %g2, %g3 181 182 jmp %o7 + 8 /* exit point */ 183 mov %o3, %o0 156 184 157 185 /* … … 160 188 .global memcpy_to_uspace 161 189 memcpy_to_uspace: 162 mov %o0, %o3 ! save dst 163 add %o1, 7, %g1 164 and %g1, -8, %g1 165 cmp %o1, %g1 166 be,pn %xcc, 3f 167 add %o0, 7, %g1 168 mov 0, %g3 169 0: 170 brz,pn %o2, 2f 171 mov 0, %g2 172 1: 173 ldub [%g3 + %o1], %g1 174 add %g2, 1, %g2 175 cmp %o2, %g2 176 stba %g1, [%g3 + %o0] ASI_AIUS 177 bne,pt %xcc, 1b 178 mov %g2, %g3 179 2: 180 jmp %o7 + 8 ! exit point 181 mov %o3, %o0 182 3: 183 and %g1, -8, %g1 184 cmp %o0, %g1 185 bne,pt %xcc, 0b 186 mov 0, %g3 187 srlx %o2, 3, %g4 188 brz,pn %g4, 5f 189 mov 0, %g5 190 4: 191 sllx %g3, 3, %g2 192 add %g5, 1, %g3 193 ldx [%o1 + %g2], %g1 194 mov %g3, %g5 195 cmp %g4, %g3 196 bne,pt %xcc, 4b 197 stxa %g1, [%o0 + %g2] ASI_AIUS 198 5: 199 and %o2, 7, %o2 200 brz,pn %o2, 2b 201 sllx %g4, 3, %g1 202 mov 0, %g2 203 add %g1, %o0, %o0 204 add %g1, %o1, %g4 205 mov 0, %g3 206 6: 207 ldub [%g2 + %g4], %g1 208 stba %g1, [%g2 + %o0] ASI_AIUS 209 add %g3, 1, %g2 210 cmp %o2, %g2 211 bne,pt %xcc, 6b 212 mov %g2, %g3 213 214 jmp %o7 + 8 ! exit point 215 mov %o3, %o0 190 mov %o0, %o3 /* save dst */ 191 add %o1, 7, %g1 192 and %g1, -8, %g1 193 cmp %o1, %g1 194 be,pn %xcc, 3f 195 add %o0, 7, %g1 196 mov 0, %g3 197 198 0: 199 200 brz,pn %o2, 2f 201 mov 0, %g2 202 203 1: 204 205 ldub [%g3 + %o1], %g1 206 add %g2, 1, %g2 207 cmp %o2, %g2 208 stba %g1, [%g3 + %o0] ASI_AIUS 209 bne,pt %xcc, 1b 210 mov %g2, %g3 211 212 2: 213 214 jmp %o7 + 8 /* exit point */ 215 mov %o3, %o0 216 217 3: 218 219 and %g1, -8, %g1 220 cmp %o0, %g1 221 bne,pt %xcc, 0b 222 mov 0, %g3 223 srlx %o2, 3, %g4 224 brz,pn %g4, 5f 225 mov 0, %g5 226 227 4: 228 229 sllx %g3, 3, %g2 230 add %g5, 1, %g3 231 ldx [%o1 + %g2], %g1 232 mov %g3, %g5 233 cmp %g4, %g3 234 bne,pt %xcc, 4b 235 stxa %g1, [%o0 + %g2] ASI_AIUS 236 237 5: 238 239 and %o2, 7, %o2 240 brz,pn %o2, 2b 241 sllx %g4, 3, %g1 242 mov 0, %g2 243 add %g1, %o0, %o0 244 add %g1, %o1, %g4 245 mov 0, %g3 246 247 6: 248 249 ldub [%g2 + %g4], %g1 250 stba %g1, [%g2 + %o0] ASI_AIUS 251 add %g3, 1, %g2 252 cmp %o2, %g2 253 bne,pt %xcc, 6b 254 mov %g2, %g3 255 256 jmp %o7 + 8 /* exit point */ 257 mov %o3, %o0 216 258 217 259 .global memcpy_from_uspace_failover_address … … 219 261 memcpy_from_uspace_failover_address: 220 262 memcpy_to_uspace_failover_address: 221 jmp %o7 + 8 ! exit point222 mov %g0, %o0 ! return 0 on failure263 jmp %o7 + 8 /* exit point */ 264 mov %g0, %o0 /* return 0 on failure */ 223 265 224 266 .global memsetb … … 232 274 nop 233 275 276 .global early_putchar 277 early_putchar: 278 retl 279 nop -
kernel/arch/sparc64/src/drivers/tick.c
rfe7abd0 rcefb126 27 27 */ 28 28 29 /** @addtogroup sparc64 29 /** @addtogroup sparc64 30 30 * @{ 31 31 */ … … 77 77 /** Process tick interrupt. 78 78 * 79 * @param n Interrupt Level, 14, (can be ignored)79 * @param n Interrupt Level (14, can be ignored) 80 80 * @param istate Interrupted state. 81 * 81 82 */ 82 void tick_interrupt( int n, istate_t *istate)83 void tick_interrupt(unsigned int n, istate_t *istate) 83 84 { 84 85 softint_reg_t softint, clear; -
kernel/arch/sparc64/src/mm/sun4u/frame.c
rfe7abd0 rcefb126 49 49 void frame_arch_init(void) 50 50 { 51 unsigned int i;52 pfn_t confdata;53 54 51 if (config.cpu_active == 1) { 52 unsigned int i; 53 55 54 for (i = 0; i < memmap.cnt; i++) { 56 uintptr_t start = (uintptr_t) memmap.zones[i].start; 57 size_t size = memmap.zones[i].size; 58 55 /* To be safe, make the available zone possibly smaller */ 56 uintptr_t new_start = ALIGN_UP((uintptr_t) memmap.zones[i].start, 57 FRAME_SIZE); 58 size_t new_size = ALIGN_DOWN(memmap.zones[i].size - 59 (new_start - ((uintptr_t) memmap.zones[i].start)), FRAME_SIZE); 60 59 61 /* 60 62 * The memmap is created by HelenOS boot loader. 61 63 * It already contains no holes. 62 64 */ 63 64 confdata = ADDR2PFN(start); 65 66 pfn_t confdata = ADDR2PFN(new_start); 67 65 68 if (confdata == ADDR2PFN(KA2PA(PFN2ADDR(0)))) 66 69 confdata = ADDR2PFN(KA2PA(PFN2ADDR(2))); 67 zone_create(ADDR2PFN(start),68 SIZE2FRAMES(ALIGN_DOWN(size, FRAME_SIZE)),70 71 zone_create(ADDR2PFN(new_start), SIZE2FRAMES(new_size), 69 72 confdata, 0); 70 last_frame = max(last_frame, start + ALIGN_UP(size,71 FRAME_SIZE));73 74 last_frame = max(last_frame, new_start + new_size); 72 75 } 73 76 74 77 /* 75 78 * On sparc64, physical memory can start on a non-zero address. … … 80 83 frame_mark_unavailable(ADDR2PFN(KA2PA(PFN2ADDR(0))), 1); 81 84 } 82 85 83 86 end_of_identity = PA2KA(last_frame); 84 87 } -
kernel/arch/sparc64/src/mm/sun4u/tlb.c
rfe7abd0 rcefb126 27 27 */ 28 28 29 /** @addtogroup sparc64mm 29 /** @addtogroup sparc64mm 30 30 * @{ 31 31 */ … … 58 58 static void dtlb_pte_copy(pte_t *, size_t, bool); 59 59 static void itlb_pte_copy(pte_t *, size_t); 60 static void do_fast_instruction_access_mmu_miss_fault(istate_t *, const char *); 60 static void do_fast_instruction_access_mmu_miss_fault(istate_t *, uintptr_t, 61 const char *); 61 62 static void do_fast_data_access_mmu_miss_fault(istate_t *, tlb_tag_access_reg_t, 62 63 const char *); … … 222 223 * Forward the page fault to the address space page fault 223 224 * handler. 224 */ 225 */ 225 226 page_table_unlock(AS, true); 226 227 if (as_page_fault(page_16k, PF_ACCESS_EXEC, istate) == 227 228 AS_PF_FAULT) { 228 229 do_fast_instruction_access_mmu_miss_fault(istate, 229 __func__);230 istate->tpc, __func__); 230 231 } 231 232 } … … 258 259 /* NULL access in kernel */ 259 260 do_fast_data_access_mmu_miss_fault(istate, tag, 260 __func__);261 "Dereferencing NULL pointer"); 261 262 } else if (page_8k >= end_of_identity) { 262 263 /* … … 438 439 439 440 void do_fast_instruction_access_mmu_miss_fault(istate_t *istate, 440 const char *str) 441 { 442 fault_if_from_uspace(istate, "%s.", str); 443 dump_istate(istate); 444 panic("%s.", str); 441 uintptr_t va, const char *str) 442 { 443 fault_if_from_uspace(istate, "%s, Address=%p.", str, va); 444 panic_memtrap(istate, PF_ACCESS_EXEC, va, "%s.", str); 445 445 } 446 446 … … 451 451 452 452 va = tag.vpn << MMU_PAGE_WIDTH; 453 if (tag.context) { 454 fault_if_from_uspace(istate, "%s, Page=%p (ASID=%d).", str, va, 455 tag.context); 456 } 457 dump_istate(istate); 458 printf("Faulting page: %p, ASID=%d.\n", va, tag.context); 459 panic("%s.", str); 453 fault_if_from_uspace(istate, "%s, Page=%p (ASID=%d).", str, va, 454 tag.context); 455 panic_memtrap(istate, PF_ACCESS_READ, va, "%s.", str); 460 456 } 461 457 … … 466 462 467 463 va = tag.vpn << MMU_PAGE_WIDTH; 468 469 if (tag.context) { 470 fault_if_from_uspace(istate, "%s, Page=%p (ASID=%d).", str, va, 471 tag.context); 472 } 473 printf("Faulting page: %p, ASID=%d\n", va, tag.context); 474 dump_istate(istate); 475 panic("%s.", str); 464 fault_if_from_uspace(istate, "%s, Page=%p (ASID=%d).", str, va, 465 tag.context); 466 panic_memtrap(istate, PF_ACCESS_WRITE, va, "%s.", str); 476 467 } 477 468 -
kernel/arch/sparc64/src/mm/sun4v/frame.c
rfe7abd0 rcefb126 47 47 void frame_arch_init(void) 48 48 { 49 unsigned int i;50 pfn_t confdata;51 52 49 if (config.cpu_active == 1) { 50 unsigned int i; 51 53 52 for (i = 0; i < memmap.cnt; i++) { 54 uintptr_t start = (uintptr_t) memmap.zones[i].start; 55 size_t size = memmap.zones[i].size; 56 53 /* To be safe, make the available zone possibly smaller */ 54 uintptr_t new_start = ALIGN_UP((uintptr_t) memmap.zones[i].start, 55 FRAME_SIZE); 56 size_t new_size = ALIGN_DOWN(memmap.zones[i].size - 57 (new_start - ((uintptr_t) memmap.zones[i].start)), FRAME_SIZE); 58 57 59 /* 58 60 * The memmap is created by HelenOS boot loader. 59 61 * It already contains no holes. 60 62 */ 61 62 confdata = ADDR2PFN(start); 63 64 pfn_t confdata = ADDR2PFN(new_start); 65 63 66 if (confdata == ADDR2PFN(KA2PA(PFN2ADDR(0)))) 64 67 confdata = ADDR2PFN(KA2PA(PFN2ADDR(2))); 65 zone_create(ADDR2PFN(start),66 SIZE2FRAMES(ALIGN_DOWN(size, FRAME_SIZE)),68 69 zone_create(ADDR2PFN(new_start), SIZE2FRAMES(new_size), 67 70 confdata, 0); 68 71 } 69 72 70 73 /* 71 74 * On sparc64, physical memory can start on a non-zero address. -
kernel/arch/sparc64/src/mm/sun4v/tlb.c
rfe7abd0 rcefb126 28 28 */ 29 29 30 /** @addtogroup sparc64mm 30 /** @addtogroup sparc64mm 31 31 * @{ 32 32 */ … … 62 62 static void itlb_pte_copy(pte_t *); 63 63 static void dtlb_pte_copy(pte_t *, bool); 64 static void do_fast_instruction_access_mmu_miss_fault(istate_t *, const char *); 64 static void do_fast_instruction_access_mmu_miss_fault(istate_t *, uintptr_t, 65 const char *); 65 66 static void do_fast_data_access_mmu_miss_fault(istate_t *, uint64_t, 66 67 const char *); … … 235 236 * Forward the page fault to the address space page fault 236 237 * handler. 237 */ 238 */ 238 239 page_table_unlock(AS, true); 239 240 if (as_page_fault(va, PF_ACCESS_EXEC, istate) == AS_PF_FAULT) { 240 241 do_fast_instruction_access_mmu_miss_fault(istate, 241 __func__);242 istate->tpc, __func__); 242 243 } 243 244 } … … 354 355 } 355 356 356 void do_fast_instruction_access_mmu_miss_fault(istate_t *istate, 357 void do_fast_instruction_access_mmu_miss_fault(istate_t *istate, uintptr_t va, 357 358 const char *str) 358 359 { 359 fault_if_from_uspace(istate, "%s.", str); 360 dump_istate(istate); 361 panic("%s.", str); 360 fault_if_from_uspace(istate, "%s, Address=%p.", str, va); 361 panic_memtrap(istate, PF_ACCESS_EXEC, va, "%s.", str); 362 362 } 363 363 … … 365 365 uint64_t page_and_ctx, const char *str) 366 366 { 367 if (DMISS_CONTEXT(page_and_ctx)) { 368 fault_if_from_uspace(istate, "%s, Page=%p (ASID=%d)\n", str, DMISS_ADDRESS(page_and_ctx), 369 DMISS_CONTEXT(page_and_ctx)); 370 } 371 dump_istate(istate); 372 printf("Faulting page: %p, ASID=%d\n", DMISS_ADDRESS(page_and_ctx), DMISS_CONTEXT(page_and_ctx)); 373 panic("%s\n", str); 367 fault_if_from_uspace(istate, "%s, Page=%p (ASID=%d).", str, 368 DMISS_ADDRESS(page_and_ctx), DMISS_CONTEXT(page_and_ctx)); 369 panic_memtrap(istate, PF_ACCESS_READ, DMISS_ADDRESS(page_and_ctx), 370 "%s."); 374 371 } 375 372 … … 377 374 uint64_t page_and_ctx, const char *str) 378 375 { 379 if (DMISS_CONTEXT(page_and_ctx)) { 380 fault_if_from_uspace(istate, "%s, Page=%p (ASID=%d)\n", str, DMISS_ADDRESS(page_and_ctx), 381 DMISS_CONTEXT(page_and_ctx)); 382 } 383 printf("Faulting page: %p, ASID=%d\n", DMISS_ADDRESS(page_and_ctx), DMISS_CONTEXT(page_and_ctx)); 384 dump_istate(istate); 385 panic("%s\n", str); 376 fault_if_from_uspace(istate, "%s, Page=%p (ASID=%d).", str, 377 DMISS_ADDRESS(page_and_ctx), DMISS_CONTEXT(page_and_ctx)); 378 panic_memtrap(istate, PF_ACCESS_WRITE, DMISS_ADDRESS(page_and_ctx), 379 "%s."); 386 380 } 387 381 -
kernel/arch/sparc64/src/trap/exception.c
rfe7abd0 rcefb126 44 44 #include <symtab.h> 45 45 46 void dump_istate(istate_t *istate)46 void istate_decode(istate_t *istate) 47 47 { 48 48 const char *tpcs = symtab_fmt_name_lookup(istate->tpc); … … 58 58 { 59 59 fault_if_from_uspace(istate, "%s.", __func__); 60 dump_istate(istate); 61 panic("%s.", __func__); 60 panic_badtrap(istate, n, "%s.", __func__); 62 61 } 63 62 … … 66 65 { 67 66 fault_if_from_uspace(istate, "%s.", __func__); 68 dump_istate(istate); 69 panic("%s.", __func__); 67 panic_badtrap(istate, n, "%s.", __func__); 70 68 } 71 69 … … 74 72 { 75 73 fault_if_from_uspace(istate, "%s.", __func__); 76 dump_istate(istate); 77 panic("%s.", __func__); 74 panic_badtrap(istate, n, "%s.", __func__); 78 75 } 79 76 … … 82 79 { 83 80 fault_if_from_uspace(istate, "%s.", __func__); 84 dump_istate(istate); 85 panic("%s.", __func__); 81 panic_badtrap(istate, n, "%s.", __func__); 86 82 } 87 83 … … 90 86 { 91 87 fault_if_from_uspace(istate, "%s.", __func__); 92 dump_istate(istate); 93 panic("%s.", __func__); 88 panic_badtrap(istate, n, "%s.", __func__); 94 89 } 95 90 … … 98 93 { 99 94 fault_if_from_uspace(istate, "%s.", __func__); 100 dump_istate(istate); 101 panic("%s.", __func__); 95 panic_badtrap(istate, n, "%s.", __func__); 102 96 } 103 97 … … 118 112 #else 119 113 fault_if_from_uspace(istate, "%s.", __func__); 120 dump_istate(istate); 121 panic("%s.", __func__); 114 panic_badtrap(istate, n, "%s.", __func__); 122 115 #endif 123 116 } … … 127 120 { 128 121 fault_if_from_uspace(istate, "%s.", __func__); 129 dump_istate(istate); 130 panic("%s.", __func__); 122 panic_badtrap(istate, n, "%s.", __func__); 131 123 } 132 124 … … 135 127 { 136 128 fault_if_from_uspace(istate, "%s.", __func__); 137 dump_istate(istate); 138 panic("%s.", __func__); 129 panic_badtrap(istate, n, "%s.", __func__); 139 130 } 140 131 … … 143 134 { 144 135 fault_if_from_uspace(istate, "%s.", __func__); 145 dump_istate(istate); 146 panic("%s.", __func__); 136 panic_badtrap(istate, n, "%s.", __func__); 147 137 } 148 138 … … 151 141 { 152 142 fault_if_from_uspace(istate, "%s.", __func__); 153 dump_istate(istate); 154 panic("%s.", __func__); 143 panic_badtrap(istate, n, "%s.", __func__); 155 144 } 156 145 … … 159 148 { 160 149 fault_if_from_uspace(istate, "%s.", __func__); 161 dump_istate(istate); 162 describe_dmmu_fault(); 163 panic("%s.", __func__); 150 panic_badtrap(istate, n, "%s.", __func__); 164 151 } 165 152 … … 168 155 { 169 156 fault_if_from_uspace(istate, "%s.", __func__); 170 dump_istate(istate); 171 panic("%s.", __func__); 157 panic_badtrap(istate, n, "%s.", __func__); 172 158 } 173 159 … … 176 162 { 177 163 fault_if_from_uspace(istate, "%s.", __func__); 178 dump_istate(istate); 179 panic("%s.", __func__); 164 panic_badtrap(istate, n, "%s.", __func__); 180 165 } 181 166 … … 184 169 { 185 170 fault_if_from_uspace(istate, "%s.", __func__); 186 dump_istate(istate); 187 panic("%s.", __func__); 171 panic_badtrap(istate, n, "%s.", __func__); 188 172 } 189 173 … … 192 176 { 193 177 fault_if_from_uspace(istate, "%s.", __func__); 194 dump_istate(istate); 195 panic("%s.", __func__); 178 panic_badtrap(istate, n, "%s.", __func__); 196 179 } 197 180 … … 200 183 { 201 184 fault_if_from_uspace(istate, "%s.", __func__); 202 dump_istate(istate); 203 panic("%s.", __func__); 185 panic_badtrap(istate, n, "%s.", __func__); 204 186 } 205 187 … … 208 190 { 209 191 fault_if_from_uspace(istate, "%s.", __func__); 210 dump_istate(istate); 211 panic("%s.", __func__); 192 panic_badtrap(istate, n, "%s.", __func__); 212 193 } 213 194 … … 216 197 { 217 198 fault_if_from_uspace(istate, "%s.", __func__); 218 dump_istate(istate); 219 panic("%s.", __func__); 199 panic_badtrap(istate, n, "%s.", __func__); 220 200 } 221 201 -
kernel/arch/sparc64/src/trap/sun4v/interrupt.c
rfe7abd0 rcefb126 111 111 ((void (*)(void)) data1)(); 112 112 } else { 113 printf("Spurious interrupt on %d, data = % lx.\n",113 printf("Spurious interrupt on %d, data = %" PRIx64 ".\n", 114 114 CPU->arch.id, data1); 115 115 }
Note:
See TracChangeset
for help on using the changeset viewer.
