From 52f605627e0a2126dd555e13d2a0102e7fa7a080 Mon Sep 17 00:00:00 2001 From: hailin cai Date: Fri, 5 Feb 2016 12:45:38 -0500 Subject: [PATCH] Update Booting/linux-bootstrap-2md.md --- Booting/linux-bootstrap-2md.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Booting/linux-bootstrap-2md.md b/Booting/linux-bootstrap-2md.md index 58ad6ee..66058ce 100644 --- a/Booting/linux-bootstrap-2md.md +++ b/Booting/linux-bootstrap-2md.md @@ -205,4 +205,8 @@ GLOBAL(memcpy) popw %si retl ENDPROC(memcpy) -``` \ No newline at end of file +``` + +Yeah, we just moved to C code and now assembly again :) First of all we can see that `memcpy` and other routines which are defined here, start and end with the two macros: `GLOBAL` and `ENDPROC`. `GLOBAL` is described in [arch/x86/include/asm/linkage.h](https://github.com/torvalds/linux/blob/master/arch/x86/include/asm/linkage.h) which defines `globl` directive and the label for it. `ENDPROC` is described in [include/linux/linkage.h](https://github.com/torvalds/linux/blob/master/include/linux/linkage.h) which marks the `name` symbol as a function name and ends with the size of the `name` symbol. + +Implementation of `memcpy` is easy. At first, it pushes values from the `si` and `di` registers to the stack to preserve their values because they will change during the `memcpy`. `memcpy` (and other functions in copy.S) use `fastcall` calling conventions. So it gets its incoming parameters from the `ax`, `dx` and `cx` registers. Calling `memcpy` looks like this: \ No newline at end of file