Sistemi Operativi - homes.di.unimi.ithomes.di.unimi.it › sisop › lucidi0809 › so09.pdf ·...

Post on 30-Jun-2020

2 views 0 download

transcript

SistemiOperativi

BruschiMartignoniMonga

La creazionedei processi inMINIX

GDT

Demo

1

Sistemi Operativi1

Mattia Monga

Dip. di Informatica e Comunicazione

Universit�a degli Studi di Milano, Italia

mattia.monga@unimi.it

a.a. 2008/09

1c 2009 M. Monga. Creative Commons Attribuzione-Condividi allo stesso modo 2.5 Italia License.

http://creativecommons.org/licenses/by-sa/2.5/it/. Immagini tratte da [?] e da Wikipedia.

SistemiOperativi

BruschiMartignoniMonga

La creazionedei processi inMINIX

GDT

Demo

254

Lezione XIII: La gestione delle interruzioni inMINIX

SistemiOperativi

BruschiMartignoniMonga

La creazionedei processi inMINIX

GDT

Demo

255

MINIX

SistemiOperativi

BruschiMartignoniMonga

La creazionedei processi inMINIX

GDT

Demo

256

Caricamento iniziale

SistemiOperativi

BruschiMartignoniMonga

La creazionedei processi inMINIX

GDT

Demo

257

Cosa c'�e nella boot image

SistemiOperativi

BruschiMartignoniMonga

La creazionedei processi inMINIX

GDT

Demo

258

Cosa c'�e nella memoria

SistemiOperativi

BruschiMartignoniMonga

La creazionedei processi inMINIX

GDT

Demo

259

Setup iniziale

Inzialmente le strutture dati pi�u importanti di cui occorre fare ilsetup sono

GDT il processore ne ha bisogno per risolvere gliindirizzi in modalit�a protetta

IDT il processore ne ha bisogno per rispondere alleinterruzioni (sincrone e asincrone)

SistemiOperativi

BruschiMartignoniMonga

La creazionedei processi inMINIX

GDT

Demo

260

GDT

SistemiOperativi

BruschiMartignoniMonga

La creazionedei processi inMINIX

GDT

Demo

261

Segment descriptor

Vedi par. 3.4.5 di \IntelManual 3A"

1 /� kernel/type.h �/2 struct segdesc s f /� segment descriptor for protected mode �/3 u16 t limit low;4 u16 t base low;5 u8 t base middle;6 u8 t access; /� jPjDLj1jXjEjRjAj �/7 u8 t granularity; /� jGjXj0jAjLIMTj �/8 u8 t base high;9 g;

1 /� kernel/protect.c �/2 struct segdesc s gdt[GDT SIZE];

SistemiOperativi

BruschiMartignoniMonga

La creazionedei processi inMINIX

GDT

Demo

262

Inizializzazione GDT

1 /� kernel/protect.c prot init() �/2 struct desctableptr s f3 char limit[sizeof(u16 t)];4 char base[sizeof(u32 t)];5 g �dtp;6 #de�ne vir2phys(vir) (kinfo.data base + (vir bytes) (vir))7

8 /� Build gdt and idt pointers in GDT where the BIOS expects them. �/9 dtp= (struct desctableptr s �) &gdt[GDT INDEX];

10 � (u16 t �) dtp�>limit = (sizeof gdt) � 1;11 � (u32 t �) dtp�>base = vir2phys(gdt);12

13 dtp= (struct desctableptr s �) &gdt[IDT INDEX];14 � (u16 t �) dtp�>limit = (sizeof idt) � 1;15 � (u32 t �) dtp�>base = vir2phys(idt);16

17 /� Build segment descriptors for tasks and interrupt handlers. �/18 init codeseg(&gdt[CS INDEX], kinfo.code base, kinfo.code size, INTR PRIVILEGE);19 init dataseg(&gdt[DS INDEX], kinfo.data base, kinfo.data size, INTR PRIVILEGE);20 init dataseg(&gdt[ES INDEX], 0L, 0, TASK PRIVILEGE);

SistemiOperativi

BruschiMartignoniMonga

La creazionedei processi inMINIX

GDT

Demo

263

Note

