0

I want to make a text-os only with assembly. I created a simple bootloader, but now I don't know how to start my kernel. Can you please help me with any example (if it's possible with a practical example)?

The current code:

boot.asm

BITS 16
ORG 0x7C00

;+--------------------------------+
mov ax, 0x3 ; Set text video mode |
int 0x10    ;                     |
;+--------------------------------+

;+--------------+
mov ah, 0x02 ;  |
xor dl, dl   ;  |
xor dh, dh   ;  |
int 0x10     ;  |
;+--------------+

;+----------------+
mov ax, 0xb800 ;  |
mov es, ax     ;  |
;+----------------+

;+-------------------------------------------------------+
mov ah, 0x02     ; FG = Green - BG = Black               |
mov si, msg_1    ;                                       |
xor di, di       ; 'di' = 0                              |
loop:            ;                                       |
    lodsb        ; Carica si 'in' 'al' e incrementa 'si' |
    or al, al    ; Controlla se 'al' è uguale a zero     |
    jz continue  ; jz = 'jump if zero'                   |
    stosw        ; Store in Video Memory                 |
jmp loop         ;                                       |
;+-------------------------------------------------------+

continue:

;+--------------+
mov ah, 0x02 ;  |
mov dl, 37   ;  |
int 0x10     ;  |
;+--------------+

;+-------------------------+
finish: ;                  |
    cli ; Clear Interrupts |
    hlt ; Halt the CPU     |
;+-------------------------+

msg_1: db "Il SO e' stato caricato con successo!", 0

times 510 - ($ - $$) db 0
dw 0xAA55

Makefile

compile:
    nasm boot.asm -o boot.bin
run:
    qemu-system-x86_64 boot.bin
Michael Petch
  • 46,082
  • 8
  • 107
  • 198
  • Maybe related: [How to make the kernel for my bootloader?](https://stackoverflow.com/q/33603842) has an example and some good tips. – Peter Cordes Jul 07 '23 at 01:53
  • @PeterCordes It's too complicated, I don't know what is gdt, what are the .inc file and I want to do all in assembly, no C. I know I should do more theory, but Im only a 14 years boy and I can’t afford lessons and I have to learn everything online. Moreover, all the sites/videos that talk about osdev are in English and therefore I can not fully understand them because I am Italian. – Federico Occhiochiuso Jul 07 '23 at 10:13
  • You titled this "protected mode" and put "x86-64" in the title. If you want to change modes to something other than real mode, you need a GDT. https://wiki.osdev.org/GDT_Tutorial / https://wiki.osdev.org/Protected_Mode . x86 has a lot of complicated stuff for an OS to set up, especially with booting in 16-bit mode with BIOS functions and then having to change to a different mode. A simpler machine might be good for learning, like a MIPS simulator such as MARS (https://courses.missouristate.edu/KenVollmar/MARS/), or better RISC-V such as RARS (https://github.com/TheThirdOne/rars) – Peter Cordes Jul 07 '23 at 12:49
  • RARS gives you an all-in-one editor + assembler + simulator + debugger for a RISC-V system with system calls to print integers and stuff that you'd normally have to do yourself or with C library calls. Maybe that's too simple if you wanted to do some bare metal programming on real CPUs. I don't know about the availability of documentation or tutorials in Italian instead of English, but if you find x86 complicated and hard to understand, that's because it *is* more complicated that most other ISAs. A different one might be a good choice for a beginner. – Peter Cordes Jul 07 '23 at 12:57

0 Answers0