@@ -16,45 +16,58 @@ section .text:
1616
1717 push ax ; Saves AX to stack
1818 push bx ; Saves BX to stack
19- push msg ; Loads message to stack
19+ push msg1 ; Loads message to stack
2020 call _printform at ; Prints the message
2121 pop ax ; Recover AX value from stack
2222 pop bx ; Recover BX value from stack
2323
2424 mov bx , buffer ; Writes input buffer address to BX
2525 push ax ; Saves AX to stack
2626 push bx ; Saves BX to stack
27- push 4 ; Writes buffer length
27+ push 1 ; Writes buffer length
2828 call _gets ; Calls _gets
2929 pop ax ; Recover AX value from stack
3030 pop bx ; Recover BX value from stack
3131
32- push ax ; Saves AX to stack
33- push bx ; Saves BX to stack
34- push buffer ; Loads input buffer to stack
35- call _printform at ; Prints the buffer
36- pop ax ; Recover AX value from stack
37- pop bx ; Recover BX value from stack
38-
32+ mov ax , [ buffer ]
33+ cmp ax , 0x4e
34+ je _stop
35+
3936 mov [ disk_index ], dl ; Save boot disk to variable
4037 mov bx , kernel_address ; Write to BX kernel origin
41- mov dh , 2 ; Read two sectors
38+ mov dh , 1 ; Read one sectors
4239 call _read_disk ; Read 16 bits from disk
4340
41+
42+ cli ; Disables BIOS interupts
43+ lgdt [ GDT_descriptor ] ; Load GDT
44+ mov eax , cr0 ; Write CR0 value to EAX
45+ or eax , 1 ; Change it to one by logical OR
46+ mov cr0 , eax ; Swap values
47+ jmp CODE_SEG:_enter_protected_mode
48+
49+ _stop:
50+ push msg2
51+ call _printform at
4452 jmp $ ; Stops the processor
4553
4654
4755; Data Section
4856%include "functions/io.asm"
4957%include "functions/disk_mng.asm"
5058
51- msg: db "Hello, There!\nPlease enter your message: \0" ; Printable string
52-
53- buffer: times 4 db 0 ; Defines input buffer
59+ msg1: db "Hello, There!\nDo You want to enter 32 bit mode?[Y]/[N](default=Y) \0" ; Printable string
60+ msg2: db "Goodby!\0"
61+
62+ buffer: db 'Y' ; Defines input buffer
5463
5564 kernel_address: equ 0x1000 ; Kernel origin
5665 disk_index: db 0 ; Variable to store boot drive index
5766
67+ CODE_SEG: equ GDT_code - GDT_start
68+ DATA_SEG: equ GDT_data - GDT_start
69+
70+
5871; Global Descriptor Table
5972GDT_start:
6073 GDT_null:
@@ -89,7 +102,15 @@ GDT_start:
89102 dw GDT_end - GDT_start - 1 ; Size of GDT
90103 dd GDT_start ; Start of GDT
91104
105+ [ bits 32 ]
106+ _enter_protected_mode:
107+ mov al , 'A'
108+ mov ah , 0x0f
109+ mov [ 0xb8000 ], ax
110+ jmp $
111+
112+
92113 times 510 - ($ - $$) db 0 ; Fills binary with 0 to keep the offset of 512
93114 dw 0xAA55 ; Magic Word
94- times 512 db 'A' ; sector 2 = 512 bytes
95- times 512 db 'B ' ; sector 3 = 512 bytes
115+
116+ times 512 db 'A ' ; sector 2 = 512 bytes
0 commit comments