#  head.s contains the -bit startup code.
# Two L3 task multitasking. The code of tasks are in kernel area,
# just like the Linux. The kernel code is located at 0x10000.
SCRN_SEL = 0x18
TSS0_SEL = 0x20
LDT0_SEL = 0x28
TSS1_SEL = 0X30
LDT1_SEL = 0x38 .text
startup_32:
movl $0x10,%eax
mov %ax,%ds
# mov %ax,%es
lss init_stack,%esp # setup base fields of descriptors.
call setup_idt
call setup_gdt
movl $0x10,%eax # reload all the segment registers
mov %ax,%ds # after changing gdt.
mov %ax,%es
mov %ax,%fs
mov %ax,%gs
lss init_stack,%esp # setup up timer chip.
movb $0x36, %al
movl $0x43, %edx
outb %al, %dx
movl $, %eax # timer frequency HZ
movl $0x40, %edx
outb %al, %dx
movb %ah, %al
outb %al, %dx # setup timer & system call interrupt descriptors.
movl $0x00080000, %eax
movw $timer_interrupt, %ax
movw $0x8E00, %dx
movl $0x08, %ecx # The PC default timer int.
lea idt(,%ecx,), %esi
movl %eax,(%esi)
movl %edx,(%esi)
movw $system_interrupt, %ax
movw $0xef00, %dx
movl $0x80, %ecx
lea idt(,%ecx,), %esi
movl %eax,(%esi)
movl %edx,(%esi) # unmask the timer interrupt.
# movl $0x21, %edx
# inb %dx, %al
# andb $0xfe, %al
# outb %al, %dx # Move to user mode (task )
pushfl
andl $0xffffbfff, (%esp)
popfl
movl $TSS0_SEL, %eax
ltr %ax
movl $LDT0_SEL, %eax
lldt %ax
movl $, current
sti
pushl $0x17
pushl $init_stack
pushfl
pushl $0x0f
pushl $task0
iret /****************************************/
setup_gdt:
lgdt lgdt_opcode
ret setup_idt:
lea ignore_int,%edx
movl $0x00080000,%eax
movw %dx,%ax /* selector = 0x0008 = cs */
movw $0x8E00,%dx /* interrupt gate - dpl=, present */
lea idt,%edi
mov $,%ecx
rp_sidt:
movl %eax,(%edi)
movl %edx,(%edi)
addl $,%edi
dec %ecx
jne rp_sidt
lidt lidt_opcode
ret # -----------------------------------
write_char:
push %gs
pushl %ebx
# pushl %eax
mov $SCRN_SEL, %ebx
mov %bx, %gs
movl scr_loc, %bx
shl $, %ebx
movb %al, %gs:(%ebx)
shr $, %ebx
incl %ebx
cmpl $, %ebx
jb 1f
movl $, %ebx
: movl %ebx, scr_loc
# popl %eax
popl %ebx
pop %gs
ret /***********************************************/
/* This is the default interrupt "handler" :-) */
.align
ignore_int:
push %ds
pushl %eax
movl $0x10, %eax
mov %ax, %ds
movl $, %eax /* print 'C' */
call write_char
popl %eax
pop %ds
iret /* Timer interrupt handler */
.align
timer_interrupt:
push %ds
pushl %eax
movl $0x10, %eax
mov %ax, %ds
movb $0x20, %al
outb %al, $0x20
movl $, %eax
cmpl %eax, current
je 1f
movl %eax, current
ljmp $TSS1_SEL, $
jmp 2f
: movl $, current
ljmp $TSS0_SEL, $
: popl %eax
pop %ds
iret /* system call handler */
.align
system_interrupt:
push %ds
pushl %edx
pushl %ecx
pushl %ebx
pushl %eax
movl $0x10, %edx
mov %dx, %ds
call write_char
popl %eax
popl %ebx
popl %ecx
popl %edx
pop %ds
iret /*********************************************/
current:.long
scr_loc:.long .align
lidt_opcode:
.word *- # idt contains entries
.long idt # This will be rewrite by code.
lgdt_opcode:
.word (end_gdt-gdt)- # so does gdt
.long gdt # This will be rewrite by code. .align
idt: .fill ,, # idt is uninitialized gdt: .quad 0x0000000000000000 /* NULL descriptor */
.quad 0x00c09a00000007ff /* 8Mb 0x08, base = 0x00000 */
.quad 0x00c09200000007ff /* 8Mb 0x10 */
.quad 0x00c0920b80000002 /* screen 0x18 - for display */ .word 0x0068, tss0, 0xe900, 0x0 # TSS0 descr 0x20
.word 0x0040, ldt0, 0xe200, 0x0 # LDT0 descr 0x28
.word 0x0068, tss1, 0xe900, 0x0 # TSS1 descr 0x30
.word 0x0040, ldt1, 0xe200, 0x0 # LDT1 descr 0x38
end_gdt:
.fill ,,
init_stack: # Will be used as user stack for task0.
.long init_stack
.word 0x10 /*************************************/
.align
ldt0: .quad 0x0000000000000000
.quad 0x00c0fa00000003ff # 0x0f, base = 0x00000
.quad 0x00c0f200000003ff # 0x17 tss0: .long /* back link */
.long krn_stk0, 0x10 /* esp0, ss0 */
.long , , , , /* esp1, ss1, esp2, ss2, cr3 */
.long , , , , /* eip, eflags, eax, ecx, edx */
.long , , , , /* ebx esp, ebp, esi, edi */
.long , , , , , /* es, cs, ss, ds, fs, gs */
.long LDT0_SEL, 0x8000000 /* ldt, trace bitmap */ .fill ,,
krn_stk0:
# .long /************************************/
.align
ldt1: .quad 0x0000000000000000
.quad 0x00c0fa00000003ff # 0x0f, base = 0x00000
.quad 0x00c0f200000003ff # 0x17 tss1: .long /* back link */
.long krn_stk1, 0x10 /* esp0, ss0 */
.long , , , , /* esp1, ss1, esp2, ss2, cr3 */
.long task1, 0x200 /* eip, eflags */
.long , , , /* eax, ecx, edx, ebx */
.long usr_stk1, , , /* esp, ebp, esi, edi */
.long 0x17,0x0f,0x17,0x17,0x17,0x17 /* es, cs, ss, ds, fs, gs */
.long LDT1_SEL, 0x8000000 /* ldt, trace bitmap */ .fill ,,
krn_stk1: /************************************/
task0:
movl $0x17, %eax
movw %ax, %ds
movl $, %al /* print 'A' */
int $0x80
movl $0xfff, %ecx
: loop 1b
jmp task0 task1:
movl $0x17, %eax
movw %ax, %ds
movl $, %al /* print 'B' */
int $0x80
movl $0xfff, %ecx
: loop 1b
jmp task1 .fill ,,
usr_stk1:

