view cos/kernel/asmcode.asm @ 180:25a0753da4cf

Re-organized files
author Windel Bouwman
date Thu, 09 May 2013 17:35:19 +0200
parents 91f91ff07ea8
children
line wrap: on
line source

; The default interrupt handlers.
; from 20 - 31 are reserved vectors.
; below are the custom ones!

; Calling convention AMD64 ABI:
; parameters in: rdi, rsi, rdx, rcx ....

section .text
align 4

; Function to read the current instruction pointer value:
global read_rip
read_rip:
   pop rax
   jmp rax

global loadIDT
loadIDT:
  extern idtP
  ; TODO: make this pointer thing more insightfull:
  lidt [idtP]
  ret

global setCR3
setCR3:
   mov cr3, rdi ; Load cr3
   ret

; ISR related assembler wrappers:

%macro ISR_NOERRCODE 1
global INT%1
INT%1:
  cli
  push strict qword 0 ; push dummy error code
  push strict qword %1 ; push interrupt number
  jmp isr_common_stub
%endmacro

%macro ISR_ERRCODE 1
global INT%1
INT%1:
  cli ; disable interrupts
  push strict qword %1 ; push interrupt number
  jmp isr_common_stub
%endmacro

isr_common_stub:
  ; Do some saving:
  push rax ; regs[6]
  push rcx
  push rdx
  push rbx
  push rbp
  push rsi
  push rdi ; regs[0]

  ; AMD64 calling convention, first parameter is in rdi:
  mov rdi, rsp ; Load stack pointer into rdi to indicate where the registers on the stack are (so that we can change them!)

   ; TODO: load kernel interrupt stack pointer
  extern isr_handler
  call isr_handler

  pop rdi
  pop rsi
  pop rbp
  pop rbx
  pop rdx
  pop rcx
  pop rax

  add rsp, 16 ; cleanup error code and isr number
  sti ; enable interrupts again
  iretq

; Exception handlers:
ISR_NOERRCODE 0
ISR_NOERRCODE 1
ISR_NOERRCODE 2
ISR_NOERRCODE 3
ISR_NOERRCODE 4
ISR_NOERRCODE 5
ISR_NOERRCODE 6
ISR_NOERRCODE 7
ISR_ERRCODE   8
ISR_NOERRCODE 9
ISR_ERRCODE 10
ISR_ERRCODE 11
ISR_ERRCODE 12
ISR_ERRCODE 13
ISR_ERRCODE 14
; 15 is reserved
ISR_NOERRCODE 16
ISR_ERRCODE 17
ISR_NOERRCODE 18
ISR_NOERRCODE 19
; 20 - 31 are reserved

; irq handlers:
ISR_NOERRCODE 32
ISR_NOERRCODE 33
ISR_NOERRCODE 34
ISR_NOERRCODE 35
ISR_NOERRCODE 36
ISR_NOERRCODE 37
ISR_NOERRCODE 38
ISR_NOERRCODE 39
ISR_NOERRCODE 40
ISR_NOERRCODE 41
ISR_NOERRCODE 42
ISR_NOERRCODE 43
ISR_NOERRCODE 44
ISR_NOERRCODE 45
ISR_NOERRCODE 46
ISR_NOERRCODE 47

; default handler:
ISR_NOERRCODE 255