Changeset 26


Ignore:
Timestamp:
Apr 18, 2014, 8:10:14 AM (10 years ago)
Author:
Mattia Monga
Message:

Programmi 2014

Location:
trunk
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/Makefile

    r15 r26  
    11TARGET_ARCH=-m32
    22ASM=nasm
     3CFLAGS=-masm=intel -Wall
    34
    45mioboot: mioboot.asm
     
    1718esercizio: esercizio.o
    1819
    19 pthreads-pc : LDFLAGS=-lrt
     20pthreads-pc rw rw-nosync rw-mutex rw-rlotto: LDFLAGS=-lpthread
    2021
    2122pthreads-pc: pthreads-pc.c
     
    3334threads-tsl: threads-tsl.o enter.o
    3435
     36threads-tsl-new: threads-tsl-new.c
     37
     38%.tex : %.nw
     39        noweave -delay -filter btdefn -index -filter "awk -f lst.awk|tee debug" $< > $@
     40
     41%.c : %.nw
     42        notangle -R$@ -filter btdefn $< > $@
     43
     44%.pdf : %.tex
     45        pdflatex $< && pdflatex $< && pdflatex $<
    3546
    3647.PHONY: clean
  • trunk/enter.asm

    r2 r26  
    66        mov   ebx,[ebp+8]     ; first parameter to function
    77
     8
     9;; bts bitbase bitoffset
     10;; selects the bitoffset bit in bitbase,
     11;; stores the value in the CF flag, and sets the bit to 1
    812spin:   lock bts dword [ebx], 0
    913        jc spin
  • trunk/enter2.asm

    r2 r26  
    88       
    99       
    10 spin:   mov ecx, 0
     10spin:   push busy
     11        call printf
    1112        lock bts dword [ebx], 0
    12         jc save
    13 print:  push busy
    14         call printf
     13        jc spin
    1514
    16         cmp ecx, 1
    17         je spin
    18 
    19 save:   mov ecx, 1
    20         jmp print
    21        
    2215        leave                   ; mov esp,ebp / pop ebp
    2316        ret     
  • trunk/filefigli.c

    r24 r26  
    3434        }
    3535        lsofd("padre (senza figli)");
    36         if (write(f, string, (strlen(string)+1)) != (strlen(string)+1) ){
     36        if (write(f, string, (strlen(string))) != (strlen(string)) ){
    3737                perror("write");
    3838                exit(1);
  • trunk/forca.c

    r2 r26  
    66  int x = fork();
    77  if (x < 0){
    8       perror("Errore nella fork:");
    9       exit(1);
    10   } else {
    11     if (x != 0){
    12       while(1) printf("Processo padre (Figlio: %d)\n", x);
    13     } else {
    14       while(1) printf("Processo figlio (%d)\n", x);
    15     }
     8    perror("Errore nella fork:");
     9    exit(1);
     10  }
     11  if (x != 0){
     12    while(1) printf("Processo padre (x == %d)\n", x);
     13 
     14  else { // x == 0
     15   while(1) printf("Processo figlio (x == %d)\n", x);       
    1616  }
    1717  return 0;
    1818}
    19 
    20    
    21        
    22  
  • trunk/hello.c

    r6 r26  
     1/* Copyright (C) 2014 by Mattia Monga <mattia.monga@unimi.it> */
     2/* $Id$ */
     3
    14#include <stdio.h>
    2 #include <unistd.h>
    3 #include <stdlib.h>
    45
    5 int main(void){
    6   int i;
    7   for (i=0; i<10; i++){
    8     printf("Hello world! (%d)\n", i+1);
    9     sleep(1);
    10   }
    11   exit(0);
     6int main(){
     7    printf("Ciao %d %s", 5, "mamma");
     8    asm("mov eax, 0");
     9    return 0;
    1210}
     11
     12/* Local Variables: */
     13/* compile-command: "make -k " */
     14/* End: */
  • trunk/hello.s

    r24 r26  
    11        .file   "hello.c"
     2        .intel_syntax noprefix
    23        .section        .rodata
    34.LC0:
    4         .string "Hello world! (%d)\n"
     5        .string "mamma"
     6.LC1:
     7        .string "Ciao %d %s"
    58        .text
    69        .globl  main
     
    912.LFB0:
    1013        .cfi_startproc
    11         pushl   %ebp
     14        push    ebp
    1215        .cfi_def_cfa_offset 8
    1316        .cfi_offset 5, -8
    14         movl    %esp, %ebp
     17        mov     ebp, esp
    1518        .cfi_def_cfa_register 5
    16         andl    $-16, %esp
    17         subl    $32, %esp
    18         movl    $0, 28(%esp)
    19         jmp     .L2
    20 .L3:
    21         movl    28(%esp), %eax
    22         addl    $1, %eax
    23         movl    %eax, 4(%esp)
    24         movl    $.LC0, (%esp)
     19        and     esp, -16
     20        sub     esp, 16
     21        mov     DWORD PTR [esp+8], OFFSET FLAT:.LC0
     22        mov     DWORD PTR [esp+4], 5
     23        mov     DWORD PTR [esp], OFFSET FLAT:.LC1
    2524        call    printf
    26         movl    $1, (%esp)
    27         call    sleep
    28         addl    $1, 28(%esp)
    29 .L2:
    30         cmpl    $9, 28(%esp)
    31         jle     .L3
    32         movl    $0, (%esp)
    33         call    exit
     25#APP
     26# 8 "hello.c" 1
     27        mov eax, 0
     28# 0 "" 2
     29#NO_APP
     30        mov     eax, 0
     31        leave
     32        .cfi_restore 5
     33        .cfi_def_cfa 4, 4
     34        ret
    3435        .cfi_endproc
    3536.LFE0:
    3637        .size   main, .-main
    37         .ident  "GCC: (Debian 4.7.2-5) 4.7.2"
     38        .ident  "GCC: (Debian 4.8.2-18) 4.8.2"
    3839        .section        .note.GNU-stack,"",@progbits
  • trunk/mioboot-nobios-simple.asm

    r3 r26  
    1 ;Copyright (C) 2008-2011 by Mattia Monga <mattia.monga@unimi.it>
     1;Copyright (C) 2008, 2009 by Mattia Monga <mattia.monga@unimi.it>
    22bits 16                         ; 16 bit real mode
    33org 0x7C00                      ; origine indirizzo 0000:7C00
  • trunk/pthreads-pc.c

    r8 r26  
    1 /* Copyright (C) 2008 by Mattia Monga <mattia.monga@unimi.it> */
     1/* Copyright (C) 2008, 2014 by Mattia Monga <mattia.monga@unimi.it> */
    22/* $Id$ */
    33#include <pthread.h>
     
    1313  while (1){
    1414    char* o = (char*)malloc(sizeof(char));
    15     printf("Ho prodotto %x\n", o);
     15    printf("Ho prodotto %p\n", o);
    1616    b_insert(o);
    1717  }
     
    2525    b_remove(&o);
    2626    free(o);
    27     printf("Ho consumato %x\n", o);
     27    printf("Ho consumato %p\n", o);
    2828  }
    2929  return NULL;
     
    5656
    5757  while (count == N) pthread_cond_wait(&full, &lock);
     58  printf("Buffer a %d\n", count);
    5859  buffer[count++] = o;
    5960  if (count == 1) pthread_cond_signal(&empty);
     
    6869
    6970  while (count == 0) pthread_cond_wait(&empty, &lock);
     71  printf("Buffer a %d\n", count);
    7072  *result = buffer[--count];
    7173  if (count == N-1) pthread_cond_signal(&full);
  • trunk/syscall.asm

    r22 r26  
    11segment .text
    22        global main
    3         extern printf
    43
    5 main:   push msg
    6         call printf             ; chiamata di libreria
    7 
    8         mov ecx, msg            ; stringa
     4main:   mov ecx, msg            ; stringa
    95        mov edx, msg_size       ; dimensione stringa
    106        mov ebx, 1              ; file descriptor (stdout)
  • trunk/threads-peterson.c

    r15 r26  
    11/* Copyright (C) 2009 by Mattia Monga <mattia.monga@unimi.it> */
    22/* $Id$ */
    3 
     3#define _GNU_SOURCE
    44#include <unistd.h>
    55#include <stdio.h>
  • trunk/threads-shared.c

    r15 r26  
    11/* Copyright (C) 2009 by Mattia Monga <mattia.monga@unimi.it> */
    22/* $Id$ */
    3 
     3#define _GNU_SOURCE
    44#include <unistd.h>
    55#include <stdio.h>
  • trunk/threads-tsl.c

    r15 r26  
    11/* Copyright (C) 2009 by Mattia Monga <mattia.monga@unimi.it> */
    22/* $Id$ */
     3#define _GNU_SOURCE
    34
    45#include <unistd.h>
     
    1819                printf("Processo figlio (%d). s = %d\n",
    1920                       getpid(), shared[0]);
     21                fflush(stdout);
    2022                if (!(shared[0] < 10)){
    2123                        printf("Corsa critica!!!!\n");
     
    2527                leave_section(&shared[1]);
    2628                sched_yield();
     29                usleep(50);
    2730        }
    2831        leave_section(&shared[1]); // il test nel while \`e dopo enter\_section
     
    7174                       shared[2],
    7275                       shared[3]);
     76                fflush(stdout);
    7377        }
    7478        return 0;
Note: See TracChangeset for help on using the changeset viewer.