Warning, cross-references for /kernel/boot/boot.S need to be fixed.
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 #include "kernel.h"
0029
0030 .globl initial_gdt
0031
0032 .bss
0033 .align 0x1000
0034 .comm pgd, 0x1000
0035
0036 .align 0x1000
0037 .comm idt, 0x1000
0038
0039 .align 0x1000
0040 .comm kern_pg_table, 0x1000
0041
0042 .align 0x1000
0043 .comm tmp_stack, 0x1000
0044
0045 .data
0046 .align 4
0047 initial_gdt:
0048
0049 .long 0
0050 .long 0
0051
0052
0053
0054 .long 0x0000FFFF
0055 .long 0x00CF9A00
0056
0057
0058
0059 .long 0x0000FFFF
0060 .long 0x00CF9200
0061
0062
0063
0064 .long 0x0000FFFF
0065 .long 0x00CBFA00
0066
0067
0068 .long 0x0000FFFF
0069 .long 0x00CBF200
0070
0071 gdt_ptr:
0072 .short 0x7FF
0073 .long KERN_GDT
0074
0075 .globl idt_ptr
0076 idt_ptr:
0077 .short 0x7FF
0078 .long KERN_IDT
0079
0080
0081 .text
0082 .globl _start
0083
0084 _start:
0085 jmp real_start
0086
0087
0088 .align 4
0089 .long 0x1BADB002
0090 .long 0x00000003
0091
0092 .long 0xE4524FFB
0093
0094 real_start:
0095
0096
0097 movw $0x8A00, %ax
0098 movw $0x8A00, %dx
0099 outw %ax, (%dx)
0100
0101
0102 movl $tmp_stack+0x1000, %esp
0103
0104
0105 pushl %ebx
0106
0107
0108 pushl $2
0109 popf
0110
0111
0112 movl $idt, %edi
0113 addl $0x800, %edi
0114 movl $initial_gdt, %esi
0115 movl $10, %ecx
0116 rep movsl
0117 lgdt gdt_ptr
0118
0119
0120
0121
0122 movl %cr4, %eax
0123 orl $0x10, %eax
0124 movl %eax, %cr4
0125
0126
0127 movl $0x83, %eax
0128 movl %eax, pgd
0129
0130
0131 movl $0xFEC00083, %eax
0132 movl %eax, pgd+0xFEC
0133
0134
0135
0136
0137 movl $kern_pg_table+3, %eax
0138 movl %eax, pgd+0xFFC
0139
0140
0141
0142
0143 movl $kern_pg_table, %edi
0144 movl $_physicalkernelstart, %eax
0145 orl $0x1, %eax
0146 movl $_readonly_pages, %ecx
0147 1: stosl
0148 addl $0x1000, %eax
0149 loop 1b
0150
0151 orl $0x3, %eax
0152 movl $_readwrite_pages, %ecx
0153 1: stosl
0154 addl $0x1000, %eax
0155 loop 1b
0156
0157
0158 movl $idt+3, %eax
0159
0160
0161
0162
0163
0164
0165
0166 movl %eax, kern_pg_table + ( ( KERN_IDT >> 10 ) & 0x0FFF )
0167
0168
0169
0170 movl $kern_pg_table+3, %eax
0171 movl %eax, kern_pg_table + ( ( KERN_PGT >> 10 ) & 0x0FFF )
0172
0173
0174 movl $0x000B8003, %eax
0175 movl %eax, kern_pg_table + ( ( KERN_SCR >> 10 ) & 0x0FFF )
0176
0177
0178 movl $pgd, %eax
0179 movl %eax, %cr3
0180 movl %cr0, %eax
0181 orl $0x80000000, %eax
0182 movl %eax, %cr0
0183
0184
0185 ljmp $0x08,$1f
0186
0187 1:
0188
0189
0190 movw $0x10, %ax
0191 movw %ax, %ds
0192 movw %ax, %es
0193 movw %ax, %fs
0194 movw %ax, %gs
0195 movw %ax, %ss
0196
0197
0198 xorw %ax, %ax
0199 lldt %ax
0200
0201
0202 movl $KERN_IDT, %edi
0203 movl $0x100, %ecx
0204 movl $0x080000,%edx
0205 movl $int_table,%esi
0206
0207
0208
0209
0210 1:
0211 lodsl
0212 movw %ax,%dx
0213 movw $0xEE00,%ax
0214 movl %edx,(%edi)
0215 addl $4,%edi
0216 stosl
0217 loop 1b
0218
0219 lidt idt_ptr
0220
0221 popl %ebx
0222 movl $stack+0x1000, %esp
0223 pushl %ebx
0224 call init
0225
0226 realmodetest:
0227 push %ebp
0228 movl %esp, %ebp
0229 movl $_code16physicalstart, %esi
0230 movl $_code16start, %edi
0231 movl $_code16_pages, %ecx
0232 shll $12, %ecx
0233 rep movsb
0234
0235 movl $realmodestub, %esi
0236 movl $0x7c00, %edi
0237 movl realmodestub_len, %ecx
0238 rep movsb
0239
0240 lgdt 0x7c00 + realmodegdtdesc - realmodestub
0241 movw $0x20, %ax
0242 movw %ax, %ds
0243 movw %ax, %es
0244 movw %ax, %fs
0245 movw %ax, %gs
0246 movw %ax, %ss
0247
0248 ljmp $0x18, $0x7c00
0249
0250 1: jmp 1b
0251 ret
0252
0253 .code16
0254 realmodestub:
0255
0256 movl %cr0, %eax
0257 andb $0xFE, %al
0258 movl %eax, %cr0
0259
0260 data32 ljmp $0x0, $1f
0261 1:
0262 xorw %ax, %ax
0263 movw %ax, %ds
0264 movw %ax, %es
0265 movw %ax, %fs
0266 movw %ax, %gs
0267 movw %ax, %ss
0268 movw $0x9000, %sp
0269 lidt 0x7c00 + ivt - realmodestub
0270 sti
0271 ljmp $0x0, $_code16start
0272 ivt: .short 0x3ff
0273 .long 0x0
0274 .p2align 2
0275 realmodegdt:
0276 .word 0, 0
0277 .byte 0, 0, 0, 0
0278
0279
0280
0281
0282
0283 .word 0xFFFF, 0
0284 .byte 0, 0x9A, 0xCF, 0
0285
0286
0287
0288
0289
0290 .word 0xFFFF, 0
0291 .byte 0, 0x92, 0xCF, 0
0292
0293
0294
0295
0296
0297 .word 0xFFFF, 0
0298 .byte 0, 0x9E, 0, 0
0299
0300
0301
0302
0303
0304 .word 0xFFFF, 0
0305 .byte 0, 0x92, 0, 0
0306 realmodegdtdesc:
0307 .word 0x27
0308 .long realmodegdt
0309 realmodestub_len:
0310 .long . - realmodestub
0311 .code32
0312
0313 int_table:
0314
0315 .long interrupt0
0316 .long interrupt1
0317 .long interrupt2
0318 .long interrupt3
0319 .long interrupt4
0320 .long interrupt5
0321 .long interrupt6
0322 .long interrupt7
0323 .long interrupt8
0324 .long interrupt9
0325 .long interrupta
0326 .long interruptb
0327 .long interruptc
0328 .long interruptd
0329 .long interrupte
0330 .long interruptIGN
0331 .long interrupt10
0332 .long interrupt11
0333 .long interrupt12
0334 .long interrupt13
0335 .long interrupt14
0336 .long interrupt15
0337 .long interrupt16
0338 .long interrupt17
0339 .long interrupt18
0340 .long interrupt19
0341 .long interrupt1a
0342 .long interrupt1b
0343 .long interrupt1c
0344 .long interrupt1d
0345 .long interrupt1e
0346 .long interrupt1f
0347
0348
0349 .long timer
0350 .long interrupt21
0351 .long interrupt22
0352 .long interrupt23
0353 .long interrupt24
0354 .long soundcard
0355
0356 .long interrupt26
0357 .long interrupt27
0358 .long interrupt28
0359 .long interrupt29
0360 .long interrupt2a
0361 .long interrupt2b
0362 .long interrupt2c
0363 .long interrupt2d
0364 .long interrupt2e
0365 .long interrupt2f
0366
0367
0368 .long syscall0
0369 .long syscall1
0370 .long syscall2
0371 .long syscall3
0372 .long syscall4
0373 .long syscall5
0374 .long syscall6
0375 .long syscall7
0376 .long syscall8
0377 .long syscall9
0378 .long syscalla
0379 .long syscallb
0380 .long syscallc
0381 .long interrupt3d
0382 .long interrupt3e
0383 .long interrupt3f
0384 #define INT(n) .long interrupt##n
0385 INT(40)
0386 INT(41)
0387 INT(42)
0388 INT(43)
0389 INT(44)
0390 INT(45)
0391 INT(46)
0392 INT(47)
0393 INT(48)
0394 INT(49)
0395 INT(4a)
0396 INT(4b)
0397 INT(4c)
0398 INT(4d)
0399 INT(4e)
0400 INT(4f)
0401 INT(50)
0402 INT(51)
0403 INT(52)
0404 INT(53)
0405 INT(54)
0406 INT(55)
0407 INT(56)
0408 INT(57)
0409 INT(58)
0410 INT(59)
0411 INT(5a)
0412 INT(5b)
0413 INT(5c)
0414 INT(5d)
0415 INT(5e)
0416 INT(5f)
0417 INT(60)
0418 INT(61)
0419 INT(62)
0420 INT(63)
0421 INT(64)
0422 INT(65)
0423 INT(66)
0424 INT(67)
0425 INT(68)
0426 INT(69)
0427 INT(6a)
0428 INT(6b)
0429 INT(6c)
0430 INT(6d)
0431 INT(6e)
0432 INT(6f)
0433 INT(70)
0434 INT(71)
0435 INT(72)
0436 INT(73)
0437 INT(74)
0438 INT(75)
0439 INT(76)
0440 INT(77)
0441 INT(78)
0442 INT(79)
0443 INT(7a)
0444 INT(7b)
0445 INT(7c)
0446 INT(7d)
0447 INT(7e)
0448 INT(7f)
0449 INT(80)
0450 INT(81)
0451 INT(82)
0452 INT(83)
0453 INT(84)
0454 INT(85)
0455 INT(86)
0456 INT(87)
0457 INT(88)
0458 INT(89)
0459 INT(8a)
0460 INT(8b)
0461 INT(8c)
0462 INT(8d)
0463 INT(8e)
0464 INT(8f)
0465 INT(90)
0466 INT(91)
0467 INT(92)
0468 INT(93)
0469 INT(94)
0470 INT(95)
0471 INT(96)
0472 INT(97)
0473 INT(98)
0474 INT(99)
0475 INT(9a)
0476 INT(9b)
0477 INT(9c)
0478 INT(9d)
0479 INT(9e)
0480 INT(9f)
0481 INT(a0)
0482 INT(a1)
0483 INT(a2)
0484 INT(a3)
0485 INT(a4)
0486 INT(a5)
0487 INT(a6)
0488 INT(a7)
0489 INT(a8)
0490 INT(a9)
0491 INT(aa)
0492 INT(ab)
0493 INT(ac)
0494 INT(ad)
0495 INT(ae)
0496 INT(af)
0497 INT(b0)
0498 INT(b1)
0499 INT(b2)
0500 INT(b3)
0501 INT(b4)
0502 INT(b5)
0503 INT(b6)
0504 INT(b7)
0505 INT(b8)
0506 INT(b9)
0507 INT(ba)
0508 INT(bb)
0509 INT(bc)
0510 INT(bd)
0511 INT(be)
0512 INT(bf)
0513 INT(c0)
0514 INT(c1)
0515 INT(c2)
0516 INT(c3)
0517 INT(c4)
0518 INT(c5)
0519 INT(c6)
0520 INT(c7)
0521 INT(c8)
0522 INT(c9)
0523 INT(ca)
0524 INT(cb)
0525 INT(cc)
0526 INT(cd)
0527 INT(ce)
0528 INT(cf)
0529 INT(d0)
0530 INT(d1)
0531 INT(d2)
0532 INT(d3)
0533 INT(d4)
0534 INT(d5)
0535 INT(d6)
0536 INT(d7)
0537 INT(d8)
0538 INT(d9)
0539 INT(da)
0540 INT(db)
0541 INT(dc)
0542 INT(dd)
0543 INT(de)
0544 INT(df)
0545 INT(e0)
0546 INT(e1)
0547 INT(e2)
0548 INT(e3)
0549 INT(e4)
0550 INT(e5)
0551 INT(e6)
0552 INT(e7)
0553 INT(e8)
0554 INT(e9)
0555 INT(ea)
0556 INT(eb)
0557 INT(ec)
0558 INT(ed)
0559 INT(ee)
0560 INT(ef)
0561 INT(f0)
0562 INT(f1)
0563 INT(f2)
0564 INT(f3)
0565 INT(f4)
0566 INT(f5)
0567 INT(f6)
0568 INT(f7)
0569 INT(f8)
0570 INT(f9)
0571 INT(fa)
0572 INT(fb)
0573 INT(fc)
0574 INT(fd)
0575 INT(fe)
0576 INT(ff)
0577 #undef INT
0578
0579