1
1

entry.asm 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. extern kmain
  2. extern INIT_STACK
  3. [section .text]
  4. global kentry:function
  5. kentry:
  6. mov rsp, INIT_STACK
  7. call kmain
  8. .lp:
  9. sti
  10. hlt
  11. jmp .lp
  12. global reset_seg:function
  13. ; fn reset_seg(di code_selector, si data_selector)
  14. reset_seg:
  15. push rdi
  16. push .ret
  17. retfq
  18. .ret:
  19. mov ds, si
  20. mov es, si
  21. mov ss, si
  22. ret
  23. global cpu_in_intr:function
  24. ; fn cpu_in_intr() -> u32
  25. cpu_in_intr:
  26. mov ax, cs
  27. cmp ax, 0xC
  28. je .true
  29. mov eax, 0
  30. jmp .ret
  31. .true:
  32. mov eax, 1
  33. .ret:
  34. ret
  35. global checked_copy:function
  36. ; fn checked_copy(
  37. ; (rdi) dst: *mut u64,
  38. ; (rsi) src: *const u64,
  39. ; (rdx) pf_resume: *mut Option<NonZeroU64>,
  40. ; (rcx) count: usize,
  41. ;) -> (usize, usize)
  42. checked_copy:
  43. mov rax, .fault
  44. mov r11, rdx
  45. mov [r11], rax
  46. mov r10, rcx
  47. shr rcx, 3
  48. rep movsq
  49. and r10, 7
  50. jz .ok
  51. mov rcx, r10
  52. rep movsb
  53. .ok:
  54. xor rdx, rdx
  55. xor rax, rax
  56. .ret:
  57. mov qword [r11], 0
  58. mov r11, 0
  59. ret
  60. .fault:
  61. add rdx, 1
  62. jmp .ret