《操作系统》的实验代码。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.1 KiB

  1. #include <mmu.h>
  2. #include <memlayout.h>
  3. #define REALLOC(x) (x - KERNBASE)
  4. .text
  5. .globl kern_entry
  6. kern_entry:
  7. # reload temperate gdt (second time) to remap all physical memory
  8. # virtual_addr 0~4G=linear_addr&physical_addr -KERNBASE~4G-KERNBASE
  9. lgdt REALLOC(__gdtdesc)
  10. movl $KERNEL_DS, %eax
  11. movw %ax, %ds
  12. movw %ax, %es
  13. movw %ax, %ss
  14. ljmp $KERNEL_CS, $relocated
  15. relocated:
  16. # set ebp, esp
  17. movl $0x0, %ebp
  18. # the kernel stack region is from bootstack -- bootstacktop,
  19. # the kernel stack size is KSTACKSIZE (8KB)defined in memlayout.h
  20. movl $bootstacktop, %esp
  21. # now kernel stack is ready , call the first C function
  22. call kern_init
  23. # should never get here
  24. spin:
  25. jmp spin
  26. .data
  27. .align PGSIZE
  28. .globl bootstack
  29. bootstack:
  30. .space KSTACKSIZE
  31. .globl bootstacktop
  32. bootstacktop:
  33. .align 4
  34. __gdt:
  35. SEG_NULL
  36. SEG_ASM(STA_X | STA_R, - KERNBASE, 0xFFFFFFFF) # code segment
  37. SEG_ASM(STA_W, - KERNBASE, 0xFFFFFFFF) # data segment
  38. __gdtdesc:
  39. .word 0x17 # sizeof(__gdt) - 1
  40. .long REALLOC(__gdt)