mirror of
https://github.com/cfenollosa/os-tutorial.git
synced 2025-12-17 04:14:37 +03:00
lessons 8, 9, 10, entering 32-bit mode
This commit is contained in:
26
08-32bit-print/32bit-print.asm
Normal file
26
08-32bit-print/32bit-print.asm
Normal file
@@ -0,0 +1,26 @@
|
||||
[bits 32] ; using 32-bit protected mode
|
||||
|
||||
; this is how constants are defined
|
||||
VIDEO_MEMORY equ 0xb8000
|
||||
WHITE_OB_BLACK equ 0x0f ; the color byte for each character
|
||||
|
||||
print_string_pm:
|
||||
pusha
|
||||
mov edx, VIDEO_MEMORY
|
||||
|
||||
print_string_pm_loop:
|
||||
mov al, [ebx] ; [ebx] is the address of our character
|
||||
mov ah, WHITE_OB_BLACK
|
||||
|
||||
cmp al, 0 ; check if end of string
|
||||
je print_string_pm_done
|
||||
|
||||
mov [edx], ax ; store character + attribute in video memory
|
||||
add ebx, 1 ; next char
|
||||
add edx, 2 ; next video memory position
|
||||
|
||||
jmp print_string_pm_loop
|
||||
|
||||
print_string_pm_done:
|
||||
popa
|
||||
ret
|
||||
29
08-32bit-print/README.md
Normal file
29
08-32bit-print/README.md
Normal file
@@ -0,0 +1,29 @@
|
||||
*Concepts you may want to Google beforehand: 32-bit protected mode, VGA, video
|
||||
memory*
|
||||
|
||||
**Goal: Print on the screen when on 32-bit protected mode**
|
||||
|
||||
32-bit mode allows us to use 32 bit registers and memory addressing
|
||||
, protected memory, virtual memory and other advangades, but we will lose
|
||||
BIOS interrupts and we'll need to code the GDT (more on this later)
|
||||
|
||||
In this lesson we will write a print string routine by directly manipulating
|
||||
the VGA video memory instead of calling `int 0x10`. The VGA memory starts
|
||||
at address `0xb8000` and it has a text mode which is useful to avoid
|
||||
manipulating direct pixels.
|
||||
|
||||
The formula for accessing a specific character on the 80x25 grid is:
|
||||
|
||||
`0xb8000 + 2 * (row * 80 + col)`
|
||||
|
||||
That is, every character uses 2 bytes (one for the ASCII, another for
|
||||
color and such), and we see that the structure of the memory concatenates
|
||||
rows.
|
||||
|
||||
Open `32bit-print.asm` to see the code. It will always print the string
|
||||
on the top left of the screen, but soon we'll write higher level routines
|
||||
to replace it.
|
||||
|
||||
Unfortunately we cannot yet call this routine from the bootloader, because
|
||||
we still don't know how to write the GDT and enter protected mode. Once
|
||||
you have understood the code, jump to the next lesson.
|
||||
Reference in New Issue
Block a user