Vengono utilizzati 3 livelli di privilegio (su 4)INTR PRIVILEGE kernel modeTASK PRIVILEGE \driver" mode, permesso I/OUSER PRIVILEGE user mode

kinfo �e una struttura dati globale1 /� include/minix/type.h �/2 typedef unsigned long phys bytes;3 typedef unsigned int vir bytes;4 struct kinfo f5 phys bytes code base; /� base of kernel code �/6 phys bytes code size;7 phys bytes data base; /� base of kernel data �/8 phys bytes data size;9 vir bytes proc addr; /� virtual address of process table �/

10 phys bytes kmem base; /� kernel memory layout (/dev/kmem) �/11 phys bytes kmem size;12 phys bytes bootdev base;/� boot device from boot image (/dev/boot) �/13 phys bytes bootdev size;14 phys bytes ramdev base;/� boot device from boot image (/dev/boot) �/15 phys bytes ramdev size;16 phys bytes params base;/� parameters passed by boot monitor �/17 phys bytes params size;18 int nr procs; /� number of user processes �/19 int nr tasks; /� number of kernel tasks �/20 char release[6]; /� kernel release number �/21 char version[6]; /� kernel version number �/22 g;

SistemiOperativi

BruschiMartignoniMonga

La creazionedei processi inMINIX

GDT

Demo

264

Il kernel

1 ; mpx386.s2 MINIX: ; this is the entry point for the MINIX kernel3 jmp over ags ; skip over the next few bytes4 .data2 CLICK SHIFT ; for the monitor: memory granularity5 ags:6 .data2 0x01FD ; boot monitor ags:7 nop ; extra byte to sync up disassembler8 over ags:9 ; ........

10 call cstart ; cstart(cs, ds, mds, parmo�, parmlen)11 add esp, 5�412

13 ; Reload gdtr, idtr and the segment registers to global descriptor table set14 ; up by prot init() called by cstart.15

16 lgdt ( gdt+GDT SELECTOR)17 lidt ( gdt+IDT SELECTOR)18

19 jmpf CS SELECTOR:csinit20 csinit:

SistemiOperativi

BruschiMartignoniMonga

La creazionedei processi inMINIX

GDT

Demo

265

Setup del kernel

1 void cstart(cs, ds, mds, parmo�, parmsize)2 U16 t cs, ds;/� kernel code and data segment �/3 U16 t mds; /� monitor data segment �/4 U16 t parmo�, parmsize;/� boot parameters o�set and length �/5 f6 /� Perform system initializations prior to calling main(). Most settings are7 � determined with help of the environment strings passed by MINIX' loader.8 �/9 extern int etext, end;

10

11 /� Record where the kernel and the monitor are. �/12 kinfo.code base = seg2phys(cs); /� get the base addr of seg �/13 kinfo.code size = (phys bytes) &etext; /� size of code segment �/14 kinfo.data base = seg2phys(ds);15 kinfo.data size = (phys bytes) &end; /� size of data segment �/16

17 /� Initialize protected mode descriptors. �/18 prot init();

SistemiOperativi

BruschiMartignoniMonga

La creazionedei processi inMINIX

GDT

Demo

266

Boot parameters

Sono �ssati tramite il boot monitor

rootdev=904

ramimagedev=904

ramsize=0

processor=686

bus=at

video=vga

chrome=color

memory=800:92540,100000:3DF0000

label=AT

controller=c0

image=boot/image

bootdelay=3000

SistemiOperativi

BruschiMartignoniMonga

La creazionedei processi inMINIX

GDT

Demo

267

Seguire il usso con QEMU e GDB

1 Lanciare QEMU con l'opzione -s che attiva il debuggingesterno (via rete, porta TCP 1234)

2 Al momento del menu premere ESC per accedere al bootmonitor

3 Aumentare il boot delay con bootdelay = 5000 peravere il tempo di bloccare QEMU e attivare il boot

4 Accedere alla console di controllo di QEMU (Ctrl-Alt-2)e fare stop

5 Attivare GDB e speci�care il target esterno con target

remote localhost:12346 Comandi utili (stessa sintassi in GDB e QEMU console)

x/10i 0x800 disassembla 10 istruzioni all'indirizzo 0x800

b *0x807 mette un break point all'indirizzo 0x807

info registers visualizza il contenuto dei registrisi step instruction (solo GDB)