; startup.asm - This file is a part of NutsOS ; NutsOS ; Copyright (C) 2013 Free Software Foundation, Inc. ; NutsOS is free software; you can redistribute it and/or modify ; it under the terms of the GNU General Public License as published by ; the Free Software Foundation; either version 3 of the License, or ; (at your option) any later version. ; NutsOS is distributed in the hope that it will be useful, ; but WITHOUT ANY WARRANTY; without even the implied warranty of ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ; GNU General Public License for more details. ; You should have received a copy of the GNU General Public License along ; with NutsOS; If not, see . ; Valentin Verdier %define ARGS_SEG 0x100 %define KERN_LDR_SEG 0x07E0 %define ARGS_CURSOR_POSX_OFFSET 0 %define ARGS_CURSOR_POSY_OFFSET 1 %define ARGS_MEMMAP_ENTRY_COUNT_OFFSET 2 %define ARGS_MEMMAP_OFFSET 3 [BITS 16] [ORG 0] ; Par rapport au segment 0x07E0 startup: mov ax, KERN_LDR_SEG mov ds, ax mov es, ax mov fs, ax mov gs, ax mov ax, 0x500 mov ss, ax mov sp, 0xFF0 mov si, start_msg call print call build_args ; On passe en mode protégé cli lgdt [gdtreg] mov eax, cr0 or eax, 1 mov cr0, eax ; Segment 0x07E0 en mode réel = adresse physique 0x7E00 ; Le seconde partie du code de kernLdr est situé 512 octets plus loin ; On saute dans le seconde partie de kernLdr et en même temps on réinitialise le segment de code jmp 0x08:0x8000 build_args: push eax push ebx push ecx push edx push es push di mov ax, ARGS_SEG mov es, ax mov ah, 3 xor bh, bh int 0x10 ; On demande la position du curseur ; On passe la position du curseur en argument mov [es:ARGS_CURSOR_POSX_OFFSET], dl mov [es:ARGS_CURSOR_POSY_OFFSET], dh ; Memory map initialisation mov di, ARGS_MEMMAP_OFFSET mov eax, 0xE820 xor ebx, ebx mov ecx, 24 mov edx, 0x534D4150 int 0x15 jc error cmp eax, 0x534D4150 jne error cmp ebx, 0 je error xor bp, bp ; récupération des entrées de la Memory Map .loop: inc bp add di, 24 mov eax, 0xE820 mov ecx, 24 int 0x15 jc .end_loop cmp ebx, 0 jne .loop .end_loop: mov ax, bp mov [es:ARGS_MEMMAP_ENTRY_COUNT_OFFSET], al pop di pop es pop edx pop ecx pop ebx pop eax ret ; Fonction print ; Params : pointeur sur str -> ds:si print: push ax push bx .top: lodsb cmp al, 0 jz .end mov ah, 0x0E ; int 0x10 fonction 0x0E mov bx, 0x07 ; attribut du caractère int 0x10 jmp .top .end: pop bx pop ax ret error: mov si, error_msg call print .loop: hlt jmp .loop ; Variables ; ################################# ; kernLdrContext: ; - cursorX ; - cursorY ; - biosBootDisk ; - listSize ; - memStructureList start_msg: db "Starting NutsOS KernelLoader...", 13, 10, 0 error_msg: db "Fatal Error !", 0 gdt_reg: dw (gdt_end - gdt_start) ; taille de la gdt dd (KERN_LDR_SEG << 4) + gdt_start ; adresse de base dur 32 bits gdt_start: .null_seg: ; descripteur nul times 8 db 0 .code_seg: ; Segment de code [0x0 - 0xFFFFFFFF] dw 0xFFFF ; limite0_15 dw 0x0000 ; base0_15 db 0x00 ; base16_23 db 0x9A ; acces db 0xCF ; Flags, limite16_19 db 0x00 ; base24_31 .data_seg: ; Segment de données [0x0 - 0xFFFFFFFF] dw 0xFFFF ; limite0_15 dw 0x0000 ; base0_15 db 0x00 ; base16_23 db 0x92 ; acces db 0xCF ; Flags, limite16_19 db 0x00 ; base24_31 .stack_seg: ; Segment de pile [... - 0x9F000] dw 0x0000 ; limite0_15, (0x009F + intel vt-x = O_o bug) dw 0x0000 ; base0_15 db 0x00 ; base16_23 db 0x96 ; acces db 0xC0 ; Flags, limite16_19 db 0x00 ; base24_31 gdt_end: ; ################################# times 512-($-$$) db 144