aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorklaar36 <klas.arvidsson@liu.se>2017-03-20 17:59:45 +0100
committerklaar36 <klas.arvidsson@liu.se>2017-03-20 17:59:45 +0100
commitf9003d89b17c039ab903f622580e61925e137523 (patch)
treeb46ab4f9745c96a78685ca29b6a18ed2531205d6
parentd9ae213323d0a036b7f3594de6822413a4c312c6 (diff)
downloadpintos-rs-f9003d89b17c039ab903f622580e61925e137523.tar.gz
added given files for standalone labs
-rw-r--r--src/.gitignore1
-rw-r--r--src/Make.config2
-rw-r--r--src/TAGS1560
-rw-r--r--src/lib/kernel/list.c8
-rw-r--r--src/standalone/upg1/basics.c6
-rw-r--r--src/standalone/upg2/about-main.c6
-rw-r--r--src/standalone/upg3/fork-wait.c95
-rw-r--r--src/standalone/upg4/use-list.c42
-rw-r--r--src/standalone/upg5/pagedir.c8
-rw-r--r--src/standalone/upg5/pagedir.h42
-rw-r--r--src/standalone/upg5/thread.h16
-rw-r--r--src/standalone/upg5/verify_adr.c90
-rw-r--r--src/standalone/upg6/main.c124
-rw-r--r--src/standalone/upg6/map.c1
-rw-r--r--src/standalone/upg6/map.h1
-rw-r--r--src/standalone/upg7/debug.c27
-rw-r--r--src/standalone/upg8/setup-argv.c265
17 files changed, 732 insertions, 1562 deletions
diff --git a/src/.gitignore b/src/.gitignore
index e132bfe..2eb4924 100644
--- a/src/.gitignore
+++ b/src/.gitignore
@@ -1,6 +1,7 @@
*~
*.o
*.a
+a.out
\#*#
TAGS
diff --git a/src/Make.config b/src/Make.config
index aa7d572..69914d8 100644
--- a/src/Make.config
+++ b/src/Make.config
@@ -43,7 +43,7 @@ else
endif
# Compiler and assembler invocation.
-DEFINES =
+DEFINES = -DPINTOS
WARNINGS = -Wall -W -Wstrict-prototypes -Wmissing-prototypes -Wsystem-headers
# klaar36@ida 2015-03: -fno-omit-frame-pointer to get working backtrace
# klaar36@ida 2016-05: -ffreestanding to assert freestanding environment
diff --git a/src/TAGS b/src/TAGS
deleted file mode 100644
index 542e6f4..0000000
--- a/src/TAGS
+++ /dev/null
@@ -1,1560 +0,0 @@
-
-threads/flags.h,75
-#define THREADS_FLAGS_H2,24
-#define FLAG_MBS 5,72
-#define FLAG_IF 6,123
-
-threads/init.c,544
-size_t ram_pages;39,889
-uint32_t *base_page_dir;base_page_dir42,956
-static bool format_filesys;46,1031
-bool power_off_when_done 50,1116
-bool force_off_when_done 52,1192
-int thread_create_limit 54,1285
-int main 67,1575
-ram_init 137,2928
-paging_init 162,3880
-read_command_line 198,5011
-parse_options 233,5756
-run_task 272,6934
-run_actions 288,7274
- struct action 291,7322
- char *name;name293,7345
- int argc;294,7404
- void (*function)function295,7484
-usage 339,8544
-power_off 382,10288
-print_stats 417,11053
-
-threads/init.h,51
-#define THREADS_INIT_H2,23
-void power_off 20,438
-
-threads/interrupt.c,714
-#define INTR_CNT 14,309
-static uint64_t idt[idt20,575
-static intr_handler_func *intr_handlers[intr_handlers23,661
-static const char *intr_names[intr_names26,769
-static bool in_external_intr;35,1205
-static bool yield_on_return;36,1284
-intr_get_level 52,1848
-intr_set_level 68,2328
-intr_enable 75,2519
-intr_disable 91,2903
-intr_init 105,3236
-register_handler 152,4930
-intr_register_ext 168,5490
-intr_register_int 189,6387
-intr_context 199,6723
-intr_yield_on_return 209,6976
-pic_init 232,7856
-pic_end_of_interrupt 259,8799
-make_gate 288,9875
-make_intr_gate 311,10633
-make_trap_gate 319,10815
-make_idtr_operand 327,11050
-intr_handler 339,11409
-intr_dump_frame 392,12850
-intr_name 416,13788
-
-threads/interrupt.h,710
-#define THREADS_INTERRUPT_H2,28
-enum intr_level 8,127
- INTR_OFF,10,148
- INTR_ON 11,201
-struct intr_frame20,452
- uint32_t edi;24,579
- uint32_t esi;25,628
- uint32_t ebp;26,677
- uint32_t esp_dummy;27,726
- uint32_t ebx;28,774
- uint32_t edx;29,823
- uint32_t ecx;30,872
- uint32_t eax;31,921
- uint16_t gs,32,970
- uint16_t fs,33,1035
- uint16_t es,34,1100
- uint16_t ds,35,1165
- uint32_t vec_no;38,1280
- uint32_t error_code;43,1506
- void *frame_pointer;frame_pointer47,1668
- void (*eip)eip51,1820
- uint16_t cs,52,1887
- uint32_t eflags;53,1947
- void *esp;esp54,2002
- uint16_t ss,55,2061
-typedef void intr_handler_func 58,2127
-
-threads/intr-stubs.S,199
-.func 18,535
-intr_entry:intr_entry19,552
-.globl 36,916
-.globl 49,1250
-.func 50,1267
-intr_exit:intr_exit51,1283
-.globl 94,2432
-intr_stubs:intr_stubs95,2450
-.globl 114,3176
-.func 115,3226
-
-threads/intr-stubs.h,70
-#define THREADS_INTR_STUBS_H2,29
-typedef void intr_stub_func 13,423
-
-threads/io.h,204
-#define THREADS_IO_H42,1987
-inb 49,2114
-insb 60,2381
-inw 71,2691
-insw 82,2977
-inl 93,3287
-insl 104,3569
-outb 115,3864
-outsb 124,4095
-outw 135,4395
-outsw 144,4649
-outl 155,4949
-outsl 164,5195
-
-threads/loader.S,247
-.globl 60,2723
-start:start61,2736
-read_sector:read_sector236,7150
-gdt:gdt304,8114
-gdtdesc:gdtdesc309,8239
-panic:panic316,8406
-panic_message:panic_message326,8574
-ram_pgs:ram_pgs333,8755
-arg_cnt:arg_cnt340,8990
-args:args343,9040
-
-threads/loader.h,481
-#define THREADS_LOADER_H2,25
-#define LOADER_BASE 5,89
-#define LOADER_END 6,162
-#define LOADER_KERN_BASE 9,275
-#define LOADER_PHYS_BASE 18,611
-#define LOADER_SIG 21,707
-#define LOADER_ARGS 22,787
-#define LOADER_ARG_CNT 23,867
-#define LOADER_RAM_PGS 24,947
-#define LOADER_SIG_LEN 27,1067
-#define LOADER_ARGS_LEN 28,1092
-#define LOADER_ARG_CNT_LEN 29,1120
-#define LOADER_RAM_PGS_LEN 30,1149
-#define SEL_NULL 34,1267
-#define SEL_KCSEG 35,1320
-#define SEL_KDSEG 36,1380
-
-threads/malloc.c,589
-struct desc38,1402
- size_t block_size;40,1418
- size_t blocks_per_arena;41,1487
- struct list free_list;42,1555
- struct lock lock;43,1614
-#define ARENA_MAGIC 47,1715
-struct arena 50,1760
- unsigned magic;52,1778
- struct desc *desc;desc53,1843
- size_t free_cnt;54,1920
-struct block 58,2015
- struct list_elem free_elem;60,2033
-static struct desc descs[descs64,2126
-static size_t desc_cnt;65,2177
-malloc_init 72,2409
-malloc 90,2927
-calloc 159,4751
-block_size 179,5115
-realloc 195,5625
-free 219,6220
-block_to_arena 268,7469
-arena_to_block 286,7945
-
-threads/malloc.h,84
-#define THREADS_MALLOC_H2,25
-void *malloc malloc8,116
-void *calloc calloc9,164
-
-threads/palloc.c,446
-struct pool30,966
- struct lock lock;32,982
- struct bitmap *used_map;used_map33,1046
- uint8_t *base;base34,1114
-struct pool kernel_pool,38,1238
-struct pool kernel_pool, user_pool;38,1238
-size_t user_page_limit 41,1326
-size_t free_page_limit 42,1361
-palloc_init 50,1625
-palloc_get_multiple 85,2799
-palloc_get_page 125,3840
-palloc_free_multiple 132,3984
-palloc_free_page 160,4611
-init_pool 168,4800
-page_from_pool 189,5510
-
-threads/palloc.h,118
-#define THREADS_PALLOC_H2,25
-enum palloc_flags7,101
- PAL_ASSERT 9,123
- PAL_ZERO 10,179
- PAL_USER 11,237
-
-threads/pte.h,714
-#define THREADS_PTE_H2,22
-#define PTSHIFT 21,612
-#define PTBITS 22,675
-#define PTSPAN 23,751
-#define PTMASK 24,831
-#define PDSHIFT 27,947
-#define PDBITS 28,1022
-#define PDMASK 29,1096
-static inline unsigned pt_no 32,1230
-static inline uintptr_t pd_no 37,1387
-#define PTE_FLAGS 61,2329
-#define PTE_ADDR 62,2378
-#define PTE_AVL 63,2430
-#define PTE_P 64,2495
-#define PTE_W 65,2559
-#define PTE_U 66,2624
-#define PTE_A 67,2692
-#define PTE_D 68,2759
-static inline uint32_t pde_create 71,2882
-static inline uint32_t *pde_get_pt pde_get_pt78,3118
-static inline uint32_t pte_create_kernel 87,3419
-static inline uint32_t pte_create_user 96,3765
-static inline void *pte_get_page pte_get_page102,3966
-
-threads/start.S,64
-.section 7,329
-.globl 9,347
-.func 10,360
-start:start12,386
-
-threads/switch.S,165
-.globl 15,605
-.func 16,627
-switch_threads:switch_threads17,648
-.globl 32,1045
-.globl 51,1424
-.func 52,1444
-switch_entry:switch_entry53,1463
-.globl 59,1573
-
-threads/switch.h,379
-#define THREADS_SWITCH_H2,25
-struct switch_threads_frame 6,110
- uint32_t edi;8,143
- uint32_t esi;9,197
- uint32_t ebp;10,251
- uint32_t ebx;11,305
- void (*eip)eip12,359
- struct thread *cur;cur13,417
- struct thread *next;next14,492
-struct switch_entry_frame23,838
- void (*eip)eip25,868
-#define SWITCH_CUR 36,1080
-#define SWITCH_NEXT 37,1107
-
-threads/synch.c,458
-sema_init 45,1674
-sema_down 61,2174
-sema_try_down 84,2728
-sema_up 109,3226
-sema_self_test 129,3751
-sema_test_helper 148,4152
-lock_init 176,5133
-lock_acquire 193,5598
-lock_try_acquire 210,6043
-lock_release 229,6496
-lock_held_by_current_thread 242,6817
-struct semaphore_elem 250,6979
- struct list_elem elem;252,7006
- struct semaphore semaphore;253,7066
-cond_init 260,7317
-cond_wait 288,8337
-cond_signal 312,9056
-cond_broadcast 331,9693
-
-threads/synch.h,294
-#define THREADS_SYNCH_H2,24
-struct semaphore 8,117
- unsigned value;10,139
- struct list waiters;11,192
-struct lock 21,468
- struct thread *holder;holder23,485
- struct semaphore semaphore;24,560
-struct condition 34,865
- struct list waiters;36,887
-#define barrier(49,1341
-
-threads/thread.c,1664
-#define THREAD_MAGIC 21,529
-static struct list ready_list;25,679
-static struct thread *idle_thread;idle_thread28,730
-static struct thread *initial_thread;initial_thread31,822
-static struct lock tid_lock;34,896
-struct kernel_thread_frame 37,965
- void *eip;eip39,997
- thread_func *function;function40,1051
- void *aux;aux41,1107
-static long long idle_ticks;45,1198
-static long long kernel_ticks;46,1265
-static long long user_ticks;47,1339
-#define TIME_SLICE 50,1431
-static unsigned thread_ticks;51,1507
-bool thread_mlfqs;56,1744
-static bool is_thread 64,2025
-init_thread 104,3280
-thread_start 131,4018
-thread_tick 148,4481
-thread_print_stats 169,4846
-thread_create 191,5806
-thread_block 249,7342
-thread_unblock 267,7881
-thread_name 282,8208
-thread_current 291,8436
-thread_tid 308,8896
-thread_exit 316,9045
-thread_yield 336,9534
-thread_set_priority 353,9906
-thread_get_priority 360,10046
-thread_set_nice 367,10174
-thread_get_nice 374,10294
-thread_get_load_avg 382,10417
-thread_get_recent_cpu 390,10558
-idle 406,11132
-kernel_thread 436,12056
-running_thread 447,12391
-is_thread 461,12835
-alloc_frame 469,13042
-next_thread_to_run 485,13557
-schedule_tail 510,14444
-schedule 547,15498
-allocate_tid 564,15895
-uint32_t thread_stack_ofs 578,16170
-static unsigned DEBUG_thread_alive_count;584,16288
-static struct lock DEBUG_thread_alive_lock;585,16330
-static struct condition DEBUG_thread_alive_cond;586,16374
-void DEBUG_thread_init(588,16424
-void DEBUG_thread_count_up(595,16593
-void DEBUG_thread_count_down(603,16822
-void DEBUG_thread_poweroff_check(612,17122
-bool DEBUG_thread_create_simulate_fail(641,18006
-
-threads/thread.h,682
-#define THREADS_THREAD_H2,25
-enum thread_status11,177
- THREAD_RUNNING,13,200
- THREAD_READY,14,246
- THREAD_BLOCKED,15,306
- THREAD_DYING 16,369
-typedef int tid_t;21,510
-#define TID_ERROR 22,529
-#define PRI_MIN 25,624
-#define PRI_DEFAULT 26,687
-#define PRI_MAX 27,751
-struct thread85,3506
- tid_t tid;88,3553
- enum thread_status status;89,3618
- char name[name90,3678
- uint8_t *stack;stack91,3755
- int priority;92,3822
- struct list_elem elem;95,3926
- struct map file_map;100,4147
- int pid;103,4194
- uint32_t *pagedir;pagedir109,4341
- unsigned magic;113,4440
-typedef void thread_func 127,4816
-void thread_exit 137,5094
-
-threads/vaddr.h,434
-#define THREADS_VADDR_H2,24
-#define BITMASK(15,288
-#define PGSHIFT 18,382
-#define PGBITS 19,458
-#define PGSIZE 20,530
-#define PGMASK 21,596
-static inline unsigned pg_ofs 24,699
-static inline uintptr_t pg_no 29,812
-static inline void *pg_round_up pg_round_up34,940
-static inline void *pg_round_down pg_round_down39,1098
-#define PHYS_BASE 53,1700
-is_user_vaddr 57,1821
-is_kernel_vaddr 64,1965
-ptov 72,2140
-vtop 82,2354
-
-threads/boundedbuffer.h,79
-#define BOUNDEDBUFFER_H9,206
-struct bounded_buffer 13,259
- int size;14,283
-
-threads/boundedbuffer.c,87
-void bb_init(15,448
-void bb_destroy(21,550
-int bb_read(26,631
-void bb_write(32,720
-
-threads/synchlist.c,105
-void sl_init(29,978
-void sl_destroy(42,1337
-void sl_append(63,1944
-void *sl_remove(sl_remove83,2646
-
-threads/copyright.h,42
-static char *copyright copyright23,1095
-
-threads/synchlist.h,204
-struct SynchList 24,773
- struct list sl_list;25,792
- struct lock sl_lock;26,815
- struct condition sl_empty;27,838
-struct SL_element30,871
- struct list_elem elem;32,891
- void *item;item33,916
-
-userprog/exception.c,128
-static long long page_fault_cnt;9,198
-exception_init 30,941
-exception_print_stats 65,2677
-kill 72,2852
-page_fault 123,4966
-
-userprog/exception.h,94
-#define USERPROG_EXCEPTION_H2,29
-#define PF_P 5,135
-#define PF_W 6,210
-#define PF_U 7,255
-
-userprog/gdt.c,324
-static uint64_t gdt[gdt25,919
-gdt_init 36,1294
-enum seg_class57,2025
- CLS_SYSTEM 59,2044
- CLS_CODE_DATA 60,2098
-enum seg_granularity64,2211
- GRAN_BYTE 66,2236
- GRAN_PAGE 67,2304
-make_seg_desc 82,2985
-make_code_desc 116,4233
-make_data_desc 124,4461
-make_tss_desc 134,4807
-make_gdtr_operand 143,5052
-
-userprog/gdt.h,126
-#define USERPROG_GDT_H2,23
-#define SEL_UCSEG 8,158
-#define SEL_UDSEG 9,216
-#define SEL_TSS 10,274
-#define SEL_CNT 11,332
-
-userprog/pagedir.c,342
-pagedir_create 17,470
-pagedir_destroy 28,686
-lookup_page 57,1502
-pagedir_set_page 99,2588
-pagedir_get_page 126,3285
-pagedir_clear_page 144,3755
-pagedir_is_dirty 164,4238
-pagedir_set_dirty 173,4472
-pagedir_is_accessed 193,4999
-pagedir_set_accessed 202,5243
-pagedir_activate 220,5632
-active_pd 235,6137
-invalidate_pagedir 255,6846
-
-userprog/pagedir.h,32
-#define USERPROG_PAGEDIR_H2,27
-
-userprog/process.c,919
-#define HACK25,751
-static void wrap_file_close(32,908
-static struct plist process_list;39,1013
-static bool register_exit(41,1048
-static bool register_child_exit(50,1216
-static bool print_process(57,1372
-void process_init(69,1667
-void process_exit(74,1725
-void process_print_list(82,1927
-void process_init(93,2278
-void process_exit(102,2633
-void process_print_list(108,2806
-struct parameters_to_start_process119,3101
- char* command_line;121,3138
- struct semaphore load_done;124,3247
- bool load_success;125,3277
- int parent_pid;128,3321
- int child_pid;129,3339
-start_process(135,3450
-start_process 316,10897
-process_wait 447,15536
-process_cleanup 489,16903
-process_activate 568,19483
-struct main_args585,19913
- void (*ret)ret587,19932
- int argc;588,19953
- char** argv;589,19965
-static bool exists_in(594,20039
-static int count_args(606,20320
-static void* setup_main_stack(623,20660
-
-userprog/process.h,88
-#define USERPROG_PROCESS_H2,27
-#define INFINITE_WAIT(15,345
-#define BUSY_WAIT(16,396
-
-userprog/syscall.c,317
-syscall_init 20,466
-static bool is_done_buf(29,703
-static bool is_done_str(34,798
-static bool verify(46,1007
-static void verify_buf(67,1456
-static void verify_str(79,1813
-static int getline(98,2338
-static int getbuf(125,2738
-#define SYS_DEBUG(143,3080
-const int argc[argc155,3545
-syscall_handler 165,3715
-
-userprog/syscall.h,32
-#define USERPROG_SYSCALL_H2,27
-
-userprog/tss.c,899
-struct tss51,2307
- uint16_t back_link,53,2322
- void *esp0;esp054,2351
- uint16_t ss0,55,2427
- void *esp1;esp156,2504
- uint16_t ss1,57,2520
- void *esp2;esp258,2543
- uint16_t ss2,59,2559
- uint32_t cr3;60,2582
- void (*eip)eip61,2600
- uint32_t eflags;62,2624
- uint32_t eax,63,2645
- uint32_t eax, ecx,63,2645
- uint32_t eax, ecx, edx,63,2645
- uint32_t eax, ecx, edx, ebx;63,2645
- uint32_t esp,64,2678
- uint32_t esp, ebp,64,2678
- uint32_t esp, ebp, esi,64,2678
- uint32_t esp, ebp, esi, edi;64,2678
- uint16_t es,65,2711
- uint16_t cs,66,2733
- uint16_t ss,67,2755
- uint16_t ds,68,2777
- uint16_t fs,69,2799
- uint16_t gs,70,2821
- uint16_t ldt,71,2843
- uint16_t trace,72,2866
- uint16_t trace, bitmap;72,2866
-static struct tss *tss;tss76,2918
-tss_init 80,2982
-tss_get 93,3321
-tss_update 102,3476
-
-userprog/tss.h,28
-#define USERPROG_TSS_H2,23
-
-userprog/flist.c,152
-void map_init(7,151
-int map_insert(19,380
-OBJECT* map_find(36,669
-OBJECT* map_remove(48,922
-void map_for_each(60,1145
-void map_make_empty(73,1395
-
-userprog/flist.h,119
-#define _MAP_H_2,16
-#define OBJECT 37,1324
-#define MAP_SIZE 39,1352
-struct map41,1373
- OBJECT* data[data43,1386
-
-userprog/test.c,79
-typedef __SIZE_TYPE__ size_t;3,20
-strlcpy_first_word 10,208
-int main(34,597
-
-userprog/plist.h,336
-#define _PLIST_H_2,18
-struct process35,1211
- struct lock mutex;37,1228
- struct semaphore wait_for_me;38,1249
- int share_count;39,1281
- int exit_status;40,1300
- int parent_pid;41,1319
- char name[name42,1337
-#define PLIST_SIZE 45,1358
-struct plist47,1381
- struct lock mutex;49,1396
- struct process* data[data50,1417
-
-userprog/load.c,1503
-typedef uint32_t Elf32_Word,19,564
-typedef uint32_t Elf32_Word, Elf32_Addr,19,564
-typedef uint32_t Elf32_Word, Elf32_Addr, Elf32_Off;19,564
-typedef uint16_t Elf32_Half;20,616
-#define PE32Wx 23,688
-#define PE32Ax 24,751
-#define PE32Ox 25,814
-#define PE32Hx 26,876
-struct Elf32_Ehdr30,1045
- unsigned char e_ident[e_ident32,1067
- Elf32_Half e_type;33,1098
- Elf32_Half e_machine;34,1124
- Elf32_Word e_version;35,1153
- Elf32_Addr e_entry;36,1182
- Elf32_Off e_phoff;37,1209
- Elf32_Off e_shoff;38,1236
- Elf32_Word e_flags;39,1263
- Elf32_Half e_ehsize;40,1290
- Elf32_Half e_phentsize;41,1318
- Elf32_Half e_phnum;42,1349
- Elf32_Half e_shentsize;43,1376
- Elf32_Half e_shnum;44,1407
- Elf32_Half e_shstrndx;45,1434
-struct Elf32_Phdr51,1600
- Elf32_Word p_type;53,1622
- Elf32_Off p_offset;54,1645
- Elf32_Addr p_vaddr;55,1670
- Elf32_Addr p_paddr;56,1694
- Elf32_Word p_filesz;57,1718
- Elf32_Word p_memsz;58,1743
- Elf32_Word p_flags;59,1767
- Elf32_Word p_align;60,1791
-#define PT_NULL 64,1863
-#define PT_LOAD 65,1909
-#define PT_DYNAMIC 66,1965
-#define PT_INTERP 67,2025
-#define PT_NOTE 68,2087
-#define PT_SHLIB 69,2141
-#define PT_PHDR 70,2189
-#define PT_STACK 71,2249
-#define PF_X 74,2353
-#define PF_W 75,2395
-#define PF_R 76,2435
-load 89,2986
-validate_segment 207,6304
-load_segment 264,8144
-setup_stack 311,9566
-install_page 338,10343
-void dump_stack(351,10809
-
-userprog/plist.c,181
-void plist_init(9,205
-int plist_insert(22,464
-struct process* plist_find(42,852
-struct process* plist_remove(54,1119
-void plist_for_each(66,1364
-void plist_make_empty(88,1939
-
-userprog/load.h,29
-#define USERPROG_LOAD_H2,24
-
-filesys/directory.c,414
-struct dir 10,192
- struct inode *inode;inode12,208
- off_t pos;13,269
-struct dir_entry 17,371
- disk_sector_t inode_sector;19,393
- char name[name20,464
- bool in_use;21,537
-dir_create 27,740
-dir_open 35,1009
-dir_open_root 55,1411
-dir_reopen 63,1605
-dir_close 70,1743
-dir_get_inode 81,1918
-lookup 92,2260
-dir_lookup 119,2960
-dir_add 142,3531
-dir_remove 188,4903
-dir_readdir 228,5849
-
-filesys/directory.h,58
-#define FILESYS_DIRECTORY_H2,28
-#define NAME_MAX 12,347
-
-filesys/file.c,389
-struct file 7,121
- struct inode *inode;inode9,138
- off_t pos;10,190
- bool deny_write;12,322
-file_open 20,660
-file_reopen 42,1149
-file_close 49,1260
-file_get_inode 61,1524
-file_read 72,1844
-file_read_at 85,2275
-file_write 98,2769
-file_write_at 113,3311
-file_deny_write 123,3674
-file_allow_write 137,4001
-file_length 150,4300
-file_seek 159,4493
-file_tell 169,4713
-
-filesys/file.h,28
-#define FILESYS_FILE_H2,23
-
-filesys/filesys.c,335
-struct disk *filesys_disk;filesys_disk13,301
-struct lock filesys_lock;27,744
-#define fat_lock_init(31,804
-#define fat_lock_acquire(32,831
-#define fat_lock_release(33,861
-filesys_init 40,1089
-filesys_done 60,1598
-filesys_create 70,1849
-filesys_open 95,2842
-filesys_close 115,3426
-filesys_remove 129,3983
-do_format 144,4525
-
-filesys/filesys.h,93
-#define FILESYS_FILESYS_H2,26
-#define FREE_MAP_SECTOR 8,139
-#define ROOT_DIR_SECTOR 9,205
-
-filesys/free-map.c,475
-static struct file *free_map_file;free_map_file8,152
-static struct bitmap *free_map;free_map9,210
-struct lock free_map_lock;14,402
-#define ref_lock_init(15,429
-#define ref_lock_acquire(16,474
-#define ref_lock_release(17,522
-#define ref_lock_init(19,576
-#define ref_lock_acquire(20,603
-#define ref_lock_release(21,633
-free_map_init 27,779
-free_map_allocate 43,1301
-free_map_release 67,2026
-free_map_open 76,2285
-free_map_close 87,2586
-free_map_create 95,2725
-
-filesys/free-map.h,32
-#define FILESYS_FREE_MAP_H2,27
-
-filesys/fsutil.c,97
-fsutil_ls 16,347
-fsutil_cat 33,742
-fsutil_rm 60,1312
-fsutil_put 82,2055
-fsutil_get 147,3971
-
-filesys/fsutil.h,30
-#define FILESYS_FSUTIL_H2,25
-
-filesys/inode.c,1196
-struct lock inode_list_lock;13,304
-#define ref_lock_init(14,333
-#define ref_lock_acquire(15,378
-#define ref_lock_release(16,426
-#define ref_lock_init(18,480
-#define ref_lock_acquire(19,507
-#define ref_lock_release(20,537
-#define INODE_MAGIC 25,673
-struct inode_disk29,774
- disk_sector_t start;31,796
- off_t length;32,861
- unsigned magic;33,927
- uint32_t unused[unused34,987
-bytes_to_sectors 40,1151
-struct inode 46,1257
- struct list_elem elem;48,1275
- disk_sector_t sector;49,1344
- int open_cnt;50,1422
- bool removed;51,1487
- int deny_write_cnt;53,1643
- struct inode_disk data;56,1867
- struct lock dir_lock;59,2000
- struct lock lock;60,2072
- struct semaphore busy;61,2149
- int reader_count;62,2176
-void inode_dir_lock_acquire(67,2346
-void inode_dir_lock_release(74,2456
-byte_to_sector 87,2809
-static struct list open_inodes;98,3104
-inode_init 102,3178
-inode_create 114,3497
-inode_open 153,4645
-inode_reopen 202,6008
-inode_get_inumber 215,6272
-inode_close 224,6512
-inode_remove 260,7537
-inode_read_at 270,7834
-inode_write_at 358,10891
-inode_length 430,13716
-inode_deny_write 455,14530
-inode_allow_write 465,14815
-
-filesys/inode.h,29
-#define FILESYS_INODE_H2,24
-
-filesys/off_t.h,80
-#define FILESYS_OFF_T_H2,24
-typedef int32_t off_t;9,199
-#define PROTd 13,307
-
-devices/disk.c,1649
-#define reg_data(15,365
-#define reg_error(16,433
-#define reg_nsect(17,502
-#define reg_lbal(18,578
-#define reg_lbam(19,649
-#define reg_lbah(20,721
-#define reg_device(21,794
-#define reg_status(22,874
-#define reg_command(23,950
-#define reg_ctl(28,1184
-#define reg_alt_status(29,1261
-#define STA_BSY 32,1380
-#define STA_DRDY 33,1424
-#define STA_DRQ 34,1476
-#define CTL_SRST 37,1558
-#define DEV_MBS 40,1641
-#define DEV_LBA 41,1692
-#define DEV_DEV 42,1755
-#define CMD_IDENTIFY_DEVICE 47,1914
-#define CMD_READ_SECTOR_RETRY 48,1977
-#define CMD_WRITE_SECTOR_RETRY 49,2049
-struct disk 52,2144
- char name[name54,2161
- struct channel *channel;channel55,2219
- int dev_no;56,2277
- bool is_ata;58,2351
- disk_sector_t capacity;59,2419
- long long read_cnt;61,2491
- long long write_cnt;62,2553
-struct channel 67,2708
- char name[name69,2728
- uint16_t reg_base;70,2784
- uint8_t irq;71,2837
- struct lock lock;73,2894
- bool expecting_interrupt;74,2971
- struct semaphore completion_wait;76,3120
- struct disk devices[devices78,3194
-#define CHANNEL_CNT 82,3338
-static struct channel channels[channels83,3360
-disk_init 103,4107
-disk_print_stats 164,5659
-disk_get 192,6377
-disk_size 208,6714
-disk_read 220,6993
-disk_write 245,7717
-reset_channel 271,8402
-check_device_type 336,10046
-identify_ata_device 366,10818
-print_ata_string 411,12327
-select_sector 432,12813
-issue_pio_command 451,13337
-input_sector 464,13752
-output_sector 472,13979
-wait_until_idle 485,14355
-wait_while_busy 504,14805
-select_device 528,15329
-select_device_wait 542,15681
-interrupt_handler 551,15838
-
-devices/disk.h,122
-#define DEVICES_DISK_H2,23
-#define DISK_SECTOR_SIZE 8,128
-typedef uint32_t disk_sector_t;12,239
-#define PRDSNu 16,357
-
-devices/input.c,109
-static struct intq buffer;7,154
-input_init 11,223
-input_putc 19,372
-input_getc 31,638
-input_full 48,934
-
-devices/input.h,29
-#define DEVICES_INPUT_H2,24
-
-devices/intq.c,137
-intq_init 11,264
-intq_empty 20,439
-intq_full 28,605
-intq_getc 39,902
-intq_putc 63,1426
-next 81,1825
-wait 89,2008
-signal 105,2520
-
-devices/intq.h,270
-#define DEVICES_INTQ_H2,23
-#define INTQ_BUFSIZE 21,692
-struct intq24,750
- struct lock lock;27,793
- struct thread *not_full;not_full28,865
- struct thread *not_empty;not_empty29,942
- uint8_t buf[buf32,1038
- int head;33,1084
- int tail;34,1148
-
-devices/kbd.c,859
-#define DATA_REG 11,220
-static bool left_shift,15,317
-static bool left_shift, right_shift;15,317
-static bool left_alt,16,390
-static bool left_alt, right_alt;16,390
-static bool left_ctrl,17,461
-static bool left_ctrl, right_ctrl;17,461
-static bool caps_lock;21,593
-static int64_t key_cnt;24,647
-static intr_handler_func keyboard_interrupt;26,672
-kbd_init 30,755
-kbd_print_stats 37,881
-struct keymap43,1022
- uint8_t first_scancode;45,1040
- const char *chars;chars46,1094
-static const struct keymap invariant_keymap[invariant_keymap54,1483
-static const struct keymap unshifted_keymap[unshifted_keymap69,1808
-static const struct keymap shifted_keymap[shifted_keymap81,2068
-keyboard_interrupt 94,2330
- struct shift_key 161,4115
- unsigned scancode;163,4149
- bool *state_var;state_var164,4178
-map_key 196,4978
-
-devices/kbd.h,27
-#define DEVICES_KBD_H2,22
-
-devices/serial.c,889
-#define IO_BASE 18,488
-#define RBR_REG 21,535
-#define THR_REG 22,607
-#define IER_REG 23,684
-#define LS_REG 26,770
-#define MS_REG 27,829
-#define IIR_REG 30,923
-#define FCR_REG 31,1003
-#define LCR_REG 32,1073
-#define MCR_REG 33,1134
-#define LSR_REG 34,1196
-#define IER_RECV 37,1307
-#define IER_XMIT 38,1375
-#define LCR_N81 41,1482
-#define LCR_DLAB 42,1556
-#define MCR_OUT2 45,1658
-#define LSR_DR 48,1740
-#define LSR_THRE 49,1820
-static enum { UNINIT,52,1896
-static enum { UNINIT, POLL,52,1896
-static enum { UNINIT, POLL, QUEUE 52,1896
-static enum { UNINIT, POLL, QUEUE } mode;52,1896
-static struct intq txq;55,1969
-static intr_handler_func serial_interrupt;60,2091
-init_poll 67,2371
-serial_init_queue 82,2913
-serial_putc 99,3235
-serial_flush 135,4181
-serial_notify 148,4565
-set_serial 157,4744
-write_ier 177,5201
-putc_poll 199,5658
-serial_interrupt 210,5856
-
-devices/serial.h,30
-#define DEVICES_SERIAL_H2,25
-
-devices/timer.c,420
-static int64_t ticks;21,466
-static unsigned loops_per_tick;25,564
-static intr_handler_func timer_interrupt;27,597
-timer_init 36,933
-timer_calibrate 51,1356
-timer_ticks 78,2134
-timer_elapsed 90,2410
-timer_sleep 97,2544
-timer_msleep 108,2828
-timer_usleep 115,2955
-timer_nsleep 122,3088
-timer_print_stats 129,3200
-timer_interrupt 136,3330
-too_many_loops 145,3520
-busy_wait 169,4121
-real_time_sleep 177,4252
-
-devices/timer.h,55
-#define DEVICES_TIMER_H2,24
-#define TIMER_FREQ 8,134
-
-devices/vga.c,290
-#define COL_CNT 13,310
-#define ROW_CNT 14,329
-static size_t cx,18,434
-static size_t cx, cy;18,434
-#define GRAY_ON_BLACK 21,516
-static uint8_t (*fb)fb26,695
-init 36,949
-vga_putc 51,1230
-cls 100,2043
-clear_row 113,2199
-newline 128,2533
-move_cursor 142,2777
-find_cursor 152,3049
-
-devices/vga.h,27
-#define DEVICES_VGA_H2,22
-
-lib/arithmetic.c,172
-divl 26,1080
-nlz 42,1364
-udiv64 78,2084
-umod64 132,3870
-sdiv64 140,4032
-smod64 151,4385
-__divdi3 165,4784
-__moddi3 172,4891
-__udivdi3 179,5008
-__umoddi3 186,5145
-
-lib/ctype.h,533
-#define __LIB_CTYPE_H2,22
-static inline int islower 4,45
-static inline int isupper 5,112
-static inline int isalpha 6,179
-static inline int isdigit 7,252
-static inline int isalnum 8,319
-static inline int isxdigit 9,392
-static inline int isspace 12,505
-static inline int isblank 16,639
-static inline int isgraph 17,707
-static inline int isprint 18,771
-static inline int iscntrl 19,836
-static inline int isascii 20,913
-static inline int ispunct 21,977
-static inline int tolower 25,1070
-static inline int toupper 26,1148
-
-lib/debug.c,24
-debug_backtrace 13,360
-
-lib/debug.h,377
-#define __LIB_DEBUG_H2,22
-#define debug(7,220
-#define UNUSED 12,420
-#define NO_RETURN 13,460
-#define NO_INLINE 14,505
-#define PRINTF_FORMAT(15,550
-#define PANIC(19,747
-void debug_panic 21,823
-#define PART 26,1071
-#undef ASSERT33,1222
-#undef NOT_REACHED34,1236
-#define ASSERT(37,1271
-#define NOT_REACHED(41,1479
-#define ASSERT(43,1552
-#define NOT_REACHED(44,1589
-
-lib/inttypes.h,858
-#define __LIB_INTTYPES_H2,25
-#define PRId8 6,72
-#define PRIi8 7,92
-#define PRIo8 8,112
-#define PRIu8 9,132
-#define PRIx8 10,152
-#define PRIX8 11,172
-#define PRId16 13,193
-#define PRIi16 14,213
-#define PRIo16 15,233
-#define PRIu16 16,253
-#define PRIx16 17,273
-#define PRIX16 18,293
-#define PRId32 20,314
-#define PRIi32 21,333
-#define PRIo32 22,352
-#define PRIu32 23,371
-#define PRIx32 24,390
-#define PRIX32 25,409
-#define PRId64 27,429
-#define PRIi64 28,450
-#define PRIo64 29,471
-#define PRIu64 30,492
-#define PRIx64 31,513
-#define PRIX64 32,534
-#define PRIdMAX 34,556
-#define PRIiMAX 35,577
-#define PRIoMAX 36,598
-#define PRIuMAX 37,619
-#define PRIxMAX 38,640
-#define PRIXMAX 39,661
-#define PRIdPTR 41,683
-#define PRIiPTR 42,704
-#define PRIoPTR 43,725
-#define PRIuPTR 44,746
-#define PRIxPTR 45,767
-#define PRIXPTR 46,788
-
-lib/limits.h,528
-#define __LIB_LIMITS_H2,23
-#define CHAR_BIT 4,47
-#define SCHAR_MAX 6,67
-#define SCHAR_MIN 7,89
-#define UCHAR_MAX 8,124
-#define CHAR_MIN 11,172
-#define CHAR_MAX 12,191
-#define CHAR_MIN 14,224
-#define CHAR_MAX 15,251
-#define SHRT_MAX 18,286
-#define SHRT_MIN 19,309
-#define USHRT_MAX 20,342
-#define INT_MAX 22,367
-#define INT_MIN 23,394
-#define UINT_MAX 24,425
-#define LONG_MAX 26,455
-#define LONG_MIN 27,484
-#define ULONG_MAX 28,517
-#define LLONG_MAX 30,549
-#define LLONG_MIN 31,589
-#define ULLONG_MAX 32,624
-
-lib/random.c,195
-static uint8_t s[s17,426
-static uint8_t s_i,18,469
-static uint8_t s_i, s_j;18,469
-static bool inited;21,541
-swap_byte 25,631
-random_init 34,781
-random_bytes 54,1118
-random_ulong 78,1560
-
-lib/random.h,28
-#define __LIB_RANDOM_H2,23
-
-lib/round.h,107
-#define __LIB_ROUND_H2,22
-#define ROUND_UP(6,135
-#define DIV_ROUND_UP(10,276
-#define ROUND_DOWN(14,429
-
-lib/stdarg.h,163
-#define __LIB_STDARG_H2,23
-typedef __builtin_va_list va_list;7,133
-#define va_start(9,169
-#define va_end(10,228
-#define va_arg(11,284
-#define va_copy(12,341
-
-lib/stdbool.h,131
-#define __LIB_STDBOOL_H2,24
-#define bool 4,49
-#define true 5,68
-#define false 6,83
-#define __bool_true_false_are_defined 7,99
-
-lib/stddef.h,149
-#define __LIB_STDDEF_H2,23
-#define NULL 4,47
-#define offsetof(5,73
-typedef __PTRDIFF_TYPE__ ptrdiff_t;9,238
-typedef __SIZE_TYPE__ size_t;10,274
-
-lib/stdint.h,1040
-#define __LIB_STDINT_H2,23
-typedef signed char int8_t;4,47
-#define INT8_MAX 5,75
-#define INT8_MIN 6,96
-typedef signed short int int16_t;8,130
-#define INT16_MAX 9,164
-#define INT16_MIN 10,188
-typedef signed int int32_t;12,224
-#define INT32_MAX 13,252
-#define INT32_MIN 14,281
-typedef signed long long int int64_t;16,317
-#define INT64_MAX 17,355
-#define INT64_MIN 18,395
-typedef unsigned char uint8_t;20,431
-#define UINT8_MAX 21,462
-typedef unsigned short int uint16_t;23,485
-#define UINT16_MAX 24,522
-typedef unsigned int uint32_t;26,548
-#define UINT32_MAX 27,579
-typedef unsigned long long int uint64_t;29,611
-#define UINT64_MAX 30,652
-typedef int32_t intptr_t;32,696
-#define INTPTR_MIN 33,722
-#define INTPTR_MAX 34,751
-typedef uint32_t uintptr_t;36,781
-#define UINTPTR_MAX 37,809
-typedef int64_t intmax_t;39,841
-#define INTMAX_MIN 40,867
-#define INTMAX_MAX 41,896
-typedef uint64_t uintmax_t;43,926
-#define UINTMAX_MAX 44,954
-#define PTRDIFF_MIN 46,986
-#define PTRDIFF_MAX 47,1016
-#define SIZE_MAX 49,1047
-
-lib/stdio.c,1097
-struct vsnprintf_aux 9,165
- char *p;p11,191
- int length;12,246
- int max_length;13,301
-vsnprintf 26,826
-vsnprintf_helper 46,1296
-snprintf 62,1849
-printf 79,2252
-struct printf_conversion 94,2487
- MINUS 99,2552
- PLUS 100,2594
- SPACE 101,2636
- POUND 102,2678
- ZERO 103,2720
- GROUP 104,2762
- int width;109,2856
- int precision;113,2949
- CHAR 118,3025
- SHORT 119,3066
- INT 120,3106
- INTMAX 121,3151
- LONG 122,3191
- LONGLONG 123,3231
- PTRDIFFT 124,3272
- SIZET 125,3312
-struct integer_base 130,3376
- int base;132,3401
- const char *digits;digits133,3445
- int x;134,3505
- int group;135,3583
-static const struct integer_base base_d 138,3666
-static const struct integer_base base_o 139,3734
-static const struct integer_base base_x 140,3799
-static const struct integer_base base_X 141,3875
-__vprintf 157,4692
-parse_conversion 340,9965
-format_integer 470,12581
-output_dup 551,15275
-format_string 561,15565
-__printf 577,16076
-hex_dump 593,16539
-
-lib/stdio.h,156
-#define __LIB_STDIO_H2,22
-#define STDIN_FILENO 15,275
-#define STDOUT_FILENO 16,298
-int printf 19,349
-#define sprintf 36,1011
-#define vsprintf 37,1057
-
-lib/stdlib.c,161
-atoi 10,213
-compare_thunk 45,914
-qsort 58,1386
-do_swap 67,1657
-do_compare 86,2177
-heapify 97,2610
-sort 132,3780
-bsearch 166,4773
-binary_search 185,5516
-
-lib/stdlib.h,28
-#define __LIB_STDLIB_H2,23
-
-lib/string.c,319
-memcpy 7,128
-memmove 24,478
-memcmp 53,1110
-strcmp 73,1667
-memchr 94,2136
-strchr 113,2604
-strcspn 131,2948
-strpbrk 145,3304
-strrchr 156,3605
-strspn 170,3892
-strstr 184,4248
-strtok_r 235,5754
-memset 279,6704
-strlen 293,6924
-strnlen 307,7198
-strlcpy 326,7810
-strlcpy_first_word 350,8309
-strlcat 385,9241
-
-lib/string.h,148
-#define __LIB_STRING_H2,23
-#define strcpy 30,948
-#define strncpy 31,991
-#define strcat 32,1036
-#define strncat 33,1079
-#define strtok 34,1124
-
-lib/syscall-nr.h,532
-#define __LIB_SYSCALL_NR_H2,27
- SYS_HALT,8,154
- SYS_EXIT,9,219
- SYS_EXEC,10,281
- SYS_WAIT,11,342
- SYS_CREATE,12,413
- SYS_REMOVE,13,466
- SYS_OPEN,14,519
- SYS_FILESIZE,15,570
- SYS_READ,16,630
- SYS_WRITE,17,686
- SYS_SEEK,18,741
- SYS_TELL,19,806
- SYS_CLOSE,20,879
- SYS_MMAP,23,971
- SYS_MUNMAP,24,1033
- SYS_CHDIR,27,1132
- SYS_MKDIR,28,1200
- SYS_READDIR,29,1258
- SYS_ISDIR,30,1321
- SYS_INUMBER,31,1397
- SYS_PLIST,35,1575
- SYS_NUMBER_OF_CALLS38,1719
-
-lib/kernel/bitmap.c,789
-typedef unsigned long elem_type;19,444
-#define ELEM_BITS 22,514
-struct bitmap27,719
- size_t bit_cnt;29,737
- elem_type *bits;bits30,783
-elem_idx 36,952
-bit_mask 44,1126
-elem_cnt 51,1292
-byte_cnt 58,1449
-last_mask 66,1686
-bitmap_create 79,2046
-bitmap_create_in_buf 100,2568
-bitmap_buf_size 115,2967
-bitmap_destroy 124,3181
-bitmap_size 137,3356
-bitmap_set 146,3523
-bitmap_mark 158,3773
-bitmap_reset 171,4222
-bitmap_flip 186,4747
-bitmap_test 199,5190
-bitmap_set_all 210,5437
-bitmap_set_multiple 219,5628
-bitmap_count 234,5998
-bitmap_contains 252,6451
-bitmap_any 269,6875
-bitmap_none 277,7113
-bitmap_all 285,7355
-bitmap_scan 297,7709
-bitmap_scan_and_flip 321,8426
-bitmap_file_size 334,8765
-bitmap_read 342,8924
-bitmap_write 357,9297
-bitmap_dump 368,9560
-
-lib/kernel/bitmap.h,65
-#define __LIB_KERNEL_BITMAP_H2,30
-#define BITMAP_ERROR 36,1307
-
-lib/kernel/console.c,440
-static struct lock console_lock;18,525
-static bool use_console_lock;31,1105
-static int console_lock_depth;57,1940
-static int64_t write_cnt;60,2019
-console_init 64,2081
-console_panic 74,2303
-console_print_stats 81,2396
-acquire_console 88,2533
-release_console 101,2801
-console_locked_by_current_thread 115,3096
-vprintf 126,3405
-puts 140,3673
-putbuf 153,3897
-putchar 163,4093
-vprintf_helper 174,4249
-putchar_have_lock 185,4501
-
-lib/kernel/console.h,36
-#define __LIB_KERNEL_CONSOLE_H2,31
-
-lib/kernel/debug.c,20
-debug_panic 15,347
-
-lib/kernel/hash.c,708
-#define list_elem_to_hash_elem(12,215
-hash_init 25,844
-hash_clear 54,1670
-hash_destroy 87,2636
-hash_insert 99,3000
-hash_replace 115,3371
-hash_find 132,3782
-hash_delete 145,4204
-hash_apply 163,4743
-hash_first 200,5648
-hash_next 219,6236
-hash_cur 241,6865
-hash_size 248,6974
-hash_empty 255,7097
-#define FNV_32_PRIME 261,7218
-#define FNV_32_BASIS 262,7249
-hash_bytes 266,7339
-hash_string 283,7659
-hash_int 299,7935
-find_bucket 306,8065
-find_elem 315,8357
-turn_off_least_1bit 330,8784
-is_power_of_2 337,8922
-#define MIN_ELEMS_PER_BUCKET 343,9035
-#define BEST_ELEMS_PER_BUCKET 344,9112
-#define MAX_ELEMS_PER_BUCKET 345,9170
-rehash 352,9481
-insert_elem 417,11430
-remove_elem 425,11614
-
-lib/kernel/hash.h,617
-#define __LIB_KERNEL_HASH_H2,28
-struct hash_elem 29,971
- struct list_elem list_elem;31,993
-#define hash_entry(39,1314
-typedef unsigned hash_hash_func 45,1599
-typedef bool hash_less_func 50,1839
-typedef void hash_action_func 56,2071
-struct hash 59,2154
- size_t elem_cnt;61,2171
- size_t bucket_cnt;62,2238
- struct list *buckets;buckets63,2309
- hash_hash_func *hash;hash64,2376
- hash_less_func *less;less65,2429
- void *aux;aux66,2488
-struct hash_iterator 70,2599
- struct hash *hash;hash72,2625
- struct list *bucket;bucket73,2679
- struct hash_elem *elem;elem74,2733
-
-lib/kernel/list.c,719
-static bool is_sorted 34,1344
-is_interior 47,1743
-is_tail 54,1926
-list_init 61,2077
-list_begin 72,2312
-list_next 82,2593
-list_end 94,2890
-list_rbegin 103,3102
-list_prev 113,3387
-list_rend 133,3929
-list_head 151,4267
-list_tail 159,4397
-list_insert 169,4633
-list_splice 184,5062
-list_push_front 209,5714
-list_push_back 217,5904
-list_remove 257,7081
-list_pop_front 268,7373
-list_pop_back 278,7630
-list_front 288,7851
-list_back 297,8043
-list_size 306,8231
-list_empty 318,8463
-swap 325,8619
-list_reverse 334,8763
-is_sorted 350,9223
-find_end_of_run 366,9736
-inplace_merge 388,10362
-list_sort 413,11088
-list_insert_ordered 454,12480
-list_unique 474,13096
-list_max 501,13875
-list_min 520,14460
-
-lib/kernel/list.h,300
-#define __LIB_KERNEL_LIST_H2,28
-struct list_elem 90,3087
- struct list_elem *prev;prev92,3109
- struct list_elem *next;next93,3170
-struct list 97,3245
- struct list_elem head;99,3262
- struct list_elem tail;100,3311
-#define list_entry(108,3649
-typedef bool list_less_func 152,5162
-
-lib/kernel/stdio.h,34
-#define __LIB_KERNEL_STDIO_H2,29
-
-lib/kernel/slist.c,410
- struct Node7,142
- ListElement Element;9,172
- Position Next;10,205
- MakeEmpty(16,286
- IsEmpty(32,647
- int IsLast(40,854
- Find(48,1036
- Delete(65,1436
- FindPrevious(83,1974
- Insert(99,2363
- DeleteList(117,2784
- Header(132,3099
- First(138,3185
- Advance(144,3276
- Retrieve(150,3375
-
-lib/kernel/slist.h,210
- typedef void * ListElement;2,40
- #define _SList_H5,102
- typedef struct Node *PtrToNode;PtrToNode8,149
- typedef PtrToNode SList;9,189
- typedef PtrToNode Position;10,222
-
-lib/user/console.c,235
-vprintf 9,174
-hprintf 16,336
-puts 31,604
-putchar 41,737
-struct vhprintf_aux 49,864
- char buf[buf51,889
- char *p;p52,937
- int char_cnt;53,995
- int handle;54,1058
-vhprintf 64,1332
-add_char 78,1652
-flush 89,1865
-
-lib/user/debug.c,20
-debug_panic 10,233
-
-lib/user/entry.c,13
-_start 7,92
-
-lib/user/stdio.h,50
-#define __LIB_USER_STDIO_H2,27
-int hprintf 4,55
-
-lib/user/syscall.c,432
-#define syscall0(6,146
-#define syscall1(19,850
-#define syscall2(33,1720
-#define syscall3(49,2639
-halt 65,3514
-exit 72,3578
-exec 79,3656
-wait 85,3733
-create 91,3795
-remove 97,3906
-open 103,3979
-filesize 109,4048
-read 115,4114
-write 121,4214
-seek 127,4323
-tell 133,4408
-close 139,4467
-mmap 145,4523
-munmap 151,4599
-chdir 157,4664
-mkdir 163,4734
-readdir 169,4804
-isdir 175,4907
-inumber 181,4967
-plist 188,5103
-
-lib/user/syscall.h,247
-#define __LIB_USER_SYSCALL_H2,29
-typedef int pid_t;8,126
-#define PID_ERROR 9,145
-typedef int mapid_t;12,206
-#define MAP_FAILED 13,227
-#define READDIR_MAX_LEN 16,323
-#define EXIT_SUCCESS 19,416
-#define EXIT_FAILURE 20,476
-void halt 23,587
-
-threads/kernel.lds.S,0
diff --git a/src/lib/kernel/list.c b/src/lib/kernel/list.c
index e9993cb..8b02162 100644
--- a/src/lib/kernel/list.c
+++ b/src/lib/kernel/list.c
@@ -1,5 +1,11 @@
#include "list.h"
+#ifdef PINTOS
#include "../debug.h"
+#else
+#define UNUSED __attribute__ ((unused))
+#define ASSERT(...) assert(__VA_ARGS__)
+#include <assert.h>
+#endif
/* Our doubly linked lists have two header elements: the "head"
just before the first element and the "tail" just after the
@@ -463,7 +469,7 @@ list_insert_ordered (struct list *list, struct list_elem *elem,
for (e = list_begin (list); e != list_end (list); e = list_next (e))
if (less (elem, e, aux))
break;
- return list_insert (e, elem);
+ list_insert (e, elem);
}
/* Iterates through LIST and removes all but the first in each
diff --git a/src/standalone/upg1/basics.c b/src/standalone/upg1/basics.c
new file mode 100644
index 0000000..62bc52c
--- /dev/null
+++ b/src/standalone/upg1/basics.c
@@ -0,0 +1,6 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+int main()
+{
+}
diff --git a/src/standalone/upg2/about-main.c b/src/standalone/upg2/about-main.c
new file mode 100644
index 0000000..2407c23
--- /dev/null
+++ b/src/standalone/upg2/about-main.c
@@ -0,0 +1,6 @@
+#include <stdio.h>
+#include <string.h>
+
+int main(int argc, char* argv[])
+{
+}
diff --git a/src/standalone/upg3/fork-wait.c b/src/standalone/upg3/fork-wait.c
new file mode 100644
index 0000000..2e7729d
--- /dev/null
+++ b/src/standalone/upg3/fork-wait.c
@@ -0,0 +1,95 @@
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+/* The printf text serve as further comments. Read it. */
+
+int main(int argc, char* argv[])
+{
+ pid_t pid;
+ char dummy[16];
+
+ if (argc < 2)
+ {
+ printf("You need to specify a program as argument 1.\n");
+ exit(1); /* Terminate the process with error (1). */
+ }
+
+ printf("P | Switch to a differen terminal.\n"
+ "P | Execute the command \"ptree $USER\".\n"
+ "P | It will show a list of processes you are running.\n"
+ "P | You should see the process '%s' once.\n"
+ "P | Press enter when you verified that.\n\n", argv[0]);
+
+ /* Wait until enter is pressed (gives you time...) */
+ fgets(dummy, 16, stdin);
+
+ printf("P | This process will now clone itself with fork.\n"
+ "P | One (almost) identical copy will be started.\n"
+ "P | The only difference is the result of fork()\n\n");
+
+ pid = fork();
+
+ if (pid == 0)
+ {
+ printf(" C | This is printed by the new process (the CHILD)\n"
+ " C | The child get a 0 return value from fork.\n\n");
+
+ printf(" C | Repeat the previous command in the other terminal.\n"
+ " C | You should see the process '%s' twice now.\n"
+ " C | (grep for it if you run many processes)\n"
+ " C | Press enter when you verified that.\n\n", argv[0]);
+
+ /* Wait until enter is pressed (gives you time...) */
+ fgets(dummy, 16, stdin);
+
+ printf(" C | The program specified as first argument (%s) on the \n"
+ " C | command line will now be started by the child process.\n"
+ " C | This will REPLACE the code of the child with the code\n"
+ " C | of the specified program.\n\n", argv[1]);
+
+ /* specify a terminal as argument 1 and check ptree again ...
+ * you will see that the child is replaced, it have the same
+ * process number, but a new command line
+ */
+ execv(argv[1], argv + 1);
+
+ printf(" C | This will never be printed, since after starting the new\n"
+ " C | program by calling exec this old program is replaced by\n"
+ " C | the new. This is only printed if the new program could not\n"
+ " C | be started for some reason.\n\n");
+
+ exit(-1); /* Terminate the child with error (-1). */
+ }
+ else
+ {
+ int ret = 0; /* Used to save the result of the child. */
+
+ printf("P | This is printed by the origingal process (the PARENT)\n"
+ "P | It got the number (%d) from fork to identify the child.\n"
+ "P | This process will now work for 5 seconds.\n\n", (int)pid);
+ sleep(5); /* pretend */
+
+ printf("P | This is printed by the origingal process (the PARENT)\n"
+ "P | It got the number (%d) from fork to identify the child.\n"
+ "P | It is now used to wait for the result of that child\n\n",
+ (int)pid);
+
+ /* Wait for the child to finish and get it's status in ret. */
+ waitpid(pid, &ret, 0);
+
+ /* Print the exit status of the child. */
+ if (WIFEXITED(ret))
+ {
+ printf("P | Child finished with code %d\n\n", WEXITSTATUS(ret));
+ }
+ else if (WIFSIGNALED(ret))
+ {
+ printf("P | Child finished due to signal %d\n\n", WTERMSIG(ret));
+ }
+ }
+
+ return 0;
+}
diff --git a/src/standalone/upg4/use-list.c b/src/standalone/upg4/use-list.c
new file mode 100644
index 0000000..065f71a
--- /dev/null
+++ b/src/standalone/upg4/use-list.c
@@ -0,0 +1,42 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdarg.h>
+
+/* Pintos contain an implementation of a doubly linked list. It is
+ * found in ../../lib/kernel/list.[ch].
+ *
+ * Recommended compilation commands:
+ *
+ * This is done once:
+ * gcc -Wall -Wextra -std=gnu99 -pedantic -g -c ../../lib/kernel/list.c
+ *
+ * Then use the precomplied list.o:
+ * gcc -Wall -Wextra -std=gnu99 -pedantic -g use-list.c list.o
+ */
+#error Read comments above, then remove this line.
+
+#include "../../lib/kernel/list.h"
+
+int main()
+{
+ int i, j;
+ int N = 1000;
+
+ /* create a list */
+ for (i = 2; i < N; ++i)
+ {
+ /* insert the value of the loop variable 'i' in the list */
+ }
+
+ for (i = 2; i < N; ++i)
+ {
+ for (j = i*2; j < N; j += i)
+ {
+ /* remove every with 'j' even divisible number from the list */
+ }
+ }
+
+ /* print all remaining numbers in the list and free any memory
+ * allocated */
+ return 0;
+}
diff --git a/src/standalone/upg5/pagedir.c b/src/standalone/upg5/pagedir.c
new file mode 100644
index 0000000..7ef78a3
--- /dev/null
+++ b/src/standalone/upg5/pagedir.c
@@ -0,0 +1,8 @@
+/* The code that simulates and tests your address verification. How
+ this is done is disclosed. As a student you shall not compile this
+ file, but instead compile your program with the .o file as:
+
+ gcc -Wall -Wextra -std=c99 -pedantic -g verify_adr.c pagedir.o
+ */
+#error Read comment above. Leave this line in place.
+
diff --git a/src/standalone/upg5/pagedir.h b/src/standalone/upg5/pagedir.h
new file mode 100644
index 0000000..2919d1a
--- /dev/null
+++ b/src/standalone/upg5/pagedir.h
@@ -0,0 +1,42 @@
+#ifndef PAGEDIR_H
+#define PAGEDIR_H
+
+typedef int bool;
+#define false 0
+#define true 1
+
+/* Returns true iff 'adr' contains a null-character ('\0'). */
+bool is_end_of_string(char* adr);
+
+/* Returns the start address of the page that contains 'adr'. */
+void* pg_round_down(const void* adr);
+
+/* Returns the page number of the page that contains 'adr'.
+ * Page numbers are counted with start at zero (0).
+ */
+unsigned pg_no(const void* adr);
+
+/* Uses the page table to translate from logic to physical
+ * address. Returns NULL if the translation fail.
+ *
+ * The first parameter specify the top level page table to
+ * use. Normally you will find it in the structure corresponding
+ * to your operating systems PCB (Process Control Block).
+ */
+void *pagedir_get_page (void *pagetable, const void *adr);
+
+/* Page size: The number of bytes in each page. */
+#define PGSIZE 100
+
+/* Functions used to simulate a paging system and testing your
+ * solution. */
+void start_evaluate_algorithm(void* start, int size);
+void evaluate(bool result);
+void end_evaluate_algorithm();
+
+/* Let us decide how costly a simulated page fault is in terms of
+ * time. Does not exist in Pintos. Set to zero (0) for faster
+ * testing. */
+void simulator_set_pagefault_time(unsigned i);
+
+#endif
diff --git a/src/standalone/upg5/thread.h b/src/standalone/upg5/thread.h
new file mode 100644
index 0000000..62568ab
--- /dev/null
+++ b/src/standalone/upg5/thread.h
@@ -0,0 +1,16 @@
+#ifndef THREAD_H
+#define THREAD_H
+
+struct thread
+{
+ /* This is just a part of the Pintos Thread. */
+ void* pagedir;
+};
+
+/* Initiate the threading system. */
+void thread_init();
+
+/* Return a pointer to the currently active thread. */
+struct thread* thread_current();
+
+#endif
diff --git a/src/standalone/upg5/verify_adr.c b/src/standalone/upg5/verify_adr.c
new file mode 100644
index 0000000..6aba06e
--- /dev/null
+++ b/src/standalone/upg5/verify_adr.c
@@ -0,0 +1,90 @@
+#include <stdlib.h>
+#include "pagedir.h"
+#include "thread.h"
+
+/* verfy_*_lenght are intended to be used in a system call that accept
+ * parameters containing suspisious (user mode) adresses. The
+ * operating system (executng the system call in kernel mode) must not
+ * be fooled into using (reading or writing) addresses not available
+ * to the user mode process performing the system call.
+ *
+ * In pagedir.h you can find some supporting functions that will help
+ * you dermining if a logic address can be translated into a physical
+ * addrerss using the process pagetable. A single translation is
+ * costly. Work out a way to perform as few translations as
+ * possible.
+ *
+ * Recommended compilation command:
+ *
+ * gcc -Wall -Wextra -std=gnu99 -pedantic -g pagedir.o verify_adr.c
+ */
+#error Read comment above and then remove this line.
+
+/* Verify all addresses from and including 'start' up to but excluding
+ * (start+length). */
+bool verify_fix_length(void* start, int length)
+{
+ // ADD YOUR CODE HERE
+}
+
+/* Verify all addresses from and including 'start' up to and including
+ * the address first containg a null-character ('\0'). (The way
+ * C-strings are stored.)
+ */
+bool verify_variable_length(char* start)
+{
+ // ADD YOUR CODE HERE
+}
+
+/* Definition of test cases. */
+struct test_case_t
+{
+ void* start;
+ unsigned length;
+};
+
+#define TEST_CASE_COUNT 6
+
+const struct test_case_t test_case[TEST_CASE_COUNT] =
+{
+ {(void*)100, 100}, /* one full page */
+ {(void*)199, 102},
+ {(void*)101, 98},
+ {(void*)250, 190},
+ {(void*)250, 200},
+ {(void*)250, 210}
+};
+
+/* This main program will evalutate your solution. */
+int main(int argc, char* argv[])
+{
+ int i;
+ bool result;
+
+ if ( argc == 2 )
+ {
+ simulator_set_pagefault_time( atoi(argv[1]) );
+ }
+ thread_init();
+
+ /* Test the algorithm with a given intervall (a buffer). */
+ for (i = 0; i < TEST_CASE_COUNT; ++i)
+ {
+ start_evaluate_algorithm(test_case[i].start, test_case[i].length);
+ result = verify_fix_length(test_case[i].start, test_case[i].length);
+ evaluate(result);
+ end_evaluate_algorithm();
+ }
+
+ /* Test the algorithm with a C-string (start address with
+ * terminating null-character).
+ */
+ for (i = 0; i < TEST_CASE_COUNT; ++i)
+ {
+ start_evaluate_algorithm(test_case[i].start, test_case[i].length);
+ result = verify_variable_length(test_case[i].start);
+ evaluate(result);
+ end_evaluate_algorithm();
+ }
+ return 0;
+}
diff --git a/src/standalone/upg6/main.c b/src/standalone/upg6/main.c
new file mode 100644
index 0000000..c481d40
--- /dev/null
+++ b/src/standalone/upg6/main.c
@@ -0,0 +1,124 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "map.h"
+
+/* Recommended compile commmand:
+ *
+ * gcc -Wall -Wextra -std=gnu99 -pedantic -g main.c map.c
+ *
+ * Recommended way to test your solution:
+ *
+ * valgrind --tool=memcheck ./a.out
+ */
+#error Read comments above, then remove this line.
+
+
+/* Can be used to inform compiler about unused parameters (prevent
+ * warning). Useful when a funtion pointer expect a certain set of
+ * parameters, but you only need some of them. */
+#define UNUSED __attribute__((unused))
+
+/* The code assumes that key_t is `int' and value_t is `char*' */
+
+/* function passed as parameter to map_remove_if in order to free the
+ * memory for all inseted values, and return true to remove them from
+ * the map */
+bool do_free(key_t k UNUSED, value_t v, int aux UNUSED)
+{
+ free(v); /*! free memory */
+ return true; /* and remove from collection */
+}
+
+/* function to display all values in the map that are less than the
+ * aux argument */
+void print_less(key_t k UNUSED, value_t v, int aux)
+{
+ /* atoi converst from sequence of character to integer, it will fail
+ * when the characters are letters, check the manpage to see how */
+ if ( atoi(v) < aux)
+ {
+ printf("%s ", v);
+ }
+}
+
+
+#define LOOPS 10
+
+char* my_strdup(char* str)
+{
+ /*! calculate the length and add space for '\0' */
+ int len = strlen(str) + 1;
+ /*! allocate memory just large enough */
+ char* dst = (char*)malloc(len);
+ /*! copy all characters in src to dst */
+ strncpy(dst, str, len);
+
+ return dst; /*(!) return our deep copy of str */
+}
+
+int main()
+{
+ struct map container;
+ char input_buffer[10];
+ char* obj;
+ int id;
+ int i;
+
+ map_init(&container);
+
+ /* remember to try to insert more values than you map can hold */
+ printf("Insert values: ");
+ for ( i = 0; i < LOOPS; ++i)
+ {
+ /* insecure, scanf may overflow the input buffer array *
+ * very serious, but we ignore it in this test program */
+ scanf("%s", input_buffer);
+
+ /*! allocates a copy of the input and inserts in map */
+ obj = my_strdup(input_buffer);
+ id = map_insert(&container, obj);
+ }
+
+ /* remember to test with invalid keys (like 4711, or -1) */
+ for ( i = 0; i < LOOPS; ++i)
+ {
+ printf("Enter id to find value for: ");
+ scanf("%d", &id);
+
+ /*! find the value for a key in the map */
+ obj = map_find(&container, id);
+
+ /*! if it was found, display it */
+YOUR CODE
+
+ /* since we leave the value in the map we may use it again and
+ * should not free the memory */
+ }
+
+ /* remember to test with invalid keys (like 4711, or -1) */
+ for ( i = 0; i < LOOPS; ++i)
+ {
+ printf("Enter id to remove value for: ");
+ scanf("%d", &id);
+
+ /*! find and remove a value for a key in the map */
+ obj = map_remove(&container, id);
+
+ /*! if it was found, display it */
+YOUR CODE
+ /* since we removed the value from the map we will never use it again and
+ * must properly free the memory (if it was allocated) */
+ }
+
+ /*! print all strings representing an integer less than N */
+ printf("Will now display all values less than N. Choose N: ");
+ scanf("%d", &i);
+ map_for_each(&container, print_less, i);
+
+ /*! free all remaining memory and remove from map */
+ map_remove_if(&container, do_free, 0);
+
+ return 0;
+}
diff --git a/src/standalone/upg6/map.c b/src/standalone/upg6/map.c
new file mode 100644
index 0000000..b323fbb
--- /dev/null
+++ b/src/standalone/upg6/map.c
@@ -0,0 +1 @@
+#include "map.h"
diff --git a/src/standalone/upg6/map.h b/src/standalone/upg6/map.h
new file mode 100644
index 0000000..9029ff5
--- /dev/null
+++ b/src/standalone/upg6/map.h
@@ -0,0 +1 @@
+/* do not forget the guard against multiple includes */
diff --git a/src/standalone/upg7/debug.c b/src/standalone/upg7/debug.c
new file mode 100644
index 0000000..d6a3707
--- /dev/null
+++ b/src/standalone/upg7/debug.c
@@ -0,0 +1,27 @@
+#include <stdio.h>
+
+int main()
+{
+ char str[] = "sihtgubed";
+ char *stri = &str[8];
+ char *buf[9];
+ char **bufi, **bufend;
+ bufi = buf;
+ bufend = &buf[9];
+
+ while (bufi != bufend){
+ *bufi = stri;
+ bufi++;
+ stri--;
+ }
+
+ while (bufi != buf){
+ *(*bufi) -= 32;
+ bufi--;
+ }
+
+ while (bufi != bufend){
+ printf("%c", **bufi);
+ bufi++;
+ }
+}
diff --git a/src/standalone/upg8/setup-argv.c b/src/standalone/upg8/setup-argv.c
new file mode 100644
index 0000000..dd326d2
--- /dev/null
+++ b/src/standalone/upg8/setup-argv.c
@@ -0,0 +1,265 @@
+#define _POSIX_C_SOURCE 2
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+/*
+ YOUR WORK:
+
+ You will complete the function setup_main_stack below. Missing code
+ and calculations are expressed with a questionmark (?). The
+ assignment is mostly about doing the correct math. To do that math
+ you will need to learn or understand:
+
+ - How the stack is used during program execution
+ - How the stack is expected to look like at start of a C-program
+ - What a pointer variable is, how it is used
+ - How a C-array (pointer to many) is laid-out in memory
+ - How pointer arithmetic behaves
+ - How to cast from one pointer type to another
+ - How to use printf to print good debug information
+ - How to use a C-struct, both object and pointer to
+
+ Some manual-pages of interest:
+
+ man -s3 printf
+ man -s3 strlen
+ man -s3 strncpy
+ man -s3 strtok_r
+
+ The prototype for above functions:
+
+ int printf(const char *restrict format, ...);
+ size_t strlen(const char *s);
+ size_t strncpy(char *dst, const char *src, size_t dstsize);
+ char *strtok_r(char *s1, const char *s2, char **lasts);
+
+ The above functions exist in Pintos code. Note the Pintos use
+ 'strlcpy' instead of 'strncpy'. If 'dst' is large enough they behave
+ identical. You can find Pintos implementations in
+ /home/TDIU16/labs/skel/pintos/src/lib, see string.c and stdio.c. It
+ is strongly recommendable to look at the strtok_r examples given in
+ string.c
+
+ About *restrict: http://en.wikipedia.org/wiki/Pointer_alias
+
+
+ Recommended compile command:
+
+ gcc -m32 -Wall -Wextra -std=gnu99 -pedantic -g setup-argv.c
+
+*/
+#error Read comments above, then remove this line.
+
+#define true 1
+#define false 0
+
+typedef int bool;
+
+/* "struct main_args" represent the stack as it must look when
+ * entering main. The only issue: argv must point somewhere...
+ *
+ * The members of this structure is is directly related to the
+ * arguments of main in a C-program, of course.
+ *
+ * int main(int argc, char* argv[]);
+ *
+ * (char** argv is a more generic form of char* argv[])
+ *
+ * The function pointer is normally handled by the compiler
+ * automatically, and determine the address at where a function shall
+ * continue when it returns. The main function does not use it, as the
+ * operating system arrange for the program to stop execution when
+ * main is finished.
+ */
+struct main_args
+{
+ /* Hint: When try to interpret C-declarations, read from right to
+ * left! It is often easier to get the correct interpretation,
+ * altough it does not always work. */
+
+ /* Variable "ret" that stores address (*ret) to a function taking no
+ * parameters (void) and returning nothing. */
+ void (*ret)(void);
+
+ /* Just a normal integer. */
+ int argc;
+
+ /* Variable "argv" that stores address to an address storing char.
+ * That is: argv is a pointer to char*
+ */
+ char** argv;
+};
+
+/* A function that dumps 'size' bytes of memory starting at 'ptr'
+ * it will dump the higher adress first letting the stack grow down.
+ */
+void dump(void* ptr, int size)
+{
+ int i;
+
+ printf("Adress \thex-data \tchar-data\n");
+
+ for (i = size - 1; i >= 0; --i)
+ {
+ void** adr = (void**)((unsigned)ptr + i);
+ unsigned char* byte = (unsigned char*)((unsigned)ptr + i);
+
+ printf("%08x\t", (unsigned)ptr + i); /* address */
+
+ if ((i % 4) == 0)
+ /* seems we're actually forbidden to read unaligned adresses */
+ printf("%08x\t", (unsigned)*adr); /* content interpreted as address */
+ else
+ printf(" \t"); /* fill */
+
+ if(*byte >= 32 && *byte < 127)
+ printf("%c\n", *byte); /* content interpreted as character */
+ else
+ printf("\\%o\n", *byte);
+
+ if ((i % 4) == 0)
+ printf("------------------------------------------------\n");
+ }
+}
+
+/* Read one line of input ...
+ */
+void custom_getline(char buf[], int size)
+{
+ int i;
+ for (i = 0; i < (size - 1); ++i)
+ {
+ buf[i] = getchar();
+ if (buf[i] == '\n')
+ break;
+ }
+ buf[i] = '\0';
+}
+
+/* Return true if 'c' is fount in the c-string 'd'
+ * NOTE: 'd' must be a '\0'-terminated c-string
+ */
+bool exists_in(char c, const char* d)
+{
+ int i = 0;
+ while (d[i] != '\0' && d[i] != c)
+ ++i;
+ return (d[i] == c);
+}
+
+/* Return the number of words in 'buf'. A word is defined as a
+ * sequence of characters not containing any of the characters in
+ * 'delimeters'.
+ * NOTE: arguments must be '\0'-terminated c-strings
+ */
+int count_args(const char* buf, const char* delimeters)
+{
+ int i = 0;
+ bool prev_was_delim;
+ bool cur_is_delim = true;
+ int argc = 0;
+
+ while (buf[i] != '\0')
+ {
+ prev_was_delim = cur_is_delim;
+ cur_is_delim = exists_in(buf[i], delimeters);
+ argc += (prev_was_delim && !cur_is_delim);
+ ++i;
+ }
+ return argc;
+}
+
+/* Replace calls to STACK_DEBUG with calls to printf. All such calls
+ * easily removed later by replacing with nothing. */
+#define STACK_DEBUG(...) printf(__VA_ARGS__)
+
+void* setup_main_stack(const char* command_line, void* stack_top)
+{
+ /* Variable "esp" stores an address, and at the memory loaction
+ * pointed out by that address a "struct main_args" is found.
+ * That is: "esp" is a pointer to "struct main_args" */
+ struct main_args* esp;
+ int argc;
+ int total_size;
+ int line_size;
+ /* "cmd_line_on_stack" and "ptr_save" are variables that each store
+ * one address, and at that address (the first) char (of a possible
+ * sequence) can be found. */
+ char* cmd_line_on_stack;
+ char* ptr_save;
+ int i = 0;
+
+ /* calculate the bytes needed to store the command_line */
+ line_size = ??? ;
+ STACK_DEBUG("# line_size = %d\n", line_size);
+
+ /* round up to make it even divisible by 4 */
+ line_size = ??? ;
+ STACK_DEBUG("# line_size (aligned) = %d\n", line_size);
+
+ /* calculate how many words the command_line contain */
+ argc = ??? ;
+ STACK_DEBUG("# argc = %d\n", argc);
+
+ /* calculate the size needed on our simulated stack */
+ total_size = ??? ;
+ STACK_DEBUG("# total_size = %d\n", total_size);
+
+
+ /* calculate where the final stack top will be located */
+ esp = ??? ;
+
+ /* setup return address and argument count */
+ esp->ret = ??? ;
+ esp->argc = ??? ;
+ /* calculate where in the memory the argv array starts */
+ esp->argv = ??? ;
+
+ /* calculate where in the memory the words is stored */
+ cmd_line_on_stack = ??? ;
+
+ /* copy the command_line to where it should be in the stack */
+
+ /* build argv array and insert null-characters after each word */
+
+ return esp; /* the new stack top */
+}
+
+/* The C way to do constants ... */
+#define LINE_SIZE 1024
+
+int main()
+{
+ struct main_args* esp;
+ char line[LINE_SIZE];
+ void* simulated_stack = malloc(4096);
+ void* simulated_stack_top = (void*)((unsigned)simulated_stack + 4096);
+ int i;
+
+ /* read one line of input, this will be the command-line */
+ printf("Mata in en mening: ");
+ custom_getline(line, LINE_SIZE);
+
+ /* put initial content on our simulated stack */
+ esp = setup_main_stack(line, simulated_stack_top);
+ printf("# esp = %08x\n", (unsigned)esp);
+
+ /* dump memory area for verification */
+ dump(esp, (unsigned)simulated_stack_top - (unsigned)esp);
+
+ /* original command-line should not be needed anymore */
+ for (i = 0; i < LINE_SIZE; ++i)
+ line[i] = (char)0xCC;
+
+ /* print the argument vector to see if it worked */
+ for (i = 0; i < esp->argc; ++i)
+ {
+ printf("argv[%d] = %s\n", i, esp->argv[i]);
+ }
+ printf("argv[%d] = %p\n", i, esp->argv[i]);
+
+ free(simulated_stack);
+
+ return 0;
+}