Multiple changes (Module Interopability, Timers, FDD Driver, VFS Bugs)
[tpg/acess2.git] / Kernel / arch / x86 / start.asm
1 ; AcessOS Microkernel Version\r
2 ; Start.asm\r
3 \r
4 [bits 32]\r
5 \r
6 KERNEL_BASE     equ 0xC0000000\r
7 \r
8 [section .multiboot]\r
9 mboot:\r
10     ; Multiboot macros to make a few lines later more readable\r
11     MULTIBOOT_PAGE_ALIGN        equ 1<<0\r
12     MULTIBOOT_MEMORY_INFO       equ 1<<1\r
13     MULTIBOOT_HEADER_MAGIC      equ 0x1BADB002\r
14     MULTIBOOT_HEADER_FLAGS      equ MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO\r
15     MULTIBOOT_CHECKSUM  equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)\r
16         \r
17     ; This is the GRUB Multiboot header. A boot signature\r
18     dd MULTIBOOT_HEADER_MAGIC\r
19     dd MULTIBOOT_HEADER_FLAGS\r
20     dd MULTIBOOT_CHECKSUM\r
21         dd mboot - KERNEL_BASE  ;Location of Multiboot Header\r
22         \r
23 [section .text]\r
24 [extern kmain]\r
25 [global start]\r
26 start:\r
27         ; Set up stack\r
28         mov esp, Kernel_Stack_Top\r
29         \r
30         ; Start Paging\r
31         mov ecx, gaInitPageDir - KERNEL_BASE\r
32         mov cr3, ecx\r
33         \r
34         mov ecx, cr0\r
35         or      ecx, 0x80010000 ; PG and WP\r
36         mov cr0, ecx\r
37         \r
38         lea ecx, [.higherHalf]\r
39         jmp ecx\r
40 .higherHalf:\r
41 \r
42         mov DWORD [gaInitPageDir], 0\r
43 \r
44         ; Call the kernel\r
45         push ebx        ; Multiboot Info\r
46         push eax        ; Multiboot Magic Value\r
47         call kmain
48
49         ; Halt the Machine\r
50         cli\r
51 .hlt:\r
52         hlt\r
53         jmp .hlt\r
54 \r
55 [global GetEIP]\r
56 GetEIP:\r
57         mov eax, [esp]\r
58         ret\r
59 \r
60 [extern Proc_Clone]\r
61 [extern Threads_Exit]\r
62 [global SpawnTask]\r
63 SpawnTask:\r
64         ; Call Proc_Clone with Flags=0\r
65         xor eax, eax\r
66         push eax
67         push eax\r
68         call Proc_Clone\r
69         add esp, 8      ; Remove arguments from stack\r
70         \r
71         test eax, eax\r
72         jnz .parent\r
73         \r
74         ; In child, so now set up stack frame\r
75         mov ebx, [esp+4]        ; Child Function\r
76         mov edx, [esp+8]        ; Argument\r
77         ; Child\r
78         push edx        ; Argument\r
79         call ebx        ; Function\r
80         call Threads_Exit       ; Kill Thread\r
81         \r
82 .parent:\r
83         ret\r
84 \r
85 [section .initpd]\r
86 [global gaInitPageDir]\r
87 [global gaInitPageTable]\r
88 align 0x1000\r
89 gaInitPageDir:\r
90         dd      gaInitPageTable-KERNEL_BASE+3   ; 0x00\r
91         times 1024-256-1        dd      0\r
92         dd      gaInitPageTable-KERNEL_BASE+3   ; 0xC0\r
93         times 256-1     dd      0\r
94 align 0x1000\r
95 gaInitPageTable:\r
96         %assign i 0\r
97         %rep 1024\r
98         dd      i*0x1000+3\r
99         %assign i i+1\r
100         %endrep\r
101 [global Kernel_Stack_Top]\r
102 ALIGN 0x1000\r
103         times 1024      dd      0\r
104 Kernel_Stack_Top:\r
105         

UCC git Repository :: git.ucc.asn.au