Changeset 46c20c8 in mainline for kernel/arch/amd64/include
- Timestamp:
- 2010-11-26T20:08:10Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 45df59a
- Parents:
- fb150d78 (diff), ffdd2b9 (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/amd64/include
- Files:
-
- 1 added
- 1 deleted
- 24 edited
-
arch.h (modified) (1 diff)
-
asm.h (modified) (28 diffs)
-
atomic.h (modified) (6 diffs)
-
boot/boot.h (modified) (2 diffs)
-
context.h (modified) (4 diffs)
-
context_offset.h (modified) (3 diffs)
-
cpu.h (modified) (1 diff)
-
cpuid.h (modified) (1 diff)
-
cycle.h (modified) (1 diff)
-
ddi/ddi.h (modified) (1 diff)
-
debug.h (deleted)
-
debugger.h (modified) (1 diff)
-
elf.h (modified) (2 diffs)
-
faddr.h (modified) (2 diffs)
-
interrupt.h (modified) (2 diffs)
-
istate.h (added)
-
memstr.h (modified) (2 diffs)
-
mm/as.h (modified) (2 diffs)
-
mm/frame.h (modified) (1 diff)
-
mm/page.h (modified) (6 diffs)
-
mm/ptl.h (modified) (2 diffs)
-
mm/tlb.h (modified) (1 diff)
-
pm.h (modified) (4 diffs)
-
proc/task.h (modified) (1 diff)
-
proc/thread.h (modified) (1 diff)
-
types.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
kernel/arch/amd64/include/arch.h
rfb150d78 r46c20c8 27 27 */ 28 28 29 /** @addtogroup amd64 29 /** @addtogroup amd64 30 30 * @{ 31 31 */ -
kernel/arch/amd64/include/asm.h
rfb150d78 r46c20c8 37 37 38 38 #include <config.h> 39 #include <arch/types.h>40 39 #include <typedefs.h> 41 42 extern void asm_delay_loop(uint32_t t); 43 extern void asm_fake_loop(uint32_t t); 40 #include <arch/cpu.h> 41 #include <trace.h> 44 42 45 43 /** Return base address of current stack. … … 50 48 * 51 49 */ 52 static inline uintptr_t get_stack_base(void)50 NO_TRACE static inline uintptr_t get_stack_base(void) 53 51 { 54 52 uintptr_t v; … … 57 55 "andq %%rsp, %[v]\n" 58 56 : [v] "=r" (v) 59 : "0" (~((uint64_t) STACK_SIZE -1))57 : "0" (~((uint64_t) STACK_SIZE - 1)) 60 58 ); 61 59 … … 63 61 } 64 62 65 static inline void cpu_sleep(void) 66 { 67 asm volatile ("hlt\n"); 68 } 69 70 static inline void __attribute__((noreturn)) cpu_halt(void) 63 NO_TRACE static inline void cpu_sleep(void) 64 { 65 asm volatile ( 66 "hlt\n" 67 ); 68 } 69 70 NO_TRACE static inline void __attribute__((noreturn)) cpu_halt(void) 71 71 { 72 72 while (true) { … … 77 77 } 78 78 79 80 79 /** Byte from port 81 80 * … … 86 85 * 87 86 */ 88 static inline uint8_t pio_read_8(ioport8_t *port)87 NO_TRACE static inline uint8_t pio_read_8(ioport8_t *port) 89 88 { 90 89 uint8_t val; … … 107 106 * 108 107 */ 109 static inline uint16_t pio_read_16(ioport16_t *port)108 NO_TRACE static inline uint16_t pio_read_16(ioport16_t *port) 110 109 { 111 110 uint16_t val; … … 128 127 * 129 128 */ 130 static inline uint32_t pio_read_32(ioport32_t *port)129 NO_TRACE static inline uint32_t pio_read_32(ioport32_t *port) 131 130 { 132 131 uint32_t val; … … 149 148 * 150 149 */ 151 static inline void pio_write_8(ioport8_t *port, uint8_t val)150 NO_TRACE static inline void pio_write_8(ioport8_t *port, uint8_t val) 152 151 { 153 152 asm volatile ( 154 153 "outb %b[val], %w[port]\n" 155 :: [val] "a" (val), [port] "d" (port) 154 :: [val] "a" (val), 155 [port] "d" (port) 156 156 ); 157 157 } … … 165 165 * 166 166 */ 167 static inline void pio_write_16(ioport16_t *port, uint16_t val)167 NO_TRACE static inline void pio_write_16(ioport16_t *port, uint16_t val) 168 168 { 169 169 asm volatile ( 170 170 "outw %w[val], %w[port]\n" 171 :: [val] "a" (val), [port] "d" (port) 171 :: [val] "a" (val), 172 [port] "d" (port) 172 173 ); 173 174 } … … 181 182 * 182 183 */ 183 static inline void pio_write_32(ioport32_t *port, uint32_t val)184 NO_TRACE static inline void pio_write_32(ioport32_t *port, uint32_t val) 184 185 { 185 186 asm volatile ( 186 187 "outl %[val], %w[port]\n" 187 :: [val] "a" (val), [port] "d" (port) 188 :: [val] "a" (val), 189 [port] "d" (port) 188 190 ); 189 191 } 190 192 191 193 /** Swap Hidden part of GS register with visible one */ 192 static inline void swapgs(void) 193 { 194 asm volatile("swapgs"); 194 NO_TRACE static inline void swapgs(void) 195 { 196 asm volatile ( 197 "swapgs" 198 ); 195 199 } 196 200 … … 203 207 * 204 208 */ 205 static inline ipl_t interrupts_enable(void) {209 NO_TRACE static inline ipl_t interrupts_enable(void) { 206 210 ipl_t v; 207 211 … … 224 228 * 225 229 */ 226 static inline ipl_t interrupts_disable(void) {230 NO_TRACE static inline ipl_t interrupts_disable(void) { 227 231 ipl_t v; 228 232 … … 244 248 * 245 249 */ 246 static inline void interrupts_restore(ipl_t ipl) {250 NO_TRACE static inline void interrupts_restore(ipl_t ipl) { 247 251 asm volatile ( 248 252 "pushq %[ipl]\n" … … 259 263 * 260 264 */ 261 static inline ipl_t interrupts_read(void) {265 NO_TRACE static inline ipl_t interrupts_read(void) { 262 266 ipl_t v; 263 267 … … 271 275 } 272 276 277 /** Check interrupts state. 278 * 279 * @return True if interrupts are disabled. 280 * 281 */ 282 NO_TRACE static inline bool interrupts_disabled(void) 283 { 284 ipl_t v; 285 286 asm volatile ( 287 "pushfq\n" 288 "popq %[v]\n" 289 : [v] "=r" (v) 290 ); 291 292 return ((v & RFLAGS_IF) == 0); 293 } 294 273 295 /** Write to MSR */ 274 static inline void write_msr(uint32_t msr, uint64_t value)296 NO_TRACE static inline void write_msr(uint32_t msr, uint64_t value) 275 297 { 276 298 asm volatile ( … … 282 304 } 283 305 284 static inline unative_t read_msr(uint32_t msr)306 NO_TRACE static inline unative_t read_msr(uint32_t msr) 285 307 { 286 308 uint32_t ax, dx; … … 295 317 } 296 318 297 298 319 /** Enable local APIC 299 320 * … … 301 322 * 302 323 */ 303 static inline void enable_l_apic_in_msr()324 NO_TRACE static inline void enable_l_apic_in_msr() 304 325 { 305 326 asm volatile ( … … 309 330 "orl $(0xfee00000),%%eax\n" 310 331 "wrmsr\n" 311 ::: "%eax","%ecx","%edx" 312 ); 313 } 314 315 static inline uintptr_t * get_ip() 316 { 317 uintptr_t *ip; 318 319 asm volatile ( 320 "mov %%rip, %[ip]" 321 : [ip] "=r" (ip) 322 ); 323 324 return ip; 332 ::: "%eax", "%ecx", "%edx" 333 ); 325 334 } 326 335 … … 330 339 * 331 340 */ 332 static inline void invlpg(uintptr_t addr)341 NO_TRACE static inline void invlpg(uintptr_t addr) 333 342 { 334 343 asm volatile ( … … 343 352 * 344 353 */ 345 static inline void gdtr_load(ptr_16_64_t *gdtr_reg)354 NO_TRACE static inline void gdtr_load(ptr_16_64_t *gdtr_reg) 346 355 { 347 356 asm volatile ( … … 356 365 * 357 366 */ 358 static inline void gdtr_store(ptr_16_64_t *gdtr_reg)367 NO_TRACE static inline void gdtr_store(ptr_16_64_t *gdtr_reg) 359 368 { 360 369 asm volatile ( … … 369 378 * 370 379 */ 371 static inline void idtr_load(ptr_16_64_t *idtr_reg)380 NO_TRACE static inline void idtr_load(ptr_16_64_t *idtr_reg) 372 381 { 373 382 asm volatile ( … … 381 390 * 382 391 */ 383 static inline void tr_load(uint16_t sel)392 NO_TRACE static inline void tr_load(uint16_t sel) 384 393 { 385 394 asm volatile ( … … 389 398 } 390 399 391 #define GEN_READ_REG(reg) static inline unative_t read_ ##reg (void) \400 #define GEN_READ_REG(reg) NO_TRACE static inline unative_t read_ ##reg (void) \ 392 401 { \ 393 402 unative_t res; \ … … 399 408 } 400 409 401 #define GEN_WRITE_REG(reg) static inline void write_ ##reg (unative_t regn) \410 #define GEN_WRITE_REG(reg) NO_TRACE static inline void write_ ##reg (unative_t regn) \ 402 411 { \ 403 412 asm volatile ( \ … … 426 435 GEN_WRITE_REG(dr7) 427 436 428 extern size_t interrupt_handler_size; 429 extern void interrupt_handlers(void); 437 extern void asm_delay_loop(uint32_t); 438 extern void asm_fake_loop(uint32_t); 439 440 extern uintptr_t int_0; 441 extern uintptr_t int_1; 442 extern uintptr_t int_2; 443 extern uintptr_t int_3; 444 extern uintptr_t int_4; 445 extern uintptr_t int_5; 446 extern uintptr_t int_6; 447 extern uintptr_t int_7; 448 extern uintptr_t int_8; 449 extern uintptr_t int_9; 450 extern uintptr_t int_10; 451 extern uintptr_t int_11; 452 extern uintptr_t int_12; 453 extern uintptr_t int_13; 454 extern uintptr_t int_14; 455 extern uintptr_t int_15; 456 extern uintptr_t int_16; 457 extern uintptr_t int_17; 458 extern uintptr_t int_18; 459 extern uintptr_t int_19; 460 extern uintptr_t int_20; 461 extern uintptr_t int_21; 462 extern uintptr_t int_22; 463 extern uintptr_t int_23; 464 extern uintptr_t int_24; 465 extern uintptr_t int_25; 466 extern uintptr_t int_26; 467 extern uintptr_t int_27; 468 extern uintptr_t int_28; 469 extern uintptr_t int_29; 470 extern uintptr_t int_30; 471 extern uintptr_t int_31; 472 extern uintptr_t int_32; 473 extern uintptr_t int_33; 474 extern uintptr_t int_34; 475 extern uintptr_t int_35; 476 extern uintptr_t int_36; 477 extern uintptr_t int_37; 478 extern uintptr_t int_38; 479 extern uintptr_t int_39; 480 extern uintptr_t int_40; 481 extern uintptr_t int_41; 482 extern uintptr_t int_42; 483 extern uintptr_t int_43; 484 extern uintptr_t int_44; 485 extern uintptr_t int_45; 486 extern uintptr_t int_46; 487 extern uintptr_t int_47; 488 extern uintptr_t int_48; 489 extern uintptr_t int_49; 490 extern uintptr_t int_50; 491 extern uintptr_t int_51; 492 extern uintptr_t int_52; 493 extern uintptr_t int_53; 494 extern uintptr_t int_54; 495 extern uintptr_t int_55; 496 extern uintptr_t int_56; 497 extern uintptr_t int_57; 498 extern uintptr_t int_58; 499 extern uintptr_t int_59; 500 extern uintptr_t int_60; 501 extern uintptr_t int_61; 502 extern uintptr_t int_62; 503 extern uintptr_t int_63; 430 504 431 505 #endif -
kernel/arch/amd64/include/atomic.h
rfb150d78 r46c20c8 36 36 #define KERN_amd64_ATOMIC_H_ 37 37 38 #include < arch/types.h>38 #include <typedefs.h> 39 39 #include <arch/barrier.h> 40 40 #include <preemption.h> 41 #include <trace.h> 41 42 42 static inline void atomic_inc(atomic_t *val) { 43 NO_TRACE static inline void atomic_inc(atomic_t *val) 44 { 43 45 #ifdef CONFIG_SMP 44 46 asm volatile ( … … 54 56 } 55 57 56 static inline void atomic_dec(atomic_t *val) { 58 NO_TRACE static inline void atomic_dec(atomic_t *val) 59 { 57 60 #ifdef CONFIG_SMP 58 61 asm volatile ( … … 68 71 } 69 72 70 static inline long atomic_postinc(atomic_t *val) 73 NO_TRACE static inline atomic_count_t atomic_postinc(atomic_t *val) 71 74 { 72 longr = 1;75 atomic_count_t r = 1; 73 76 74 77 asm volatile ( 75 78 "lock xaddq %[r], %[count]\n" 76 : [count] "+m" (val->count), [r] "+r" (r) 79 : [count] "+m" (val->count), 80 [r] "+r" (r) 77 81 ); 78 82 … … 80 84 } 81 85 82 static inline long atomic_postdec(atomic_t *val) 86 NO_TRACE static inline atomic_count_t atomic_postdec(atomic_t *val) 83 87 { 84 longr = -1;88 atomic_count_t r = -1; 85 89 86 90 asm volatile ( 87 91 "lock xaddq %[r], %[count]\n" 88 : [count] "+m" (val->count), [r] "+r" (r) 92 : [count] "+m" (val->count), 93 [r] "+r" (r) 89 94 ); 90 95 … … 95 100 #define atomic_predec(val) (atomic_postdec(val) - 1) 96 101 97 static inline uint64_t test_and_set(atomic_t *val) { 98 uint64_t v; 102 NO_TRACE static inline atomic_count_t test_and_set(atomic_t *val) 103 { 104 atomic_count_t v = 1; 99 105 100 106 asm volatile ( 101 "movq $1, %[v]\n"102 107 "xchgq %[v], %[count]\n" 103 : [v] "=r" (v), [count] "+m" (val->count) 108 : [v] "+r" (v), 109 [count] "+m" (val->count) 104 110 ); 105 111 … … 107 113 } 108 114 109 110 115 /** amd64 specific fast spinlock */ 111 static inline void atomic_lock_arch(atomic_t *val)116 NO_TRACE static inline void atomic_lock_arch(atomic_t *val) 112 117 { 113 uint64_t tmp;118 atomic_count_t tmp; 114 119 115 120 preemption_disable(); 116 121 asm volatile ( 117 122 "0:\n" 118 " pause\n"119 " mov %[count], %[tmp]\n"120 " testq %[tmp], %[tmp]\n"121 " jnz 0b\n" /* lightweight looping on locked spinlock */123 " pause\n" 124 " mov %[count], %[tmp]\n" 125 " testq %[tmp], %[tmp]\n" 126 " jnz 0b\n" /* lightweight looping on locked spinlock */ 122 127 123 "incq %[tmp]\n" /* now use the atomic operation */ 124 "xchgq %[count], %[tmp]\n" 125 "testq %[tmp], %[tmp]\n" 126 "jnz 0b\n" 127 : [count] "+m" (val->count), [tmp] "=&r" (tmp) 128 " incq %[tmp]\n" /* now use the atomic operation */ 129 " xchgq %[count], %[tmp]\n" 130 " testq %[tmp], %[tmp]\n" 131 " jnz 0b\n" 132 : [count] "+m" (val->count), 133 [tmp] "=&r" (tmp) 128 134 ); 135 129 136 /* 130 137 * Prevent critical section code from bleeding out this way up. -
kernel/arch/amd64/include/boot/boot.h
rfb150d78 r46c20c8 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
rfb150d78 r46c20c8 27 27 */ 28 28 29 /** @addtogroup amd64 29 /** @addtogroup amd64 30 30 * @{ 31 31 */ … … 38 38 #ifdef KERNEL 39 39 40 #include < arch/types.h>40 #include <typedefs.h> 41 41 42 42 /* According to ABI the stack MUST be aligned on … … 44 44 * panic sooner or later 45 45 */ 46 #define SP_DELTA 1646 #define SP_DELTA 16 47 47 48 48 #define context_set(c, _pc, stack, size) \ … … 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/context_offset.h
rfb150d78 r46c20c8 30 30 #define KERN_amd64_CONTEXT_OFFSET_H_ 31 31 32 #define OFFSET_SP 0x033 #define OFFSET_PC 0x834 #define OFFSET_RBX 0x1035 #define OFFSET_RBP 0x1836 #define OFFSET_R12 0x2037 #define OFFSET_R13 0x2838 #define OFFSET_R14 0x3039 #define OFFSET_R15 0x3832 #define OFFSET_SP 0x00 33 #define OFFSET_PC 0x08 34 #define OFFSET_RBX 0x10 35 #define OFFSET_RBP 0x18 36 #define OFFSET_R12 0x20 37 #define OFFSET_R13 0x28 38 #define OFFSET_R14 0x30 39 #define OFFSET_R15 0x38 40 40 41 41 #ifdef KERNEL 42 # define OFFSET_IPL0x4042 #define OFFSET_IPL 0x40 43 43 #else 44 # define OFFSET_TLS0x4044 #define OFFSET_TLS 0x40 45 45 #endif 46 46 47 47 #ifdef __ASM__ 48 48 49 # ctx: address of the structure with saved context 49 # ctx: address of the structure with saved context 50 50 # pc: return address 51 51 .macro CONTEXT_SAVE_ARCH_CORE ctx:req pc:req … … 61 61 .endm 62 62 63 # ctx: address of the structure with saved context 63 # ctx: address of the structure with saved context 64 64 .macro CONTEXT_RESTORE_ARCH_CORE ctx:req pc:req 65 65 movq OFFSET_R15(\ctx), %r15 … … 68 68 movq OFFSET_R12(\ctx), %r12 69 69 movq OFFSET_RBP(\ctx), %rbp 70 movq OFFSET_RBX(\ctx), %rbx 70 movq OFFSET_RBX(\ctx), %rbx 71 71 72 72 movq OFFSET_SP(\ctx), %rsp # ctx->sp -> %rsp -
kernel/arch/amd64/include/cpu.h
rfb150d78 r46c20c8 36 36 #define KERN_amd64_CPU_H_ 37 37 38 #define RFLAGS_CF (1 << 0) 39 #define RFLAGS_PF (1 << 2) 40 #define RFLAGS_AF (1 << 4) 41 #define RFLAGS_ZF (1 << 6) 42 #define RFLAGS_SF (1 << 7) 43 #define RFLAGS_TF (1 << 8) 44 #define RFLAGS_IF (1 << 9) 45 #define RFLAGS_DF (1 << 10) 46 #define RFLAGS_OF (1 << 11) 47 #define RFLAGS_RF (1 << 16) 38 #define RFLAGS_CF (1 << 0) 39 #define RFLAGS_PF (1 << 2) 40 #define RFLAGS_AF (1 << 4) 41 #define RFLAGS_ZF (1 << 6) 42 #define RFLAGS_SF (1 << 7) 43 #define RFLAGS_TF (1 << 8) 44 #define RFLAGS_IF (1 << 9) 45 #define RFLAGS_DF (1 << 10) 46 #define RFLAGS_OF (1 << 11) 47 #define RFLAGS_NT (1 << 14) 48 #define RFLAGS_RF (1 << 16) 48 49 49 50 #define EFER_MSR_NUM 0xc0000080 -
kernel/arch/amd64/include/cpuid.h
rfb150d78 r46c20c8 48 48 #ifndef __ASM__ 49 49 50 #include < arch/types.h>50 #include <typedefs.h> 51 51 52 52 typedef struct { -
kernel/arch/amd64/include/cycle.h
rfb150d78 r46c20c8 36 36 #define KERN_amd64_CYCLE_H_ 37 37 38 extern uint64_t get_cycle(void); 38 #include <trace.h> 39 40 NO_TRACE static inline uint64_t get_cycle(void) 41 { 42 uint32_t lower; 43 uint32_t upper; 44 45 asm volatile ( 46 "rdtsc\n" 47 : "=a" (lower), 48 "=d" (upper) 49 ); 50 51 return ((uint64_t) lower) | (((uint64_t) upper) << 32); 52 } 39 53 40 54 #endif -
kernel/arch/amd64/include/ddi/ddi.h
rfb150d78 r46c20c8 33 33 /** 34 34 * @file 35 * @brief amd64 specific DDI declarations and macros.35 * @brief amd64 specific DDI declarations and macros. 36 36 */ 37 37 -
kernel/arch/amd64/include/debugger.h
rfb150d78 r46c20c8 36 36 #define KERN_amd64_DEBUGGER_H_ 37 37 38 #include < arch/types.h>38 #include <typedefs.h> 39 39 40 #define BKPOINTS_MAX 440 #define BKPOINTS_MAX 4 41 41 42 42 /* Flags that are passed to breakpoint_add function */ 43 #define BKPOINT_INSTR 0x144 #define BKPOINT_WRITE 0x245 #define BKPOINT_READ_WRITE 0x443 #define BKPOINT_INSTR 0x1U 44 #define BKPOINT_WRITE 0x2U 45 #define BKPOINT_READ_WRITE 0x4U 46 46 47 #define BKPOINT_CHECK_ZERO 0x847 #define BKPOINT_CHECK_ZERO 0x8U 48 48 49 49 50 50 extern void debugger_init(void); 51 extern int breakpoint_add(const void * where, const int flags, int curidx);52 extern void breakpoint_del(int slot);51 extern int breakpoint_add(const void *, const unsigned int, int); 52 extern void breakpoint_del(int); 53 53 54 54 #endif -
kernel/arch/amd64/include/elf.h
rfb150d78 r46c20c8 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
rfb150d78 r46c20c8 27 27 */ 28 28 29 /** @addtogroup amd64 29 /** @addtogroup amd64 30 30 * @{ 31 31 */ … … 36 36 #define KERN_amd64_FADDR_H_ 37 37 38 #include < arch/types.h>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
rfb150d78 r46c20c8 36 36 #define KERN_amd64_INTERRUPT_H_ 37 37 38 #include <arch/types.h> 38 #include <typedefs.h> 39 #include <arch/istate.h> 39 40 #include <arch/pm.h> 40 41 41 #define IVT_ITEMS IDT_ITEMS42 #define IVT_FIRST 042 #define IVT_ITEMS IDT_ITEMS 43 #define IVT_FIRST 0 43 44 44 #define EXC_COUNT 3245 #define IRQ_COUNT 1645 #define EXC_COUNT 32 46 #define IRQ_COUNT 16 46 47 47 #define IVT_EXCBASE 048 #define IVT_IRQBASE (IVT_EXCBASE + EXC_COUNT)49 #define IVT_FREEBASE (IVT_IRQBASE + IRQ_COUNT)48 #define IVT_EXCBASE 0 49 #define IVT_IRQBASE (IVT_EXCBASE + EXC_COUNT) 50 #define IVT_FREEBASE (IVT_IRQBASE + IRQ_COUNT) 50 51 51 #define IRQ_CLK 0 52 #define IRQ_KBD 1 53 #define IRQ_PIC1 2 54 #define IRQ_PIC_SPUR 7 55 #define IRQ_MOUSE 12 52 #define IRQ_CLK 0 53 #define IRQ_KBD 1 54 #define IRQ_PIC1 2 55 #define IRQ_PIC_SPUR 7 56 #define IRQ_MOUSE 12 57 #define IRQ_DP8390 9 56 58 57 /* this one must have four least significant bits set to ones */58 #define VECTOR_APIC_SPUR (IVT_ITEMS - 1)59 /* This one must have four least significant bits set to ones */ 60 #define VECTOR_APIC_SPUR (IVT_ITEMS - 1) 59 61 60 62 #if (((VECTOR_APIC_SPUR + 1) % 16) || VECTOR_APIC_SPUR >= IVT_ITEMS) … … 62 64 #endif 63 65 64 #define VECTOR_DEBUG 165 #define VECTOR_CLK (IVT_IRQBASE + IRQ_CLK)66 #define VECTOR_PIC_SPUR (IVT_IRQBASE + IRQ_PIC_SPUR)67 #define VECTOR_SYSCALL IVT_FREEBASE68 #define VECTOR_TLB_SHOOTDOWN_IPI (IVT_FREEBASE + 1)69 #define VECTOR_DEBUG_IPI (IVT_FREEBASE + 2)66 #define VECTOR_DEBUG 1 67 #define VECTOR_CLK (IVT_IRQBASE + IRQ_CLK) 68 #define VECTOR_PIC_SPUR (IVT_IRQBASE + IRQ_PIC_SPUR) 69 #define VECTOR_SYSCALL IVT_FREEBASE 70 #define VECTOR_TLB_SHOOTDOWN_IPI (IVT_FREEBASE + 1) 71 #define VECTOR_DEBUG_IPI (IVT_FREEBASE + 2) 70 72 71 /** This is passed to interrupt handlers */ 72 typedef struct istate { 73 uint64_t rax; 74 uint64_t rcx; 75 uint64_t rdx; 76 uint64_t rsi; 77 uint64_t rdi; 78 uint64_t r8; 79 uint64_t r9; 80 uint64_t r10; 81 uint64_t r11; 82 uint64_t rbp; 83 uint64_t error_word; 84 uint64_t rip; 85 uint64_t cs; 86 uint64_t rflags; 87 uint64_t stack[]; /* Additional data on stack */ 88 } istate_t; 89 90 /** Return true if exception happened while in userspace */ 91 static inline int istate_from_uspace(istate_t *istate) 92 { 93 return !(istate->rip & 0x8000000000000000); 94 } 95 96 static inline void istate_set_retaddr(istate_t *istate, uintptr_t retaddr) 97 { 98 istate->rip = retaddr; 99 } 100 static inline unative_t istate_get_pc(istate_t *istate) 101 { 102 return istate->rip; 103 } 104 static inline unative_t istate_get_fp(istate_t *istate) 105 { 106 return istate->rbp; 107 } 108 109 extern void (* disable_irqs_function)(uint16_t irqmask); 110 extern void (* enable_irqs_function)(uint16_t irqmask); 73 extern void (* disable_irqs_function)(uint16_t); 74 extern void (* enable_irqs_function)(uint16_t); 111 75 extern void (* eoi_function)(void); 112 76 113 extern void decode_istate(int n, istate_t *istate);114 77 extern void interrupt_init(void); 115 extern void trap_virtual_enable_irqs(uint16_t irqmask); 116 extern void trap_virtual_disable_irqs(uint16_t irqmask); 117 /* AMD64 - specific page handler */ 118 extern void ident_page_fault(int n, istate_t *istate); 78 extern void trap_virtual_enable_irqs(uint16_t); 79 extern void trap_virtual_disable_irqs(uint16_t); 119 80 120 81 #endif -
kernel/arch/amd64/include/memstr.h
rfb150d78 r46c20c8 27 27 */ 28 28 29 /** @addtogroup amd64 29 /** @addtogroup amd64 30 30 * @{ 31 31 */ … … 38 38 #define memcpy(dst, src, cnt) __builtin_memcpy((dst), (src), (cnt)) 39 39 40 extern void memsetw(void *dst, size_t cnt, uint16_t x); 41 extern void memsetb(void *dst, size_t cnt, uint8_t x); 42 43 extern int memcmp(const void *a, const void *b, size_t cnt); 40 extern void memsetw(void *, size_t, uint16_t); 41 extern void memsetb(void *, size_t, uint8_t); 44 42 45 43 #endif -
kernel/arch/amd64/include/mm/as.h
rfb150d78 r46c20c8 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 0 38 #define ADDRESS_SPACE_HOLE_START UINT64_C(0x0000800000000000) 39 #define ADDRESS_SPACE_HOLE_END UINT64_C(0xffff7fffffffffff) 39 40 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 41 #define KERNEL_ADDRESS_SPACE_SHADOWED_ARCH 0 44 42 45 #define USTACK_ADDRESS_ARCH (USER_ADDRESS_SPACE_END_ARCH-(PAGE_SIZE-1)) 43 #define KERNEL_ADDRESS_SPACE_START_ARCH UINT64_C(0xffff800000000000) 44 #define KERNEL_ADDRESS_SPACE_END_ARCH UINT64_C(0xffffffffffffffff) 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 USER_ADDRESS_SPACE_START_ARCH UINT64_C(0x0000000000000000) 47 #define USER_ADDRESS_SPACE_END_ARCH UINT64_C(0x00007fffffffffff) 48 49 #define USTACK_ADDRESS_ARCH (USER_ADDRESS_SPACE_END_ARCH - (PAGE_SIZE - 1)) 50 51 #define as_constructor_arch(as, flags) (as != as) 52 #define as_destructor_arch(as) (as != as) 53 #define as_create_arch(as, flags) (as != as) 54 50 55 #define as_install_arch(as) 51 56 #define as_deinstall_arch(as) -
kernel/arch/amd64/include/mm/frame.h
rfb150d78 r46c20c8 36 36 #define KERN_amd64_FRAME_H_ 37 37 38 #ifndef __ASM__39 #include <arch/types.h>40 #endif /* __ASM__ */41 42 38 #define FRAME_WIDTH 12 /* 4K */ 43 39 #define FRAME_SIZE (1 << FRAME_WIDTH) 44 40 41 #ifdef KERNEL 45 42 #ifndef __ASM__ 43 44 #include <typedefs.h> 45 46 46 extern uintptr_t last_frame; 47 47 extern void frame_arch_init(void); 48 48 extern void physmem_print(void); 49 49 50 #endif /* __ASM__ */ 51 #endif /* KERNEL */ 50 52 51 53 #endif -
kernel/arch/amd64/include/mm/page.h
rfb150d78 r46c20c8 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 … … 49 46 50 47 #include <arch/mm/frame.h> 51 52 #define PAGE_WIDTH FRAME_WIDTH 53 #define PAGE_SIZE FRAME_SIZE 48 #include <trace.h> 49 50 #define PAGE_WIDTH FRAME_WIDTH 51 #define PAGE_SIZE FRAME_SIZE 54 52 55 53 #ifdef KERNEL 56 54 57 55 #ifndef __ASM__ 58 # include <mm/mm.h> 59 # include <arch/types.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 56 57 #define KA2PA(x) (((uintptr_t) (x)) - UINT64_C(0xffff800000000000)) 58 #define PA2KA(x) (((uintptr_t) (x)) + UINT64_C(0xffff800000000000)) 59 60 #else /* __ASM__ */ 61 62 #define KA2PA(x) ((x) - 0xffff800000000000) 63 #define PA2KA(x) ((x) + 0xffff800000000000) 64 65 #endif /* __ASM__ */ 77 66 78 67 /* 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 51268 #define PTL0_ENTRIES_ARCH 512 69 #define PTL1_ENTRIES_ARCH 512 70 #define PTL2_ENTRIES_ARCH 512 71 #define PTL3_ENTRIES_ARCH 512 83 72 84 73 /* 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_FRAME74 #define PTL0_SIZE_ARCH ONE_FRAME 75 #define PTL1_SIZE_ARCH ONE_FRAME 76 #define PTL2_SIZE_ARCH ONE_FRAME 77 #define PTL3_SIZE_ARCH ONE_FRAME 89 78 90 79 /* 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)80 #define PTL0_INDEX_ARCH(vaddr) (((vaddr) >> 39) & 0x1ffU) 81 #define PTL1_INDEX_ARCH(vaddr) (((vaddr) >> 30) & 0x1ffU) 82 #define PTL2_INDEX_ARCH(vaddr) (((vaddr) >> 21) & 0x1ffU) 83 #define PTL3_INDEX_ARCH(vaddr) (((vaddr) >> 12) & 0x1ffU) 95 84 96 85 /* Get PTE address accessors for each level. */ … … 156 145 #ifndef __ASM__ 157 146 147 #include <mm/mm.h> 148 #include <arch/interrupt.h> 149 #include <typedefs.h> 150 158 151 /* Page fault error codes. */ 159 152 … … 161 154 * page. 162 155 */ 163 #define PFERR_CODE_P (1 << 0)156 #define PFERR_CODE_P (1 << 0) 164 157 165 158 /** When bit on this position is 1, the page fault was caused by a write. */ 166 #define PFERR_CODE_RW (1 << 1)159 #define PFERR_CODE_RW (1 << 1) 167 160 168 161 /** When bit on this position is 1, the page fault was caused in user mode. */ 169 #define PFERR_CODE_US (1 << 2)162 #define PFERR_CODE_US (1 << 2) 170 163 171 164 /** When bit on this position is 1, a reserved bit was set in page directory. */ 172 #define PFERR_CODE_RSVD (1 << 3)165 #define PFERR_CODE_RSVD (1 << 3) 173 166 174 167 /** When bit on this position os 1, the page fault was caused during instruction 175 168 * fecth. 176 169 */ 177 #define PFERR_CODE_ID (1 << 4)170 #define PFERR_CODE_ID (1 << 4) 178 171 179 172 /** Page Table Entry. */ 180 173 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;174 unsigned int present : 1; 175 unsigned int writeable : 1; 176 unsigned int uaccessible : 1; 177 unsigned int page_write_through : 1; 178 unsigned int page_cache_disable : 1; 179 unsigned int accessed : 1; 180 unsigned int dirty : 1; 181 unsigned int unused: 1; 182 unsigned int global : 1; 183 unsigned int soft_valid : 1; /**< Valid content even if present bit is cleared. */ 184 unsigned int avl : 2; 185 unsigned int addr_12_31 : 30; 186 unsigned int addr_32_51 : 21; 187 unsigned int no_execute : 1; 195 188 } __attribute__ ((packed)) pte_t; 196 189 197 static inline unsigned int get_pt_flags(pte_t *pt, size_t i)190 NO_TRACE static inline unsigned int get_pt_flags(pte_t *pt, size_t i) 198 191 { 199 192 pte_t *p = &pt[i]; … … 208 201 } 209 202 210 static inline void set_pt_addr(pte_t *pt, size_t i, uintptr_t a)203 NO_TRACE static inline void set_pt_addr(pte_t *pt, size_t i, uintptr_t a) 211 204 { 212 205 pte_t *p = &pt[i]; 213 214 p->addr_12_31 = (a >> 12) & 0xfffff;206 207 p->addr_12_31 = (a >> 12) & UINT32_C(0xfffff); 215 208 p->addr_32_51 = a >> 32; 216 209 } 217 210 218 static inline void set_pt_flags(pte_t *pt, size_t i, int flags)211 NO_TRACE static inline void set_pt_flags(pte_t *pt, size_t i, int flags) 219 212 { 220 213 pte_t *p = &pt[i]; … … 234 227 235 228 extern void page_arch_init(void); 236 extern void page_fault( int n, istate_t *istate);229 extern void page_fault(unsigned int, istate_t *); 237 230 238 231 #endif /* __ASM__ */ -
kernel/arch/amd64/include/mm/ptl.h
rfb150d78 r46c20c8 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
rfb150d78 r46c20c8 27 27 */ 28 28 29 /** @addtogroup amd64mm 29 /** @addtogroup amd64mm 30 30 * @{ 31 31 */ -
kernel/arch/amd64/include/pm.h
rfb150d78 r46c20c8 37 37 38 38 #ifndef __ASM__ 39 #include < arch/types.h>39 #include <typedefs.h> 40 40 #include <arch/context.h> 41 41 #endif … … 65 65 #endif /* CONFIG_FB */ 66 66 67 #define gdtselector(des) ((des) << 3) 68 #define idtselector(des) ((des) << 4) 67 #define GDT_SELECTOR(des) ((des) << 3) 69 68 70 69 #define PL_KERNEL 0 71 70 #define PL_USER 3 72 71 73 #define AR_PRESENT (1 << 7)72 #define AR_PRESENT (1 << 7) 74 73 #define AR_DATA (2 << 3) 75 74 #define AR_CODE (3 << 3) 76 75 #define AR_WRITABLE (1 << 1) 77 76 #define AR_READABLE (1 << 1) 78 #define AR_TSS (0x09 )79 #define AR_INTERRUPT (0x0e )80 #define AR_TRAP (0x0f )77 #define AR_TSS (0x09U) 78 #define AR_INTERRUPT (0x0eU) 79 #define AR_TRAP (0x0fU) 81 80 82 81 #define DPL_KERNEL (PL_KERNEL << 5) … … 84 83 85 84 #define TSS_BASIC_SIZE 104 86 #define TSS_IOMAP_SIZE ( 16 * 1024 + 1) /* 16K for bitmap + 1 terminating byte for convenience */85 #define TSS_IOMAP_SIZE (8 * 1024 + 1) /* 8K for bitmap + 1 terminating byte for convenience */ 87 86 88 87 #define IO_PORTS (64 * 1024) … … 168 167 169 168 extern ptr_16_64_t gdtr; 170 extern ptr_16_32_t bootstrap_gdtr;171 169 extern ptr_16_32_t protected_ap_gdtr; 172 170 -
kernel/arch/amd64/include/proc/task.h
rfb150d78 r46c20c8 36 36 #define KERN_amd64_TASK_H_ 37 37 38 #include < arch/types.h>38 #include <typedefs.h> 39 39 #include <adt/bitmap.h> 40 40 -
kernel/arch/amd64/include/proc/thread.h
rfb150d78 r46c20c8 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
rfb150d78 r46c20c8 36 36 #define KERN_amd64_TYPES_H_ 37 37 38 typedef signed char int8_t;39 typedef signed short int16_t;40 typedef signed int int32_t;41 typedef signed long long int64_t;42 43 typedef unsigned char uint8_t;44 typedef unsigned short uint16_t;45 typedef unsigned int uint32_t;46 typedef unsigned long long uint64_t;47 48 38 typedef uint64_t size_t; 49 39 … … 55 45 typedef uint64_t unative_t; 56 46 typedef int64_t native_t; 47 typedef uint64_t atomic_count_t; 57 48 58 49 typedef struct { 59 50 } fncptr_t; 60 51 61 /**< Formats for uintptr_t, size_t */ 62 #define PRIp "llx" 63 #define PRIs "llu" 52 #define INTN_C(c) INT64_C(c) 53 #define UINTN_C(c) UINT64_C(c) 64 54 65 /**< Formats for (u)int8_t, (u)int16_t, (u)int32_t, (u)int64_t and (u)native_t */ 66 #define PRId8 "d" 67 #define PRId16 "d" 68 #define PRId32 "d" 69 #define PRId64 "lld" 70 #define PRIdn "lld" 71 72 #define PRIu8 "u" 73 #define PRIu16 "u" 74 #define PRIu32 "u" 75 #define PRIu64 "llu" 76 #define PRIun "llu" 77 78 #define PRIx8 "x" 79 #define PRIx16 "x" 80 #define PRIx32 "x" 81 #define PRIx64 "llx" 82 #define PRIxn "llx" 55 #define PRIdn PRId64 /**< Format for native_t. */ 56 #define PRIun PRIu64 /**< Format for unative_t. */ 57 #define PRIxn PRIx64 /**< Format for hexadecimal unative_t. */ 58 #define PRIua PRIu64 /**< Format for atomic_count_t. */ 83 59 84 60 #endif
Note:
See TracChangeset
for help on using the changeset viewer.