C

最新文章

  1. redis实现tomcat集群session共享
  2. ARCGIS server没有服务、silverlight不能调试、windows server2008安装时跳出“安装程序无法创建新的系统分区也无法定位现有的系统分区”的解决方案
  3. c++时间处理
  4. 【转载】Powershell获取世纪互联Office365中所有用户的OWA时区
  5. poj 3614 Sunscreen
  6. 你不需要jQuery(三):新AJAX方法fetch()
  7. Ajax 技术原理(转)
  8. Bootstrap--导航元素
  9. XSLT 调用外部程序
  10. Unity3D ——强大的跨平台3D游戏开发工具(五)
  11. iOS中UITableView分割线左侧顶齐
  12. Hadoop系列006-HDFS概念及命令行操作
  13. Asp.Net Core 轻松学-玩转配置文件
  14. linux内核调试技巧之一 dump_stack【转】
  15. usermod语法
  16. fPLL结构及动态配置
  17. python中的字符串切片
  18. 11-使用EF操作数据库
  19. updated stream stash changes
  20. 使用cronolog工具给tomcat进行日志切割

热门文章

  1. Coursera课程《Machine Learning》学习笔记(week2)
  2. android菜鸟学习笔记30----Android使用百度地图API(一)准备工作及在应用中显示地图
  3. JavaScript获取地址栏内容
  4. python面试题(三)
  5. Java里的4种引用类型
  6. 测试开发面试的Linux面试题:常用命令
  7. ABAP锁,数据库锁
  8. Centos 常用系统命令
  9. linux mint —— 图片一张
  10. Python学习进程(11)日期和时间