Skip to content

Commit 341685e

Browse files
committed
Commented Global Descriptors Table (GDT)
1 parent ef0e8fe commit 341685e

3 files changed

Lines changed: 24 additions & 18 deletions

File tree

boot.asm

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ section .text:
4848
%include "functions/io.asm"
4949
%include "functions/disk_mng.asm"
5050

51-
msg: db "Hello, There!\nPlease enter your message: ", 0x0 ; Printable string
51+
msg: db "Hello, There!\nPlease enter your message: \0" ; Printable string
5252
5353
buffer: times 4 db 0 ; Defines input buffer
5454

@@ -62,26 +62,32 @@ GDT_start:
6262
dd 0x0
6363

6464
GDT_code:
65-
dw 0xffff
66-
dw 0x0
67-
db 0x0
65+
dw 0xffff ; Segment limit (size)
66+
dw 0x0 ; 8 bit base
67+
db 0x0 ; 4 bit base
6868
db 0b10011010
69+
; 1 - defines a segment 00 - defines highest privilege 1 - defines code segment
70+
; 1 - code segment 0 - disable execution from low privileged segments 1 - readable 0 - access by CPU
6971
db 0b11001111
72+
; 1 - size *= 4096 1 - enable 32 bit memory
7073
db 0x0
7174

7275
GDT_data:
73-
dw 0xffff
74-
dw 0x0
75-
db 0x0
76+
dw 0xffff ; Segment limit (size)
77+
dw 0x0 ; 8 bit base
78+
db 0x0 ; 4 bit base
7679
db 0b10010010
80+
; 1 - defines a segment 00 - defines highest privilege 1 - defines code segment
81+
; 0 - data segment 0 - expandable upwords segment 1 - writable
7782
db 0b11001111
83+
; 1 - size *= 4096 1 - enable 32 bit memory
7884
db 0x0
7985

8086
GDT_end:
8187

8288
GDT_descriptor:
83-
dw GDT_end - GDT_start - 1
84-
dd GDT_start
89+
dw GDT_end - GDT_start - 1 ; Size of GDT
90+
dd GDT_start ; Start of GDT
8591

8692
times 510-($-$$) db 0 ; Fills binary with 0 to keep the offset of 512
8793
dw 0xAA55 ; Magic Word

functions/disk_mng.asm

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,22 @@ section .text:
1212
mov dh, 0x00 ; Head that read
1313

1414
int 0x13 ; BIOS interupt to read data
15-
jc disk_error ; If carry is set raise an error
15+
jc _disk_error ; If carry is set raise an error
1616

1717
pop dx ; Recover DX from stack
1818
cmp al, dh ; Check amount of readen sectors
19-
jne sectors_error ; If they are not equal raise an error
19+
jne _sectors_error ; If they are not equal raise an error
2020
popa ; Recover registers
2121
ret ; Exit the function
2222

2323

24-
disk_error:
25-
push DISK_ERROR
24+
_disk_error:
25+
push disk_error_text
2626
call _printformat
2727

28-
sectors_error:
29-
push SECTORS_ERROR
28+
_sectors_error:
29+
push sectors_error_text
3030
call _printformat
3131

32-
DISK_ERROR: db "Disk read error", 0
33-
SECTORS_ERROR: db "Incorrect number of sectors read", 0
32+
disk_error_text: db "Disk read error\0"
33+
sectors_error_text: db "Incorrect number of sectors read\0",

functions/printf.asm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ section .text:
4646
mov al, [bx] ; Moves addresses value to AL
4747
4848
cmp al, 0x6e ; If character is 'n'
49-
je _newline ; Call new line
49+
call _newline ; Call new line
5050
cmp al, 0x30 ; If character is '0'
5151
je _done_printf ; Exits if was \0
5252

0 commit comments

Comments
 (0)