- Timestamp:
- Jun 21, 2017, 8:35:30 AM (8 years ago)
- Location:
- trunk/hal/x86_64
- Files:
-
- 4 added
- 1 deleted
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/hal/x86_64/hal_boot.S
r25 r29 2 2 * hal_boot.S - Kernel boot entry point 3 3 * 4 * Author Maxime Villard (2017) 5 * This code is inspired a lot from the NetBSD boot procedure, 6 * written by Maxime Villard too. 7 * 8 * Copyright (c) UPMC Sorbonne Universites 9 * 10 * This file is part of ALMOS-kernel. 11 * 12 * ALMOS-kernel is free software; you can redistribute it and/or modify it 4 * Copyright (c) 2017 Maxime Villard 5 * This code is inspired a lot from the NetBSD boot procedure, written by 6 * Maxime Villard too. XXX copyright 7 * 8 * This file is part of ALMOS-MKH. 9 * 10 * ALMOS-MKH is free software; you can redistribute it and/or modify it 13 11 * under the terms of the GNU General Public License as published by 14 12 * the Free Software Foundation; version 2.0 of the License. 15 13 * 16 * ALMOS- kernelis distributed in the hope that it will be useful, but14 * ALMOS-MKH is distributed in the hope that it will be useful, but 17 15 * WITHOUT ANY WARRANTY; without even the implied warranty of 18 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU … … 20 18 * 21 19 * You should have received a copy of the GNU General Public License 22 * along with ALMOS- kernel; if not, write to the Free Software Foundation,20 * along with ALMOS-MKH.; if not, write to the Free Software Foundation, 23 21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 24 22 */ 25 23 24 #define x86_ASM 26 25 #include <hal_boot.h> 27 26 #include <hal_register.h> … … 99 98 2: ; 100 99 100 /* 101 * killkpt - Destroy a kernel page table (long mode) 102 * rbx = page table address 103 * rcx = number of pages to destroy 104 */ 105 #define killkpt \ 106 1: movq $0,(%rbx) ; \ 107 addq $PDE_SIZE,%rbx ; \ 108 loop 1b ; 109 101 110 /* 32bit version of PG_NX */ 102 111 #define PG_NX32 0x80000000 … … 106 115 .globl start_x86_64 107 116 .globl L4paddr 117 .globl iom_base 108 118 109 119 /* … … 125 135 .type L4paddr, @object 126 136 L4paddr: .quad 0 /* paddr of L4 */ 137 138 .type iom_base, @object 139 iom_base: .quad 0 /* virt. addr. of ISA I/O MEM */ 140 127 141 128 142 #define GDT64_LIMIT gdt64_end-gdt64_start-1 … … 152 166 farjmp64: 153 167 .long RELOC(longmode) 154 .word G SEL(GCODE_SEL, SEL_KPL)168 .word GDT_FIXED_SEL(GDT_KCODE_SEL, SEL_KPL) 155 169 .align 64 156 170 … … 169 183 170 184 /* Make sure it is a multiboot-compliant bootloader. */ 171 cmpl $MULTIBOOT_INFO_MAGIC,%eax172 jne boot_panic185 // cmpl $MULTIBOOT_INFO_MAGIC,%eax 186 // jne boot_panic 173 187 174 188 movl $RELOC(tmpstk),%esp … … 246 260 subl %eax,%ecx 247 261 shrl $PGSHIFT,%ecx 248 orl $(PG_V|PG_KR ),%eax262 orl $(PG_V|PG_KR|PG_G),%eax 249 263 fillkpt 250 264 … … 254 268 subl %eax,%ecx 255 269 shrl $PGSHIFT,%ecx 256 orl $(PG_V|PG_KW ),%eax270 orl $(PG_V|PG_KW|PG_G),%eax 257 271 fillkpt_nox 258 272 … … 261 275 movl $TABLESIZE,%ecx /* length of BOOTSTRAP TABLES */ 262 276 shrl $PGSHIFT,%ecx 263 orl $(PG_V|PG_KW ),%eax277 orl $(PG_V|PG_KW|PG_G),%eax 264 278 fillkpt_nox 265 279 … … 268 282 movl $IOM_SIZE,%ecx /* size of ISA I/O MEM */ 269 283 shrl $PGSHIFT,%ecx 270 orl $(PG_V|PG_KW /*|PG_N*/),%eax284 orl $(PG_V|PG_KW|PG_G),%eax 271 285 fillkpt_nox 272 286 … … 335 349 */ 336 350 movl %cr4,%eax 337 orl $(CR4_PAE|CR4_OSFXSR|CR4_OSXMMEXCPT ),%eax351 orl $(CR4_PAE|CR4_OSFXSR|CR4_OSXMMEXCPT|CR4_PGE),%eax 338 352 movl %eax,%cr4 339 353 … … 381 395 */ 382 396 movabsq $longmode_hi,%rax 383 jmp *%rax /* XXX XXX: <------ this instruction faults */397 jmp *%rax 384 398 385 399 longmode_hi: … … 397 411 movq $KERNBASE,%r8 398 412 399 400 /* 401 * STOP HERE FOR NOW 402 */ 403 1: nop 404 jmp 1b 405 406 407 boot_panic: 408 jmp boot_panic 409 413 #if L2_SLOT_KERNBASE > 0 414 movq $(NKL2_KIMG_ENTRIES+1),%rcx 415 leaq (PROC0_PTP2_OFF)(%rsi),%rbx /* old, phys address */ 416 addq %r8,%rbx /* new, virt address */ 417 killkpt 418 #endif 419 420 #if L3_SLOT_KERNBASE > 0 421 movq $NKL3_KIMG_ENTRIES,%rcx 422 leaq (PROC0_PTP3_OFF)(%rsi),%rbx /* old, phys address */ 423 addq %r8,%rbx /* new, virt address */ 424 killkpt 425 #endif 426 427 movq $NKL4_KIMG_ENTRIES,%rcx 428 leaq (PROC0_PML4_OFF)(%rsi),%rbx /* old, phys address of PML4 */ 429 addq %r8,%rbx /* new, virt address of PML4 */ 430 killkpt 431 432 /* Relocate atdevbase. */ 433 movq $(TABLESIZE+KERNBASE),%rdx 434 addq %rsi,%rdx 435 movq %rdx,iom_base(%rip) 436 437 /* Set up bootstrap stack. */ 438 leaq (PROC0_STK_OFF)(%rsi),%rax 439 addq %r8,%rax 440 leaq (STKSIZE)(%rax),%rsp 441 xorq %rbp,%rbp /* mark end of frames */ 442 443 xorw %ax,%ax 444 movw %ax,%gs 445 movw %ax,%fs 446 447 /* The first physical page available. */ 448 leaq (TABLESIZE)(%rsi),%rdi 449 450 call init_x86_64 451 -
trunk/hal/x86_64/hal_boot.h
r25 r29 2 2 * hal_boot.h - General values used by the boot procedure 3 3 * 4 * Author Maxime Villard (2017) 4 * Copyright (c) 2017 Maxime Villard 5 * 6 * This file is part of ALMOS-MKH. 5 7 * 6 * Copyright (c) UPMC Sorbonne Universites 7 * 8 * This file is part of ALMOS-kernel. 9 * 10 * ALMOS-kernel is free software; you can redistribute it and/or modify it 8 * ALMOS-MKH is free software; you can redistribute it and/or modify it 11 9 * under the terms of the GNU General Public License as published by 12 10 * the Free Software Foundation; version 2.0 of the License. 13 11 * 14 * ALMOS- kernelis distributed in the hope that it will be useful, but12 * ALMOS-MKH is distributed in the hope that it will be useful, but 15 13 * WITHOUT ANY WARRANTY; without even the implied warranty of 16 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU … … 18 16 * 19 17 * You should have received a copy of the GNU General Public License 20 * along with ALMOS- kernel; if not, write to the Free Software Foundation,18 * along with ALMOS-MKH.; if not, write to the Free Software Foundation, 21 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 20 */ … … 36 34 /* -------------------------------------------------------------------------- */ 37 35 36 #define ASM_ALIGN_TEXT .align 16 37 #define ASM_ENTRY(x) \ 38 .text; ASM_ALIGN_TEXT; .globl x; .type x,@function; x: 39 40 /* -------------------------------------------------------------------------- */ 41 38 42 #define PSL_MBO 0x00000002 39 43 40 44 #define STKPAGES 4 45 #define STKSIZE (PAGE_SIZE * STKPAGES) 41 46 42 47 #define NKL4_KIMG_ENTRIES 1 … … 107 112 #define L4_SLOT_KERNBASE 511 108 113 114 /* 115 * L3 = (KERNBASE % NBPD_L4) / NBPD_L3 116 * L2 = (KERNBASE % NBPD_L3) / NBPD_L2 117 */ 118 #define L3_SLOT_KERNBASE 510 119 #define L2_SLOT_KERNBASE 0 120 109 121 #define PDIR_SLOT_KERN L4_SLOT_KERN 110 122 #define PDIR_SLOT_PTE L4_SLOT_PTE -
trunk/hal/x86_64/hal_kentry.S
r25 r29 1 1 /* 2 * hal_kentry.S - exception/interrupt/syscall kernel entry point for MIPS322 * hal_kentry.S - Entry points into the kernel (traps, interrupts, syscalls) 3 3 * 4 * AUthors Ghassan Almaless (2007,2008,2009,2010,2011,2012) 5 * Mohamed Lamine Karaoui (2015) 6 * Alain Greiner (2017) 7 * 8 * Copyright (c) UPMC Sorbonne Universites 4 * Copyright (c) 2017 Maxime Villard 9 5 * 10 6 * This file is part of ALMOS-MKH. … … 20 16 * 21 17 * You should have received a copy of the GNU General Public License 22 * along with ALMOS-MKH ; if not, write to the Free Software Foundation,18 * along with ALMOS-MKH.; if not, write to the Free Software Foundation, 23 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 24 20 */ 25 21 22 #define x86_ASM 23 #include <hal_boot.h> 24 #include <hal_kentry.h> 26 25 27 #--------------------------------------------------------------------------------- 28 # This code is the unique kernel entry point in case of exception, interrupt, 29 # or syscall for the TSAR_MIPS32 architecture. 30 # 31 # - If the core is in user mode: 32 # . we desactivate the MMU. 33 # . we save the context in the uzone of the calling thread descriptor. 34 # . we increment the cores_in_kernel variable. 35 # . we call the relevant exception/interrupt/syscall handler 36 # 37 # - If the core is already in kernel mode: 38 # . we save the context in the kernel stack 39 # . we call the relevant exception/interrupt/syscall handler 40 # 41 # - In both cases, when the handler returns: 42 # . we restore the context 43 # . we reactivate the MMU ??? 44 #--------------------------------------------------------------------------------- 26 #define TRAPENTRY(a) \ 27 pushq $(a); \ 28 jmp alltraps; 45 29 46 .section .kentry,"ax",@progbits 47 .extern cpu_do_interrupt 48 .extern cpu_do_exception 49 .extern cpu_do_syscall 50 .extern cpu_kentry 51 .extern cpu_kexit 30 #define ZTRAPENTRY(a) \ 31 pushq $0; \ 32 TRAPENTRY(a) 52 33 53 .global kentry 54 .global kentry_load 34 .text 35 .globl hal_trap_entry 36 .type hal_trap_entry, @function 55 37 56 #define SAVE_SIZE CPU_REGS_NR*4 57 #define LID_WIDTH 2 58 #define CXY_WIDTH 8 59 #define CXY_MASK 0xFF 60 #define MMU_MODE_MASK 0xF 61 #define GID_MASK 0x3FF 62 #define LID_MASK 0x3 38 ASM_ENTRY(x86_trap00) 39 ZTRAPENTRY(T_DIVIDE) 63 40 64 #--------------------------------------------------------------------------------- 65 # Kernel Entry point 66 #--------------------------------------------------------------------------------- 41 ASM_ENTRY(x86_trap01) 42 ZTRAPENTRY(T_TRCTRAP) 67 43 68 kentry: 69 70 #--------------------------------------------------------------------------------------- 71 # this code is executed when the core is in user mode: 72 # - we use the uzone defined in user thread descriptor. 73 # - we set the MMU off, and save the CP2_MODE register to uzone. 74 # - we save the user thread stack pointer to uzone and load the kernel stack pointer 75 # - we store the uzone pointer in $27 44 ASM_ENTRY(x86_trap02) 45 ZTRAPENTRY(T_NMI) 76 46 77 user_mode: 47 ASM_ENTRY(x86_trap03) 48 ZTRAPENTRY(T_BPTFLT) 78 49 79 #--------------------------------------------------------------------------------------- 80 # this code is executed when the core is in kernel mode: 81 # - we use an uzone allocated in kernel stack. 82 # - we set the MMU off, set the MMU data_paddr extension to local_cxy, 83 # and save the CP2_MODE and CP2_DEXT to uzone. 84 # - we save the kernel stack pointer to uzone and load the new kernel stack pointer 85 # - we store the uzone pointer in $27 50 ASM_ENTRY(x86_trap04) 51 ZTRAPENTRY(T_OFLOW) 86 52 87 kernel_mode: 53 ASM_ENTRY(x86_trap05) 54 ZTRAPENTRY(T_BOUND) 88 55 89 #-------------------------------------------------------------------------------------- 90 # this code is executed in both modes, with the two following assumptions: 91 # - $27 contains the pointer on uzone to save the cpu registers 92 # - $29 contains the kernel stack pointer 56 ASM_ENTRY(x86_trap06) 57 ZTRAPENTRY(T_PRIVINFLT) 93 58 94 unified_mode: 59 ASM_ENTRY(x86_trap07) 60 ZTRAPENTRY(T_DNA) 95 61 96 #--------------------------------------------------------------------------------------- 97 # Depending on XCODE (in $1) , call the apropriate handler. The three called 98 # functions take the same two arguments: thread pointer and uzone pointer. 62 ASM_ENTRY(x86_trap08) 63 TRAPENTRY(T_DOUBLEFLT) 99 64 65 ASM_ENTRY(x86_trap09) 66 ZTRAPENTRY(T_FPOPFLT) 100 67 101 cause_excp: 68 ASM_ENTRY(x86_trap0a) 69 TRAPENTRY(T_TSSFLT) 102 70 103 cause_sys: 71 ASM_ENTRY(x86_trap0b) 72 ZTRAPENTRY(T_SEGNPFLT) 104 73 105 cause_int: 74 ASM_ENTRY(x86_trap0c) 75 ZTRAPENTRY(T_STKFLT) 106 76 107 # ----------------------------------------------------------------------------------- 108 # Kentry exit 109 # ----------------------------------------------------------------------------------- 110 kentry_exit: 77 ASM_ENTRY(x86_trap0d) 78 ZTRAPENTRY(T_PROTFLT) 111 79 112 # Possible value for MMU_MODE 113 # In kernel mode : 0x7/0x3 114 # In user mode : 0xF 80 ASM_ENTRY(x86_trap0e) 81 TRAPENTRY(T_PAGEFLT) 115 82 116 # DP_EXT can either be local or remote 117 # Once these register set we can no longuer 118 # access global data 83 ASM_ENTRY(x86_trap0f) 84 ZTRAPENTRY(T_ASTFLT) 119 85 120 out_mmu_F: 86 ASM_ENTRY(x86_trap10) 87 ZTRAPENTRY(T_ARITHTRAP) 121 88 122 out_mmu_7: 89 ASM_ENTRY(x86_trap11) 90 TRAPENTRY(T_ALIGNFLT) 123 91 124 out_mmu_3: 92 ASM_ENTRY(x86_trap12) 93 ZTRAPENTRY(T_MCA) 125 94 126 out_kentry: 95 ASM_ENTRY(x86_trap13) 96 ZTRAPENTRY(T_XMM) 127 97 128 kentry_load: 129 # theses nops are required to load the eret instruction 130 # while we are in virtual mode (processor pipeline) ? 98 ASM_ENTRY(x86_trap14) 99 ASM_ENTRY(x86_trap15) 100 ASM_ENTRY(x86_trap16) 101 ASM_ENTRY(x86_trap17) 102 ASM_ENTRY(x86_trap18) 103 ASM_ENTRY(x86_trap19) 104 ASM_ENTRY(x86_trap1a) 105 ASM_ENTRY(x86_trap1b) 106 ASM_ENTRY(x86_trap1c) 107 ASM_ENTRY(x86_trap1d) 108 ASM_ENTRY(x86_trap1e) 109 ASM_ENTRY(x86_trap1f) 110 /* 20 - 31 reserved for future exp */ 111 ZTRAPENTRY(T_RESERVED) 131 112 113 /* 114 * Arguments pushed on the stack: 115 * tf_trapno 116 * tf_err: Dummy inserted if not defined 117 * tf_rip 118 * tf_cs 119 * tf_rflags 120 * tf_rsp 121 * tf_ss 122 */ 123 alltraps: 124 movq %rsp,%rdi 125 call hal_trap_entry 126 /* NOTREACHED */ 132 127 133 #------------------------------------------------------------------------------- 128 .data 129 .globl x86_traps 130 .type x86_traps, @object 134 131 132 .align 64 133 x86_traps: 134 .quad x86_trap00, x86_trap01 135 .quad x86_trap02, x86_trap03 136 .quad x86_trap04, x86_trap05 137 .quad x86_trap06, x86_trap07 138 .quad x86_trap08, x86_trap09 139 .quad x86_trap0a, x86_trap0b 140 .quad x86_trap0c, x86_trap0d 141 .quad x86_trap0e, x86_trap0f 142 .quad x86_trap10, x86_trap11 143 .quad x86_trap12, x86_trap13 144 .quad x86_trap14, x86_trap15 145 .quad x86_trap16, x86_trap17 146 .quad x86_trap18, x86_trap19 147 .quad x86_trap1a, x86_trap1b 148 .quad x86_trap1c, x86_trap1d 149 .quad x86_trap1e, x86_trap1f 150 -
trunk/hal/x86_64/hal_kentry.h
r25 r29 1 1 /* 2 * cpu-regs.h - mips register map2 * hal_kentry.h - General values used in the different kernel entries 3 3 * 4 * Copyright (c) 2008,2009,2010,2011,2012 Ghassan Almaless 5 * Copyright (c) 2011,2012 UPMC Sorbonne Universites 4 * Copyright (c) 2017 Maxime Villard 6 5 * 7 * This file is part of ALMOS- kernel.6 * This file is part of ALMOS-MKH. 8 7 * 9 * ALMOS- kernelis free software; you can redistribute it and/or modify it8 * ALMOS-MKH is free software; you can redistribute it and/or modify it 10 9 * under the terms of the GNU General Public License as published by 11 10 * the Free Software Foundation; version 2.0 of the License. 12 11 * 13 * ALMOS- kernelis distributed in the hope that it will be useful, but12 * ALMOS-MKH is distributed in the hope that it will be useful, but 14 13 * WITHOUT ANY WARRANTY; without even the implied warranty of 15 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU … … 17 16 * 18 17 * You should have received a copy of the GNU General Public License 19 * along with ALMOS- kernel; if not, write to the Free Software Foundation,18 * along with ALMOS-MKH.; if not, write to the Free Software Foundation, 20 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 20 */ 22 21 23 #ifndef _HAL_KENTRY_H_ 24 #define _HAL_KENTRY_H_ 22 #define T_PRIVINFLT 0 /* privileged instruction */ 23 #define T_BPTFLT 1 /* breakpoint trap */ 24 #define T_ARITHTRAP 2 /* arithmetic trap */ 25 #define T_ASTFLT 3 /* asynchronous system trap */ 26 #define T_PROTFLT 4 /* protection fault */ 27 #define T_TRCTRAP 5 /* trace trap */ 28 #define T_PAGEFLT 6 /* page fault */ 29 #define T_ALIGNFLT 7 /* alignment fault */ 30 #define T_DIVIDE 8 /* integer divide fault */ 31 #define T_NMI 9 /* non-maskable interrupt */ 32 #define T_OFLOW 10 /* overflow trap */ 33 #define T_BOUND 11 /* bounds check fault */ 34 #define T_DNA 12 /* device not available fault */ 35 #define T_DOUBLEFLT 13 /* double fault */ 36 #define T_FPOPFLT 14 /* fp coprocessor operand fetch fault */ 37 #define T_TSSFLT 15 /* invalid tss fault */ 38 #define T_SEGNPFLT 16 /* segment not present fault */ 39 #define T_STKFLT 17 /* stack fault */ 40 #define T_MCA 18 /* machine check */ 41 #define T_XMM 19 /* SSE FP exception */ 42 #define T_RESERVED 20 /* reserved fault base */ 25 43 26 #define KSP 0 27 #define AT 1 28 #define V0 2 29 #define V1 3 30 #define A0 4 31 #define A1 5 32 #define A2 6 33 #define A3 7 34 #define T0 8 35 #define T1 9 36 #define T2 10 37 #define T3 11 38 #define T4 12 39 #define T5 13 40 #define T6 14 41 #define T7 15 42 #define T8 16 43 #define T9 17 44 #define S0 18 45 #define S1 19 46 #define S2 20 47 #define S3 21 48 #define S4 22 49 #define S5 23 50 #define S6 24 51 #define S7 25 52 #define S8 26 53 #define GP 27 54 #define RA 28 55 #define EPC 29 56 #define CR 30 57 #define SP 31 58 #define SR 32 59 #define LO 33 60 #define HI 34 61 #define TLS_K1 35 62 #define DP_EXT 36 // DATA PADDR EXTENSION 63 #define MMU_MD 37 // MMU MODE 64 #define REGS_NR 38 44 /* Trap's coming from user mode */ 45 #define T_USER 0x100 65 46 66 # define CPU_IN_KERNEL 147 #ifndef x86_ASM 67 48 68 #endif /* _HAL_ENTRY_H_ */ 49 /* 50 * The x86_64 trap frame. 51 */ 52 struct trapframe { 53 uint64_t tf_rdi; 54 uint64_t tf_rsi; 55 uint64_t tf_rdx; 56 uint64_t tf_r10; 57 uint64_t tf_r8; 58 uint64_t tf_r9; 59 60 uint64_t tf_arg6; 61 uint64_t tf_arg7; 62 uint64_t tf_arg8; 63 uint64_t tf_arg9; 64 65 uint64_t tf_rcx; 66 uint64_t tf_r11; 67 uint64_t tf_r12; 68 uint64_t tf_r13; 69 uint64_t tf_r14; 70 uint64_t tf_r15; 71 uint64_t tf_rbp; 72 uint64_t tf_rbx; 73 uint64_t tf_rax; 74 75 uint64_t tf_gs; 76 uint64_t tf_fs; 77 uint64_t tf_es; 78 uint64_t tf_ds; 79 80 uint64_t tf_trapno; 81 82 /* These are pushed for a trap */ 83 uint64_t tf_err; 84 uint64_t tf_rip; 85 uint64_t tf_cs; 86 uint64_t tf_rflags; 87 88 /* These are always pushed */ 89 uint64_t tf_rsp; 90 uint64_t tf_ss; 91 }; 92 93 /* 94 * Our small trap frame. 95 */ 96 struct small_trapframe { 97 uint64_t tf_trapno; 98 99 /* These are pushed for a trap */ 100 uint64_t tf_err; 101 uint64_t tf_rip; 102 uint64_t tf_cs; 103 uint64_t tf_rflags; 104 105 /* These are always pushed */ 106 uint64_t tf_rsp; 107 uint64_t tf_ss; 108 }; 109 110 #endif 111 -
trunk/hal/x86_64/hal_register.h
r25 r29 2 2 * hal_register.h - Values available in some x86 registers 3 3 * 4 * Author Maxime Villard (2017) 4 * Copyright (c) 2017 Maxime Villard 5 * 6 * This file is part of ALMOS-MKH. 5 7 * 6 * Copyright (c) UPMC Sorbonne Universites 7 * 8 * This file is part of ALMOS-kernel. 9 * 10 * ALMOS-kernel is free software; you can redistribute it and/or modify it 8 * ALMOS-MKH is free software; you can redistribute it and/or modify it 11 9 * under the terms of the GNU General Public License as published by 12 10 * the Free Software Foundation; version 2.0 of the License. 13 11 * 14 * ALMOS- kernelis distributed in the hope that it will be useful, but12 * ALMOS-MKH is distributed in the hope that it will be useful, but 15 13 * WITHOUT ANY WARRANTY; without even the implied warranty of 16 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU … … 18 16 * 19 17 * You should have received a copy of the GNU General Public License 20 * along with ALMOS- kernel; if not, write to the Free Software Foundation,18 * along with ALMOS-MKH.; if not, write to the Free Software Foundation, 21 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 20 */ -
trunk/hal/x86_64/hal_segmentation.h
r25 r29 1 1 /* 2 * hal_ boot.S - Kernel boot entry point2 * hal_segmentation.h - Segmentation-related values and structures 3 3 * 4 * Author Maxime Villard (2017) 4 * Copyright (c) 2017 Maxime Villard 5 * 6 * This file is part of ALMOS-MKH. 5 7 * 6 * Copyright (c) UPMC Sorbonne Universites 7 * 8 * This file is part of ALMOS-kernel. 9 * 10 * ALMOS-kernel is free software; you can redistribute it and/or modify it 8 * ALMOS-MKH is free software; you can redistribute it and/or modify it 11 9 * under the terms of the GNU General Public License as published by 12 10 * the Free Software Foundation; version 2.0 of the License. 13 11 * 14 * ALMOS- kernelis distributed in the hope that it will be useful, but12 * ALMOS-MKH is distributed in the hope that it will be useful, but 15 13 * WITHOUT ANY WARRANTY; without even the implied warranty of 16 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU … … 18 16 * 19 17 * You should have received a copy of the GNU General Public License 20 * along with ALMOS- kernel; if not, write to the Free Software Foundation,18 * along with ALMOS-MKH.; if not, write to the Free Software Foundation, 21 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 20 */ 23 21 24 22 /* 25 * Selectors 23 * The GDT has NGDT_MEM entries of 8-byte-sized, static memory entries. Then 24 * there is a certain number of 16-byte-sized TSS entries, one for each CPU. 26 25 */ 26 #define GDT_NULL_SEL 0 /* Null descriptor */ 27 #define GDT_KCODE_SEL 1 /* Kernel code descriptor */ 28 #define GDT_KDATA_SEL 2 /* Kernel data descriptor */ 29 #define GDT_UCODE_SEL 3 /* User code descriptor */ 30 #define GDT_UDATA_SEL 4 /* User data descriptor */ 31 #define NGDT_MEM 6 /* aligned */ 27 32 28 #define ISPL(s) ((s) & SEL_RPL) /* what is the priority level of a selector */ 33 #define GDT_CPU0TSS_SEL 0 /* cpu0's tss */ 34 #define NGDT_DYN (256 - (NGDT_MEM / 2) * 16) 35 36 /* 37 * GDT Selectors Privileges 38 */ 39 #define ISPL(s) ((s) & SEL_RPL) 40 #define USERMODE(c, f) (ISPL(c) == SEL_UPL) 41 #define KERNELMODE(c, f) (ISPL(c) == SEL_KPL) 29 42 #define SEL_KPL 0 /* kernel privilege level */ 30 43 #define SEL_UPL 3 /* user privilege level */ 31 44 #define SEL_RPL 3 /* requester's privilege level mask */ 32 #define ISLDT(s) ((s) & SEL_LDT) /* is it local or global */33 45 #define SEL_LDT 4 /* local descriptor table */ 34 46 35 #define GSEL(s,r) (((s) << 3) | r)47 #define SYSSEL_START (NGDT_MEM * 8) 36 48 49 /* Create a selector, with an index and a privilege */ 50 #define GDT_FIXED_SEL(s,r) (((s) << 3) | r) 51 #define GDT_DYNAM_SEL(s,r) ((SYSSEL_START + ((s) << 4)) | r) 37 52 53 #ifndef x86_ASM 38 54 39 55 /* 40 * Entries in the Global Descriptor Table (GDT). They remain static.56 * Offsets. 41 57 */ 42 #define GNULL_SEL 0 /* Null descriptor */ 43 #define GCODE_SEL 1 /* Kernel code descriptor */ 44 #define GDATA_SEL 2 /* Kernel data descriptor */ 45 #define GUCODE_SEL 3 /* User code descriptor */ 46 #define GUDATA_SEL 4 /* User data descriptor */ 58 #define GDT_ADDR_MEM(s,i) \ 59 ((struct gdt_memseg *)((s) + ((i) << 3))) 60 #define GDT_ADDR_SYS(s,i) \ 61 ((struct gdt_sysseg *)((s) + (SYSSEL_START + ((i) << 4)))) 47 62 63 /* 64 * System segment descriptor (16 bytes): used for TSS and LDT. 65 */ 66 struct gdt_sysseg { 67 uint64_t sd_lolimit:16; /* segment extent (lsb) */ 68 uint64_t sd_lobase:24; /* segment base address (lsb) */ 69 uint64_t sd_type:5; /* segment type */ 70 uint64_t sd_dpl:2; /* segment descriptor priority level */ 71 uint64_t sd_p:1; /* segment descriptor present */ 72 uint64_t sd_hilimit:4; /* segment extent (msb) */ 73 uint64_t sd_xx1:3; /* avl, long and def32 (not used) */ 74 uint64_t sd_gran:1; /* limit granularity (byte/page) */ 75 uint64_t sd_hibase:40; /* segment base address (msb) */ 76 uint64_t sd_xx2:8; /* reserved */ 77 uint64_t sd_zero:5; /* must be zero */ 78 uint64_t sd_xx3:19; /* reserved */ 79 } __packed; 80 81 /* 82 * Memory segment descriptor (8 bytes): used for cs, ds, etc. 83 */ 84 struct gdt_memseg { 85 unsigned sd_lolimit:16; /* segment extent (lsb) */ 86 unsigned sd_lobase:24; /* segment base address (lsb) */ 87 unsigned sd_type:5; /* segment type */ 88 unsigned sd_dpl:2; /* segment descriptor priority level */ 89 unsigned sd_p:1; /* segment descriptor present */ 90 unsigned sd_hilimit:4; /* segment extent (msb) */ 91 unsigned sd_avl:1; /* available */ 92 unsigned sd_long:1; /* long mode */ 93 unsigned sd_def32:1; /* default 32 vs 16 bit size */ 94 unsigned sd_gran:1; /* limit granularity (byte/page) */ 95 unsigned sd_hibase:8; /* segment base address (msb) */ 96 } __packed; 97 98 /* 99 * Common part of the above structures. Used to walk descriptor tables. 100 */ 101 struct common_segment_descriptor { 102 unsigned sdc_lolimit:16; 103 unsigned sdc_lobase:24; 104 unsigned sdc_type:5; 105 unsigned sdc_other:19; 106 } __packed; 107 108 /* 109 * IDT descriptors (16 bytes). 110 */ 111 struct idt_seg { 112 uint64_t gd_looffset:16;/* gate offset (lsb) */ 113 uint64_t gd_selector:16;/* gate segment selector */ 114 uint64_t gd_ist:3; /* IST select */ 115 uint64_t gd_xx1:5; /* reserved */ 116 uint64_t gd_type:5; /* segment type */ 117 uint64_t gd_dpl:2; /* segment descriptor priority level */ 118 uint64_t gd_p:1; /* segment descriptor present */ 119 uint64_t gd_hioffset:48;/* gate offset (msb) */ 120 uint64_t gd_xx2:8; /* reserved */ 121 uint64_t gd_zero:5; /* must be zero */ 122 uint64_t gd_xx3:19; /* reserved */ 123 } __packed; 124 125 /* 126 * Region descriptors, used to load gdt/idt tables before segments yet exist. 127 */ 128 struct region_descriptor { 129 uint16_t rd_limit; /* segment extent */ 130 uint64_t rd_base; /* base address */ 131 } __packed; 132 133 struct tss { 134 uint32_t tss_reserved1; 135 uint64_t tss_rsp0; 136 uint64_t tss_rsp1; 137 uint64_t tss_rsp3; 138 uint32_t tss_reserved2; 139 uint32_t tss_reserved3; 140 uint64_t tss_ist[7]; 141 uint32_t tss_reserved4; 142 uint32_t tss_reserved5; 143 uint32_t tss_iobase; 144 } __packed; 145 146 #define IOMAP_INVALOFF 0xffff 147 148 void lgdt(struct region_descriptor *); 149 void lidt(struct region_descriptor *); 150 void ltr(u_short); 151 152 #endif /* !x86_ASM */ 153 154 /* system segments and gate types */ 155 #define SDT_SYSNULL 0 /* system null */ 156 #define SDT_SYS286TSS 1 /* system 286 TSS available */ 157 #define SDT_SYSLDT 2 /* system local descriptor table */ 158 #define SDT_SYS286BSY 3 /* system 286 TSS busy */ 159 #define SDT_SYS286CGT 4 /* system 286 call gate */ 160 #define SDT_SYSTASKGT 5 /* system task gate */ 161 #define SDT_SYS286IGT 6 /* system 286 interrupt gate */ 162 #define SDT_SYS286TGT 7 /* system 286 trap gate */ 163 #define SDT_SYSNULL2 8 /* system null again */ 164 #define SDT_SYS386TSS 9 /* system 386 TSS available */ 165 #define SDT_SYSNULL3 10 /* system null again */ 166 #define SDT_SYS386BSY 11 /* system 386 TSS busy */ 167 #define SDT_SYS386CGT 12 /* system 386 call gate */ 168 #define SDT_SYSNULL4 13 /* system null again */ 169 #define SDT_SYS386IGT 14 /* system 386 interrupt gate */ 170 #define SDT_SYS386TGT 15 /* system 386 trap gate */ 171 172 /* memory segment types */ 173 #define SDT_MEMRO 16 /* memory read only */ 174 #define SDT_MEMROA 17 /* memory read only accessed */ 175 #define SDT_MEMRW 18 /* memory read write */ 176 #define SDT_MEMRWA 19 /* memory read write accessed */ 177 #define SDT_MEMROD 20 /* memory read only expand dwn limit */ 178 #define SDT_MEMRODA 21 /* memory read only expand dwn limit accessed */ 179 #define SDT_MEMRWD 22 /* memory read write expand dwn limit */ 180 #define SDT_MEMRWDA 23 /* memory read write expand dwn limit accessed */ 181 #define SDT_MEME 24 /* memory execute only */ 182 #define SDT_MEMEA 25 /* memory execute only accessed */ 183 #define SDT_MEMER 26 /* memory execute read */ 184 #define SDT_MEMERA 27 /* memory execute read accessed */ 185 #define SDT_MEMEC 28 /* memory execute only conforming */ 186 #define SDT_MEMEAC 29 /* memory execute only accessed conforming */ 187 #define SDT_MEMERC 30 /* memory execute read conforming */ 188 #define SDT_MEMERAC 31 /* memory execute read accessed conforming */ 189 190 /* 191 * Entries in the Interrupt Descriptor Table (IDT) 192 */ 193 #define NCPUIDT 32 /* reserved entries for CPU exceptions */ 194 #define NIDT 256 /* total number of IDT entries */ 195 -
trunk/hal/x86_64/hal_types.h
r25 r29 31 31 #endif 32 32 33 #define __packed __attribute__((__packed__)) 34 #define __arraycount(a) (sizeof(a) / sizeof(*(a))) 35 #define __in_kdata __attribute__((section(".kdata"))) 36 37 33 38 /************************************************************************** 34 39 * Exact-width integer types. … … 46 51 typedef signed long long int int64_t; 47 52 typedef unsigned long long int uint64_t; 53 54 typedef uint64_t size_t; 48 55 49 56 /***************************************************************************
Note: See TracChangeset
for help on using the changeset viewer.