From f591dc02a3fdda366bddbf5c8628fda50c9aa151 Mon Sep 17 00:00:00 2001 From: Drew Bednar Date: Wed, 29 Jan 2020 11:36:25 -0500 Subject: [PATCH] Adding Ch3 code --- .gitignore | 1 + LICENSE | 1 + README.md | 4 +++- ch1/Makefile | 19 +++++++++++++++++++ ch1/hello.c | 7 +++++++ ch3/Makefile | 9 +++++++++ ch3/aspace.c | 24 ++++++++++++++++++++++++ 7 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 ch1/Makefile create mode 100644 ch1/hello.c create mode 100644 ch3/Makefile create mode 100644 ch3/aspace.c diff --git a/.gitignore b/.gitignore index e7388b9..4433abd 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,4 @@ # Debug files *.dSYM/ +.idea/ \ No newline at end of file diff --git a/LICENSE b/LICENSE index 472ac23..63fb0fa 100644 --- a/LICENSE +++ b/LICENSE @@ -6,3 +6,4 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + diff --git a/README.md b/README.md index 5cf6f23..4323712 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,4 @@ -# think_os +# Think OS + +Repo following the [Think OS](http://greenteapress.com/thinkos/) book. diff --git a/ch1/Makefile b/ch1/Makefile new file mode 100644 index 0000000..367611b --- /dev/null +++ b/ch1/Makefile @@ -0,0 +1,19 @@ +.PHONEY: build object_code optimal assembly preprocess clean + +build: + gcc hello.c -o hello + +object_code: + gcc hello.c -c + +optimal: + gcc hello.c -O1 -o hello_optimal + +assembly: + gcc hello.c -S + +preprocess: + gcc hello.c -E + +clean: + rm -rf hello hello_optimal hello.o hello.s diff --git a/ch1/hello.c b/ch1/hello.c new file mode 100644 index 0000000..ac801c4 --- /dev/null +++ b/ch1/hello.c @@ -0,0 +1,7 @@ +#include + +int main(){ + printf("Hello dirp\n"); +} + + diff --git a/ch3/Makefile b/ch3/Makefile new file mode 100644 index 0000000..dca84cf --- /dev/null +++ b/ch3/Makefile @@ -0,0 +1,9 @@ +.PHONY: build all + +all: build + +build: + gcc aspace.c -o aspace + +clean: + rm -rf aspace *.o *.s diff --git a/ch3/aspace.c b/ch3/aspace.c new file mode 100644 index 0000000..057407e --- /dev/null +++ b/ch3/aspace.c @@ -0,0 +1,24 @@ +#include +#include + +// code segment - program text +// constant segment - immutable values. *s for example. +// globals - global variables or local variables marked 'static' +// heap - memory allocated at runtime. Grows towards the top virtual address space +// stack - sequence of stack frames. Grows from the top of the virtual-address space + +int global; + +int main(){ + int local = 5; + void *p = malloc(128); + char *s = "Hello, World"; + + printf("Address of main is %p\n", main); + printf("s points to %p\n", s); + printf("Address of global is %p\n", &global); + printf("Address of local is %p\n", &local); + printf("p points to %p\n", p); + + return 0; +} \ No newline at end of file