Skip to content

Commit ee74011

Browse files
committed
session 08: Initial commit
1 parent 6f7d78a commit ee74011

19 files changed

+432
-0
lines changed

sesiune-08/code-sol/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/hello

sesiune-08/code-sol/Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CFLAGS = -Wall -g
2+
3+
.PHONY: all clean
4+
5+
all: hello
6+
7+
clean:
8+
-rm -f *~
9+
-rm -f *.o
10+
-rm -f hello

sesiune-08/code-sol/hello.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Sample C source code file
3+
*/
4+
5+
#include <stdio.h>
6+
7+
int main(void)
8+
{
9+
puts("Hello, World!");
10+
11+
return 0;
12+
}

sesiune-08/code/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/hello

sesiune-08/slides/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/texfiles
2+
/*.pdf
3+
/code/*.tex
4+
/code/highlight.sty

sesiune-08/slides/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
BASENAME = sesiune-08
2+
3+
include ../../metafiles/base.mk

sesiune-08/slides/code/Makefile

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
TEXFILES = inittraps.tex paging.tex interrupt.tex idle.tex skbuf.tex skbuff.tex create.tex rcv.tex sock.tex
2+
3+
ifeq (3, $(shell highlight --version | head -2 | tail -1 | rev | cut -d ' ' -f 1 | rev | cut -d '.' -f 1))
4+
HIGHLIGHT_OPTS = -O latex -l -f -t 8 -K tiny -S bash -c highlight.sty
5+
else
6+
HIGHLIGHT_OPTS = -L -l -f -t 8 -K tiny -S bash -c highlight.sty
7+
endif
8+
9+
all: $(TEXFILES)
10+
11+
create.tex: create.c
12+
highlight $(HIGHLIGHT_OPTS) -i $< -o $@
13+
14+
rcv.tex: rcv.c
15+
highlight $(HIGHLIGHT_OPTS) -i $< -o $@
16+
17+
sock.tex: sock.c
18+
highlight $(HIGHLIGHT_OPTS) -i $< -o $@
19+
20+
skbuff.tex: skbuff.c
21+
highlight $(HIGHLIGHT_OPTS) -i $< -o $@
22+
23+
skbuf.tex: skbuf.c
24+
highlight $(HIGHLIGHT_OPTS) -i $< -o $@
25+
26+
idle.tex: idle.c
27+
highlight $(HIGHLIGHT_OPTS) -i $< -o $@
28+
29+
interrupt.tex: interrupt.c
30+
highlight $(HIGHLIGHT_OPTS) -i $< -o $@
31+
32+
inittraps.tex: inittraps.c
33+
highlight $(HIGHLIGHT_OPTS) -i $< -o $@
34+
35+
paging.tex: paging.c
36+
highlight $(HIGHLIGHT_OPTS) -i $< -o $@
37+
38+
.PHONY: clean
39+
clean:
40+
rm -f $(TEXFILES) highlight.sty *~

sesiune-08/slides/code/create.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
static const struct net_proto_family my_family_ops = {
2+
.family = PF_MY,
3+
.create = my_create,
4+
.owner = THIS_MODULE,
5+
};
6+

sesiune-08/slides/code/highlight.css

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* Style definition file generated by highlight 3.9, http://www.andre-simon.de/ */
2+
3+
/* Highlighting theme: Kwrite Editor */
4+
5+
body.hl { background-color:#e0eaee; }
6+
pre.hl { color:#000000; background-color:#e0eaee; font-size:10pt; font-family:'Courier New';}
7+
.hl.num { color:#b07e00; }
8+
.hl.esc { color:#ff00ff; }
9+
.hl.str { color:#bf0303; }
10+
.hl.pps { color:#818100; }
11+
.hl.slc { color:#838183; font-style:italic; }
12+
.hl.com { color:#838183; font-style:italic; }
13+
.hl.ppc { color:#008200; }
14+
.hl.opt { color:#000000; }
15+
.hl.lin { color:#555555; }
16+
.hl.kwa { color:#000000; font-weight:bold; }
17+
.hl.kwb { color:#0057ae; }
18+
.hl.kwc { color:#000000; font-weight:bold; }
19+
.hl.kwd { color:#010181; }
20+

sesiune-08/slides/code/idle.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
void cpu_idle(void)
2+
{
3+
int cpu = smp_processor_id();
4+
5+
current_thread_info()->status |= TS_POLLING;
6+
7+
/* endless idle loop with no priority at all */
8+
while (1) {
9+
tick_nohz_stop_sched_tick();
10+
while (!need_resched()) {
11+
void (*idle)(void);
12+
13+
check_pgt_cache();
14+
rmb();
15+
idle = pm_idle;
16+
17+
if (rcu_pending(cpu))
18+
rcu_check_callbacks(cpu, 0);
19+
20+
if (!idle)
21+
idle = default_idle;
22+
23+
if (cpu_is_offline(cpu))
24+
play_dead();
25+
26+
__get_cpu_var(irq_stat).idle_timestamp = jiffies;
27+
idle();
28+
}
29+
tick_nohz_restart_sched_tick();
30+
preempt_enable_no_resched();
31+
schedule();
32+
preempt_disable();
33+
}
34+
}

sesiune-08/slides/code/inittraps.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
set_trap_gate(0,&divide_error);
2+
set_intr_gate(1,&debug);
3+
set_intr_gate(2,&nmi);
4+
set_system_intr_gate(3, &int3);
5+
set_system_gate(4,&overflow);
6+
set_trap_gate(5,&bounds);
7+
set_trap_gate(6,&invalid_op);
8+
set_trap_gate(7,&device_not_available);
9+
set_task_gate(8,GDT_ENTRY_DOUBLEFAULT_TSS);
10+
set_trap_gate(9,&coprocessor_segment_overrun);
11+
set_trap_gate(10,&invalid_TSS);
12+
set_trap_gate(11,&segment_not_present);
13+
set_trap_gate(12,&stack_segment);
14+
set_trap_gate(13,&general_protection);
15+
set_intr_gate(14,&page_fault);
16+
set_trap_gate(15,&spurious_interrupt_bug);
17+
set_trap_gate(16,&coprocessor_error);
18+
set_trap_gate(17,&alignment_check);

sesiune-08/slides/code/interrupt.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
void enable_8259A_irq(unsigned int irq)
2+
{
3+
unsigned int mask = ~(1 << irq);
4+
unsigned long flags;
5+
6+
spin_lock_irqsave(&i8259A_lock, flags);
7+
cached_irq_mask &= mask;
8+
if (irq & 8)
9+
outb(cached_slave_mask, PIC_SLAVE_IMR);
10+
else
11+
outb(cached_master_mask, PIC_MASTER_IMR);
12+
spin_unlock_irqrestore(&i8259A_lock, flags);
13+
}
14+
15+
int i8259A_irq_pending(unsigned int irq)
16+
{
17+
unsigned int mask = 1<<irq;
18+
unsigned long flags;
19+
int ret;
20+
21+
spin_lock_irqsave(&i8259A_lock, flags);
22+
if (irq < 8)
23+
ret = inb(PIC_MASTER_CMD) & mask;
24+
else
25+
ret = inb(PIC_SLAVE_CMD) & (mask >> 8);
26+
spin_unlock_irqrestore(&i8259A_lock, flags);
27+
28+
return ret;
29+
}

sesiune-08/slides/code/paging.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
* Enable paging
3+
*/
4+
5+
movl $pa(swapper_pg_dir),%eax
6+
/* set the page table pointer.. */
7+
movl %eax,%cr3
8+
movl %cr0,%eax
9+
orl $X86_CR0_PG,%eax
10+
/* ..and set paging (PG) bit */
11+
movl %eax,%cr0

sesiune-08/slides/code/rcv.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
static struct packet_type my_packet_type __read_mostly = {
2+
.type = __constant_htons(MY_ETH),
3+
.func = my_rcv,
4+
};
5+

sesiune-08/slides/code/skbuf.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
struct sk_buff {
2+
struct sk_buff *next;
3+
struct sk_buff *prev;
4+
5+
struct sock *sk;
6+
ktime_t tstamp;
7+
struct net_device *dev;
8+
char cb[48];
9+
10+
unsigned int len,
11+
data_len;
12+
__u16 mac_len,
13+
hdr_len;
14+
15+
void (*destructor)(struct sk_buff *skb);
16+
17+
sk_buff_data_t transport_header;
18+
sk_buff_data_t network_header;
19+
sk_buff_data_t mac_header;
20+
sk_buff_data_t tail;
21+
sk_buff_data_t end;
22+
23+
unsigned char *head,
24+
*data;
25+
unsigned int truesize;
26+
atomic_t users;

sesiune-08/slides/code/skbuff.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* reserve head room */
2+
void skb_reserve(struct sk_buff *skb, int len);
3+
/* add data to the end */
4+
unsigned char *skb_put(struct sk_buff *skb, unsigned int len);
5+
/* add data to the top */
6+
unsigned char *skb_push(struct sk_buff *skb, unsigned int len);
7+
/* discard data at the top */
8+
unsigned char *skb_pull(struct sk_buff *skb, unsigned int len);
9+
/* discard data at the end */
10+
unsigned char *skb_trim(struct sk_buff *skb, unsigned int len);

sesiune-08/slides/code/sock.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
static struct proto my_proto = {
2+
.name = MY_PROTO_NAME,
3+
.owner = THIS_MODULE,
4+
.obj_size = sizeof(struct my_sock),
5+
};
6+

sesiune-08/slides/code/user-stat.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
root@profus:~# id razvan.deaconescu
2+
uid=1059(razvan.deaconescu) gid=1010(prof) groups=1010(prof)
3+
root@profus:~# finger razvan.deaconescu
4+
Login: razvan.deaconescu Name: Razvan DEACONESCU
5+
Directory: /home/prof/razvan.deaconescu Shell: /bin/bash
6+
Last login Fri Oct 2 21:03 (EEST) on pts/1 from dhcp-227.cs.pub.ro
7+
Mail forwarded to | /usr/bin/procmail
8+
root@profus:~# w
9+
17:38:09 up 14 days, 4:01, 1 user, load average: 1.28, 2.28, 1.53
10+
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
11+
root pts/0 10.38.248.154 17:34 0.00s 0.03s 0.01s w
12+
root@profus:~# who
13+
root pts/0 Oct 8 17:34 (10.38.248.154)
14+
root@profus:~# last -3
15+
root pts/0 10.38.248.154 Thu Oct 8 17:34 still logged in
16+
elena.ap pts/0 89.36.46.156 Thu Oct 8 00:10 - 01:02 (00:51)
17+
emil.slu pts/1 82.76.28.29 Wed Oct 7 19:00 - 19:22 (00:22)
18+
koala:~# groups www-data
19+
www-data tracker projects

0 commit comments

Comments
 (0)