wiki:WikiStart

Version 5 (modified by lorenzo, 15 years ago) ( diff )

--

Laboratorio di Sistemi Operativi

TOC(noheading)

Lezione 1: Introduzione

Slide

Programmi

  • Accesso diretto alla macchina fisica mioboot-nobios-simple.asm
    bits 16                         ; 16 bit real mode
    org 0x7C00                      ; origine indirizzo 0000:7C00
    
    start:	
     mov ax, 0xb800	 ; text video memory
     mov ds, ax
     mov eax, 10
    write:
     cmp eax, 0
     jz end
     mov byte [eax], 'm'
     mov byte [eax+1], 0x0F    ; attrib = white on black
     sub eax, 2
     jmp write
    end:
     hlt
    
    times 510-($-$$) db 0 ; 0-padding 
    dw 0xAA55
    
    nasm -l mioboot-nobios-simple.lst -o mioboot-nobios-simple.img mioboot-nobios-simple.asm
    qemu mioboot-nobios-simple.img
    
  • Uso dei servizi del BIOS mioboot.asm
    bits 16                         ; 16 bit real mode
    org 0x7C00                      ; origine indirizzo 0000:7C00
            
    start:
            cld                     ; clears direction flag (index regs incremented)
            mov si, boot
            call message
    working:
            mov si, work
            call message
    
            call waitenter
            jmp working
    
    message:
            lodsb                   ; carica un byte da [DS:SI] in AL e inc SI
            cmp al, 0
            jz done
            mov ah, 0x0E            ; write char to screen in text mode
            mov bx, 0               ; BH page number BL foreground color
            int 0x10                ; write AL to screen (BIOS)
            jmp message
    done:   ret
    
    boot: db "Loading unuseful system...." , 10, 13, 0
    work: db "I've done my unuseful stuff!" , 10, 13, 0 
    cont: db "Hit ENTER to continue...", 10, 13, 0
    wow: db "Great! Hello world!" , 10, 13, 0
            
    waitenter: mov si, cont
               call message
               mov ah, 0
               int 0x16                ; Wait for keypress (BIOS)
               cmp al, 'm'
               jz egg
               cmp al, 'b'
               jz basic
               cmp al, 13
               jnz waitenter
               ret
    egg:       mov si, wow
               call message
               jmp waitenter
    basic:     int 0x18		; basic (BIOS)
               hlt
    
            times 510-($-$$) db 0
            dw 0xAA55
    
    nasm -l mioboot.lst -o mioboot.img mioboot.asm
    qemu mioboot.img
    
  • Programma che esegue il codice letto da standard input exec.c
    #include <stdio.h>
    
    int main() {
      unsigned char buf[1024];
      void (*ptr)();
      int n;
      unsigned int eax;
    
      n = read(0, buf, 1024);
      buf[n] = '\xc3';
    
      ptr = (void(*)()) buf;
      ptr();
    
      __asm__("mov %%eax, %0" : "=m"(eax));
    
      printf("EAX: %.8x\n", eax);
    
      return 0;
    }
    
    gcc -o exec exec.c
    echo -ne "\xB8\x11\x22\x33\x44" | ./exec
    echo -n "ciao" | ./exec
    ...
    

Lezione 2

Note: See TracWiki for help on using the wiki.